I got an issue with following script when the select-options become long:
选项很少的解决方案http://jsfiddle.net/hsQjh/5/
有问题的长选项:http: //jsfiddle.net/hsQjh/6/
我的第一个选择框选项最多有 40+ 个选项,因此第二个选择框也最多有 40+ 个 optgroup,当我在第一个框上选择选项“ 2 ”时,第二个框填充了所有 optgroup,即编号以 2 开头,即 optgroup ' 2 ',填充了' 20 ' - ' 29 ',其他已选择的选项也是如此。
它可以与选项值和选项组标签之间的“ID”完全匹配吗?
function filterActivity(e){
var ids = $('#filterActivity + div input:checked').map(function(i) {
return $(this).val().replace(/ .*/, '');
}).get(); // Retrieve checked IDs
$('#filterSubActivity + div div label').each(function() { // Show matching options
$(this).toggle($.inArray($('input', this).val()[0], ids) > -1);
});
$('#filterSubActivity + div label.optGroup').each(function() { // Show matching groups
$(this).toggle($(this).next().find('label:visible').length > 0);
});
}
谢谢。