使用所选插件时禁用组

时间:2013-12-02 09:31:57

标签: jquery jquery-chosen

我需要的是,如果用户选择值为0的选项,则禁用选择中的整个组,或者如果我不能使用组,则禁用我想要的所有选项,这可能吗?

我试试这样:

$('#ottipo_alcance').chosen().change(function(event){
 if (this.value == '0') 
    $('optgroup option').prop('disabled', true);
 else
    $('optgroup option').prop('disabled', false);                   
  $('#ottipo_alcance').trigger("liszt:updated");
});

<select id="ottipo_alcance" name="ottipo_alcance[]" class="chosen" style="width:200px" multiple="true">
   <option value="0">General</option>
   <optgroup label="Áreas">
        <option value="1">Sistemas</option>
        <option value="2">Operaciones</option>
        ...
   </optgroup>
</select>

注意:我也试过$('#ottipo_alcance')。触发器(“选择:更新”);

1 个答案:

答案 0 :(得分:3)

您应该可以使用以下方法禁用整个optgroup:

$('#ottipo_alcance').find('optgroup:first').prop('disabled', true);