jquery.multiselect.js

凌朗
2023-12-01
jquery.multiselect.js  //使用
$(function(){
$("select").multiselect({
noneSelectedText: "==请选择==",
checkAllText: "全选",
uncheckAllText: '全不选',
selectedList:4
});
});
首先修改jquery.multiselect.js,添加全局变量multiValues ,用来存放选项值,然后修改update方法,添加multiValues 那一行代码:
update: function() {
      var o = this.options;
      var $inputs = this.inputs;
      var $checked = $inputs.filter(':checked');
      var numChecked = $checked.length;
      var value;
      if(numChecked === 0) {
        value = o.noneSelectedText;
      } else {
        if($.isFunction(o.selectedText)) {
          value = o.selectedText.call(this, numChecked, $inputs.length, $checked.get());
        } else if(/\d/.test(o.selectedList) && o.selectedList > 0 && numChecked <= o.selectedList) {
          value = $checked.map(function() { return $(this).next().html(); }).get().join(', ');
        } else {
          value = o.selectedText.replace('#', numChecked).replace('#', $inputs.length);
        }
        multiValues = $checked.map(function () { return $(this).val(); }).get().join(',');
      }
      this._setButtonValue(value);
      return value;
    },
   
    再添加自定义方法:
    MyValues:function(){
        return multiValues;
    },
   
   
    页面使用此自定义方法,获取选中值的代码:
 if ($('input[name=multiselect_ddlConditions]:checked').length < 1)
            alert('Please Select Option');
        else {
            var strConditions = $("#ddlConditions").multiselect("MyValues");
}
 类似资料:

相关阅读

相关文章

相关问答