简体   繁体   English

如何使下拉列表无法选择?

[英]How to make dropdown list unselectable?

How can I make the <h:selectOneMenu> dropdown list unselectable? 如何使<h:selectOneMenu>下拉列表无法选择?

It is not like using disabled . 它不像使用disabled I just want to make the dropdown list options unselectable and to appear with a different (inactive) style class. 我只想让下拉列表选项无法选择,并以不同的(非活动)样式类出现。

How can I achieve this? 我怎样才能做到这一点? By a JSF component attribute or CSS or JavaScript? 通过JSF组件属性或CSS或JavaScript?

<asp:DropDownList ID="ddlName" runat="server" style="pointer-events: none; cursor: default;">
</asp:DropDownList>

Add style attribute to DropDownList as style="pointer-events: none; cursor: default;" style属性添加到DropDownList作为style="pointer-events: none; cursor: default;" . This will work succesfully, I have tried this. 这将成功,我试过这个。

If I understand you correctly, all you need to do is use the disabled attribute. 如果我理解正确,您需要做的就是使用disabled属性。

So, if you have a select tag like this: 所以,如果您有这样的选择标记:

<select>
  <option>Value</option>
  <option>Value</option>
  <option>Value</option>
</select>

Simply change it to this: 只需将其更改为:

<select disabled>
  <option>Value</option>
  <option>Value</option>
  <option>Value</option>
</select>

Some doctypes require all attributes to have values, in order to be valid. 某些doctypes要求所有属性都具有值,以便有效。 In that case, you can just use disabled="true" instead. 在这种情况下,您可以使用disabled="true"代替。

According to this answer , some browsers allow to change the style of disabled components (non-IE), some not (IE). 根据这个答案 ,一些浏览器允许改变禁用组件的风格(非IE),有些则不允许(IE)。 However, the answer is 3 years old - a long time for browsers. 但是,答案是3年 - 浏览器需要很长时间。 So you could try a solution like: 所以你可以试试像这样的解决方案:

<h:selectOneMenu disabled="true" style="..." ...>

... and check the result with different browsers. ...并使用不同的浏览器检查结果。

Or alternatively use the readonly attribute: 或者使用readonly属性:

<h:selectOneMenu readonly="true" style="..." ...>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM