在MSIE下将选择的选项显示样式更改为无 [英] Changing select's option display style to none under MSIE

查看:105
本文介绍了在MSIE下将选择的选项显示样式更改为无的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我为什么下面的代码不能在MSIE下工作?

Could someone please give me a clue as to why the following code does not work under MSIE?

<html>
<body>
<select id="si">
<option value="">1</option>
<option value="">2</option>
<option value="">3</option>
</select>

<script type="text/javascript">
var e=document.getElementById("si");
e.size=3;
e[0].style.display="none"; // <-------- no effect
</script>

</body>
</html>


推荐答案

IE不允许操作 option 元素。根据我的经验,你需要从选择中删除​​所有选项元素,并重新填充它们,以使已经应用(在这种情况下,一个元素被删除)。

IE doesn't allow you to manipulate option elements directly. In my experience, you need to remove all of the option elements from the select and repopulate them with whatever changes you want to make already applied (in this case, one element removed).

这篇关于在MSIE下将选择的选项显示样式更改为无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆