我正在使用David Stutz的bootstrap多选插件,我无法显示'all selected'。使用allSelectedText方法可以工作,但在使用'allSelectedText'回调时它会被覆盖。Bootstrap Multiselect Plugin显示'all selected'
使用前一个问题的答案,我试图抓住孩子的数量和检查,如果他们都选择(见注释)
注意 - 这是工作,如果我删除了“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,
});
});
HTML
<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>
你能提供你的HTML代码SELECT标签的摘录? –
对不起,编辑。查看帖子。 – Mintberry