我有三个选择框:
<select id="box1">
<option>foo1</option>
</select>
<select id="box2">
<option>foo2</option>
</select>
<select id="box3">
<option disabled>foo3</option>
</select>
我需要选择选项ID:禁用 - &gt; (BOX3)
如何找到选项的id:用jquery禁用?
答案 0 :(得分:3)
您可以使用:disabled
伪选择器来实现此目的
$('select option:disabled')
要获取父元素,您可以使用closest
选择器或parent
console.log($('select option:disabled').closest('select').attr('id'));
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="box1">
<option disabled>foo1</option>
</select>
<select id="box2">
<option>foo1</option>
</select>
&#13;
答案 1 :(得分:0)
alert($('option:disabled').parent().attr('id'))
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="box2">
</select>
<select id="box1">
</select>
<select id="box3">
<option>foo1</option>
<option>foo2
</option>
<option disabled>foo3</option>
</select>
&#13;
使用选择器:禁用
答案 2 :(得分:0)
var id = $("option:disabled").closest("selecte").attr('id');
console.log(id);