這應(yīng)該工作:$('option').hide(); // hide options它可以在Firefox中運(yùn)行,但不能在Chrome中運(yùn)行(可能未在IE中運(yùn)行,未經(jīng)測(cè)試)。一個(gè)更有趣的示例:<select> <option class="hide">Hide me</option> <option>visible option</option></select><script type="text/javascript">// try to hide the first option$('option.hide').hide();// to select the first visible option$('option:visible').first().attr('selected', 'selected');</script>或參見(jiàn)http://jsfiddle.net/TGxUf/上的示例是將選項(xiàng)元素與DOM分離的唯一選擇嗎?我需要稍后再顯示給他們,所以這不會(huì)很有效。
如何使用JavaScript隱藏選擇選項(xiàng)?(跨瀏覽器)
陪伴而非守候
2019-11-18 10:14:23