本文介绍了style.display ='none'不工作在chrome的选项标签,但它在firefox,任何人知道为什么?或解决方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定,下面是一些演示问题的示例代码。
如果我点击firefox中的按钮,第一个选项消失。
如果我点击chrome中的按钮,没有什么发生,或者如果我检查第一个选项,它有属性style ='display:none',但在HTML页面上的选项本身不隐藏。

ok, heres some sample code that demonstrates the problem.if i click the button in firefox, the first option disappears.if i click the button in chrome, nothing happens, or rather if i inspect the first option, it does have the attribute "style='display:none'" but the option itself on the html page is not hidden.

<form>
<select>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<input type="button" onclick="document.getElementsByTagName('option')[0].style.display='none'" value="hide option 1">
</form>

有人知道为什么这不工作在chrome?并且任何人都知道一个解决方法?

does anyone know why this doesnt work in chrome? and does anyone know of a workaround?

推荐答案

解决方法是删除选项元素来响应您的事件,并在需要时添加它们。 IIRC,IE不允许您在选项显示设置为 none c $ c>元素。我建议将删除的元素存储在数组中,以便您可以轻松地将它们添加回来。

The workaround is to remove the option elements in response to your event and add them back if and when they are needed. IIRC, IE will not allow you to set the display to none on option elements. I would advise storing the removed elements in an array so that you can easily add them back in.

这篇关于style.display ='none'不工作在chrome的选项标签,但它在firefox,任何人知道为什么?或解决方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 23:13