在bootstrap-multiselect 选择的时候,选择为4个的时候 会显示 4 selectd,选择全部的时候 会显示 all selectd。
现在的要求是全部显示出来。
通过调试工具发现 title 和 text 内容是有区别的,title的值是我们需要的。
在 bootstrap-multiselect.js 中搜索 multiselect-selected-text(class)
发现在 updateButtonText: function() {} 方法 中 有设置title和text 内容,将 设置text的内容 修改为设置title的值。
原代码:
updateButtonText: function() {
var options = this.getSelected();
// First update the displayed button text.
if (this.options.enableHTML) {
$('.multiselect .multiselect-selected-text', this.$container).html(this.options.buttonText(options, this.$select));
}
else {
$('.multiselect .multiselect-selected-text', this.$container).text(this.options.buttonText(options, this.$select));
}
// Now update the title attribute of the button.
$('.multiselect', this.$container).attr('title', this.options.buttonTitle(options, this.$select));
},
修改为
updateButtonText: function() {
var options = this.getSelected();
// First update the displayed button text.
if (this.options.enableHTML) {
$('.multiselect .multiselect-selected-text', this.$container).html(this.options.buttonTitle(options, this.$select));
}
else {
$('.multiselect .multiselect-selected-text', this.$container).text(this.options.buttonTitle(options, this.$select));
}
// Now update the title attribute of the button.
$('.multiselect', this.$container).attr('title', this.options.buttonTitle(options, this.$select));
},
还有默认选择第一项的问题
设置
var x = document.getElementById("xxxxx");
x.selectedIndex = -1;
$(".multiselect-selected-text").html("请选择");
动态重建:
var html = html+="<option value='"+obj.id+"'>"+obj.pro_Name+"</option>";
$("#xx").html(html);
$('#xx').multiselect('rebuild');