Hide first option in select
This question already has an answer here:
$("#my-drop-down-select-element-id").find("option").eq(0).remove();
You can remove the first <option />
element in a <select />
element with the above code.
Using CSS to hide <option />
elements is problematic. See the link below for more on this.
To break-down the above function chain:
<select />
element. (No pun intended) <option />
elements within the previously selected element. I used find()
because if there are option groups then children()
won't work. <option />
element. This has definitely been asked before, for some more reading: How to hide a <option> in a <select> menu with CSS?
$('select > option:first').hide();
所有你的第一个选择选项隐藏与此。
HTML
<select id='test'>
<option value='1'> op 1 </option>
<option value='2'> op 2 </option>
<option value='3'> op 3 </option>
<option value='4'> op 4 </option>
</select>
Jquery
$(document).ready(function() {
$("#test").find("option").eq(0).remove();
});
that's it!
链接地址: http://www.djcxy.com/p/70602.html上一篇: 在选择框中删除“默认”<选项>
下一篇: 在选择中隐藏第一个选项