不可选择的下拉列表 [英] Non-selectable drop down list

查看:61
本文介绍了不可选择的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以有一个下拉列表,其中非项目是可选的?所以基本上,我只是想用它来显示/隐藏列表。我不希望任何悬停突出显示,我不希望能够更改选定的项目。

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屋!

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