获取selectpicker多选值

JQuery: 

var selected = "";    

 $("#selectId :selected").each(function(){
     selected += $(this).val() + ","
 });
 
JS:
var e = document.getElementById("selectId");
alert(getSelectValues(e));
function getSelectValues(select) {
  var result = "";
  var options = select && select.options;
  var opt;
 
  for (var i=0, iLen=options.length; i<iLen; i++) {
    opt = options[i];
 
    if (opt.selected) {
      result += (opt.value || opt.text) + ",";
    }
  }
  return result;
}
posted @ 2019-12-24 14:23  wylngg  阅读(1934)  评论(0)    收藏  举报