跨浏览器隐藏disabled =“disabled”<option> </option>

时间:2012-11-29 14:59:48

标签: jquery html css internet-explorer

是否有可靠的方法(CSS,JQuery等)来完全隐藏已禁用的内容 所有主流浏览器都是<option disabled="disabled">

我需要将它完全隐藏,而不是仅仅显示为灰色(如在IE中)。

更新:没有隐藏禁用选项的crossbrowser方法。如果你需要删除一个选项,请使用Jquery的detach(),如下面Kevin B.所指出的,禁用选项是没有用的。

2 个答案:

答案 0 :(得分:2)

是的,将其从选择中删除,直到您想要显示它。

var options = $("#myselect option");

// to disable the option at index 3

options.eq(3).detach();

// to enable the option at index 3

options.eq(3).insertAfter(options.eq(2)); // assuming option at index 2 is still attached to the DOM

DEMO

答案 1 :(得分:0)

或许这个

$('option[disabled="disabled"]').remove()​
相关问题