3 javascript jquery twitter-bootstrap
我正在使用 David Stutz 的引导多选插件,我在显示“全部选定”时遇到问题。使用 allSelectedText 方法可以工作,但在使用“allSelectedText”回调时它会被覆盖。
使用上一个问题的答案,我尝试获取孩子的数量并检查他们是否全部被选中(请参阅评论)
注意 - 如果我删除“numberofOptions”,这将起作用
使用buttonText回调/allSelectedText方法,这里是文档的链接 - http://davidstutz.github.io/bootstrap-multiselect/
感谢您的意见。
JS
$(document).ready(function() {
$('#multiselect').multiselect({
//Following line is being overridden by the numberOfOptions
allSelectedText: 'All Selected',
buttonText: function(options, select) {
//grab the number of childeren to later return 'all selected'
var numberOfOptions = $(this).children('option').length;
if (options.length === 0) {
return 'Select';
}
else if (options.length > 1) {
return '1+ Selected';
}
//This line is calculating number of options,
//displaying 'AllSelected in the label'
else if (options.length === numberOfOptions) {
return 'AllSelected';
}
else {
var labels = [];
options.each(function() {
if ($(this).attr('label') !== undefined) {
labels.push($(this).attr('label'));
}
else {
labels.push($(this).html());
}
});
return labels.join(', ') + '';
}
},
buttonWidth: '100%',
includeSelectAllOption: true,
});
});
Run Code Online (Sandbox Code Playgroud)
超文本标记语言
<select id="multiselect" multiple="multiple">
<option value="x">XYZ</option>
<option value="x">XYZ</option>
<option value="x">XYZ</option>
<option value="x">XYZ</option>
<option value="x">XYZ</option>
</select>
Run Code Online (Sandbox Code Playgroud)
小智 5
我通过使用文档中找到的以下内容修复了此问题。
显示数量:1
$(document).ready(function() {
$('#multiselect').multiselect({
allSelectedText: 'All',
numberDisplayed: 1,
buttonWidth: '100%',
includeSelectAllOption: true,
});
});
Run Code Online (Sandbox Code Playgroud)