[英]Add onclick event to disabled field
I am using a form a custom generator. 我正在使用表单自定义生成器。 The form is specified in a file, this file gets parsed and HTML elements will be generated by JSF 2.x programmatically, for example HtmlInputText by Apache MyFaces.
该格式在文件中指定,该文件将被解析,HTML元素将由JSF 2.x以编程方式生成,例如Apache MyFaces的HtmlInputText。
In our application we have a readonly user role. 在我们的应用程序中,我们具有只读用户角色。 For those users we try to make all input options
disabled
. 对于这些用户,我们尝试
disabled
所有输入选项。 On input
fields we are setting the html readonly
attribute, for other elements, which have no readonly
attribute like select
fields, we are setting disabled
attribute. 在
input
字段上,我们设置html readonly
属性,对于其他元素(如select
字段)没有readonly
属性,我们在设置disabled
属性。
Unfortunately setting disabled=disabled
will inactivate all javascript events too. 不幸的是,设置
disabled=disabled
也会使所有的javascript事件无效。 Now, I need to trigger a javascript-function on click
at a disabled option-field. 现在,我需要在禁用的选项字段
on click
以触发javascript函数。 How can I do this? 我怎样才能做到这一点?
I don't think, there is much you can do about it. 我不认为您可以做很多事情。
though there is one, ugly solution to this. 尽管有一个丑陋的解决方案。
place position:absolute
non-disabled container over your disabled elements ie 放置
position:absolute
非禁用容器,位于禁用元素上方,即
<select disabled="disabled" >
<option>one</option>
<option>two</option>
<option>three</option>
</select>
<div onclick="alert('s')"
style="width:56px;position:absolute; top:1.7%; left:1.6%;height:18px;" >
</div>
where value of top and left for the container depends on the position of the select 容器的顶部和左侧的值取决于选择的位置
Wrap the disabled element in another element that supports the onclick attribute. 将禁用的元素包装在另一个支持onclick属性的元素中。 A good example of this is the
<h:panelGrid/>
一个很好的例子是
<h:panelGrid/>
<h:panelGrid style="width=20px" onclick="foo.myBar()">
<h:someComponent disabled="true"/>
</h:panelGrid>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.