最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to make dropdown list unselectable? - Stack Overflow

programmeradmin5浏览0评论

How can I make the <h:selectOneMenu> dropdown list unselectable?

It is not like using 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?

How can I make the <h:selectOneMenu> dropdown list unselectable?

It is not like using 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?

Share Improve this question edited Apr 30, 2012 at 18:08 BalusC 1.1m376 gold badges3.6k silver badges3.6k bronze badges asked Apr 30, 2012 at 5:13 AKZapAKZap 1,2116 gold badges18 silver badges31 bronze badges 3
  • What do you mean with "unchangeable/unselectable"? That nothing happens when clicking on it (no drop down) or that selecting a value doesn't let it show up, or that it has no effect when submitting? – Zeemee Commented Apr 30, 2012 at 5:28
  • @Mulmoth "unchangeable/unselectable" mean that nothing happens when clicking on it (no drop down). – AKZap Commented Apr 30, 2012 at 5:37
  • Then the disabled attribute is the only option. – Zeemee Commented Apr 30, 2012 at 5:57
Add a comment  | 

3 Answers 3

Reset to default 15
<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;". This will work succesfully, I have tried this.

If I understand you correctly, all you need to do is use the disabled attribute.

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. In that case, you can just use disabled="true" instead.

According to this answer, some browsers allow to change the style of disabled components (non-IE), some not (IE). However, the answer is 3 years old - a long time for browsers. 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:

<h:selectOneMenu readonly="true" style="..." ...>
发布评论

评论列表(0)

  1. 暂无评论