不可选择的下拉列表 [英] Non-selectable drop down list
问题描述
有什么办法可以有一个下拉列表,其中非项目是可选的?所以基本上,我只是想用它来显示/隐藏列表。我不希望任何悬停突出显示,我不希望能够更改选定的项目。
Is there any way to have a drop-down list in which non of the items are selectable? So basically, I'm just looking to use it as a way of showing/hiding a list. I don't want any hover highlighting and I don't want to be able to change the selected item.
您能否建议这是否可能,或者是否有人有任何其他的想法来实现类似的东西,你能指出我一个很好的例子。
Could you suggest if this is possible, or if anyone has any other ideas to achieve something similar, could you point me to a good example.
谢谢
Thanks
推荐答案
optgroup
标签让人想起。它有一个禁用
属性。
The optgroup
tag comes to mind. It has a disabled
attribute.
<select>
<optgroup label="My List" disabled>
<option value="item1">Item 1</option>
<option value="item2">Item 2</option>
</optgroup>
</select>
然而,IE 6和7并不尊重停用
。 Arrgh。他们也不会听整个选择
中的 readonly
属性。
However, IE 6 and 7 don't respect the disabled
. Arrgh. Neither do they listen to the readonly
attribute slapped on the whole select
.
您必须为这些浏览器添加一个 onchange =this.value ='item1';
fallback,如果JavaScript是显式的关闭。
You will have to add a onchange="this.value ='item1';"
fallback for those browsers, which obviously isn't watertight if JavaScript is turned off.
JSFiddle 此处
JSFiddle here
这篇关于不可选择的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!