【发布时间】:2013-03-26 02:00:22
【问题描述】:
I got an issue with following script when the select-options become long:
选项少的解决方案http://jsfiddle.net/hsQjh/5/
有问题的长选项:http://jsfiddle.net/hsQjh/6/
我的第一个选择框选项最多有 40 多个选项,因此当我第一次选择选项“2”时,第二个选择框也最多有 40 多个 optgroup框,第二个框填充所有以 2 开头的 optgroup,即 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);
});
}
谢谢。
【问题讨论】:
标签: jquery drop-down-menu optgroup