如何禁用select optgroup(groupbox)?

时间:2015-03-30 08:23:09

标签: php jquery

如何禁用select optgroup(groupbox)?我想禁用选择组复选框。

http://wenzhixin.net.cn/p/multiple-select/docs/

<form action="show.php" method="post">
    <select name="test[]" multiple="multiple" id="duo">
      <optgroup label="UAE">
      <option value="18">Abu Dhabi</option>
      <option value="19">Dubai</option>
      </optgroup>
      <optgroup label="UK">
      <option value="22">Birmingham</option>
      <option value="94">Brighton</option>
      <option value="24">Leeds</option>
      <option value="99">Liverpool</option>
      <option value="21">London</option>
      <option value="85">Luton</option>
      <option value="23">Manchester</option>
      </optgroup>
    </select>
    <input type="submit" name="submit" value="submit">
    </form>

    @import url('http://wenzhixin.net.cn/p/multiple-select/multiple-select.css');
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="http://wenzhixin.net.cn/p/multiple-select/jquery.multiple.select.js"></script>

    <script>
        $("#duo").multipleSelect({
            placeholder: "Here is the placeholder",
            width: 200,
            selectAll: false,
            filter: true,
        });
    </script>

2 个答案:

答案 0 :(得分:1)

标记optgroup接受属性disabled

<select name="test[]" multiple="multiple" id="duo">
    <optgroup label="UAE" disabled>
        <option value="18">Abu Dhabi</option>
        <option value="19">Dubai</option>
    </optgroup>
</select>

Demo

<强>参考

optgroup

答案 1 :(得分:1)

您应该将disable道具添加到optgroup。尝试这样的事情:

$('[label=UAE]').prop('disabled', 'disabled')

在HTML标记中,它必须是:

<select name="test[]" multiple="multiple" id="duo">
      <optgroup label="UAE" disabled>
        <option value="18">Abu Dhabi</option>
        <option value="19">Dubai</option>
      </optgroup>
      <optgroup label="UK">
        <option value="22">Birmingham</option>
        <option value="94">Brighton</option>
      </optgroup>
</select>

<强> DEMO