我使用了2個jQuery UI小部件來添加選項,只允許用戶在兩個下拉小部件之間選擇5個總數複選框。我可以阻止用戶在5次擊中後檢查更多的盒子,但無法取消選中。下面的代碼不會有任何限制。任何幫助,將不勝感激。我使用JS - 添加2個多重選擇複選框
UI部件:http://www.erichynds.com/blog/jquery-ui-multiselect-widget
<select id="dropdown1" multiple="multiple" class="multiselect">
<select id="dropdown2" multiple="multiple" class="multiselect">
JS
$(document).ready(function() {
$(".multiselect").multiselect({
header: "Choose up to 5 areas total",
click: function (event, ui) {
if (!this.checked) return true;
if ($(".multiselect").children(":checked").length >= 5) {
return false;
}
},
selectedList:5
});
});
除去return true
IF允許用戶僅選擇5這也防止用戶從取消選中。
的可能重複[jQuery UI的多選控件 - 無法取消選中複選框(http://stackoverflow.com/questions/21194696/jquery-ui-multiselect-widget-cant-uncheck-checkbox) –