j查询选择后显示更改



当有人选择多选选项时,我如何能够像"类别子类别"一样显示类别和子类别?代码是这样的。

.HTML:

<select multiple="multiple" class="choosen-multiselect">
    <optgroup label="BLUES">
        <option value="1">Acoustic</option>
        <option value="2">Electric</option>
    </optgroup>
    <optgroup label="R&B/SOUL">
        <option value="50">Contemporary R&B</option>
    </optgroup>
</select>


脚本:
$('select.choosen-multiselect').chosen({});

所以,我喜欢做的是,每当有人选择说"声学"时,我需要能够在jQuery选择提供的选择框中显示"Blues Acoustic"。现在,它仅在选择时显示选定的子类别"声学"。

你可以通过这种方式得到父子...

 $('.choosen-multiselect').on('change', function ()
     {
         var selected = $(this.options[this.selectedIndex]); 
         var parent = selected.closest('optgroup').prop('label');
         var child = selected.prop('label');
         alert(parent +" "+child);
      });

最新更新