我使用的是从这里无法取消选择“选择多个”与选择计数器选项和optgroups
How do you limit options selected in a html select box?
接受答案的代码在“选择多个”菜单来算选定的选项:
var last_valid_selection = null;
$("#select_options").change(function(event) {
if ($(this).val().length > 10) {
$(this).val(last_valid_selection);
} else {
last_valid_selection = $(this).val();
$("#select_options_text").text("Please select at least one, and up to ten options. You have currently selected "+$(this).val().length);
}
});
该菜单分为六个optgroups。当我点击10个选择时,我无法再按预期做出选择。但是我也不能再使用CTRL +点击选定的选项来取消选择。
如果我删除所有optgroup,菜单功能正常。它也可以正确使用一个和两个optgroups。它似乎只是在添加第三个optgroup时出现上述问题。
我已经在Chrome和Firefox中测试过,并且两者都出现问题。
您可以添加HTML,甚至更好,reproduca,在上一个的jsfiddle jsfiddl –
重现问题,作为工作在这里预期:http://jsfiddle.net/z9r26r3j/1/ –
这里的一个jsFiddle使用实际的选择菜单选项:https://jsfiddle.net/gzdrL5wu/2/ –