Jquery在主选择器上隐藏/显示optgroup

con*_*men 0 jquery multiple-select show-hide optgroup

请参考此链接,是一个多选框,根据主要活动中选取的内容选择子活动,现在它的工作非常好.

根据更改请求,我想让操作在选择时仅显示子活动中的optgroup,意味着当您选择时main-activity option 1 and 2,sub-activity显示optgroup 1 and 2,其余是隐藏且不可见,请指教,谢谢.

bte*_*fik 5

你需要得到没有选择的选项和hide()他们在亚活动.而不要忘记显示选定的.

 //get not selected ones
 var arr1 = $('#filterActivity option:not(:selected)');

  //iterate and hide 
  $("#filterSubActivity").children("optgroup[label='" + arr1[j].value + "']").hide();
Run Code Online (Sandbox Code Playgroud)

这是演示:http://jsfiddle.net/btevfik/q62PK/