[英]OnClick Event on a disabled input
onclick
event on an <input>
tag which is disabled. <input>
标签上有一个onclick
事件,该事件被禁用。 onclick
event doesn't work. onclick
事件不起作用。 onclick
event for disabled input based on id? onclick
事件? input
worked but I need worked same as second one also same as of first one. input
工作但我需要与第二次input
相同,也与第一次input
相同。 (I need to call function Clicked
on input
only). Clicked
on input
only)。 My code: 我的代码:
function Clicked(event) { alert(event.id) } function ClickedDisabled(event) { alert(event.ids) }
<input type="text" id="ID" onclick="Clicked(this)" /> <input type="text" id="IDs" onclick="ClickedDisabled(this)" disabled />
function Clicked(event) { alert(event.id) } function ClickedDisabled(event) { alert(event.id) }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> <input type="text" id="ID" onclick="Clicked(this)" /> <span style="position:relative;"> <input type="text" id="IDs" disabled /> <div style="position:absolute; left:0; right:0; top:0; bottom:0; cursor: pointer;" id="IDs" onclick="ClickedDisabled(this)"></div> </span>
Try this it may help you 试试这可能会对你有所帮助
Put 放
input[disabled] {pointer-events:none}
in your CSS (it prevents some browsers from discarding clicks on disabled inputs altogether), and capture the click on a parent element. 在您的CSS中(它可以防止某些浏览器完全放弃对已禁用输入的点击),并捕获父元素上的点击。 It's a cleaner solution, IMHO, than putting a transparent overlay over the element to capture the click, and depending on circumstances may also be much easier than simply "simulating" the disabled state using CSS (since that won't prevent the input from being submitted, and also requires overriding the default browser 'disabled' style).
这是一个更清洁的解决方案,恕我直言,而不是在元素上放置透明覆盖来捕获点击,并且根据情况也可能比使用CSS简单地“模拟”禁用状态容易得多(因为这不会阻止输入提交,还需要覆盖默认浏览器“禁用”样式。
If you have multiple such buttons, you'll need a unique parent for each, in order to be able to distinguish which button was clicked, because with pointer-events:none
, the click target is the button's parent rather than the button itself. 如果您有多个这样的按钮,则每个按钮都需要一个唯一的父按钮,以便能够区分单击了哪个按钮,因为使用
pointer-events:none
,单击目标是按钮的父按钮而不是按钮本身。 (Or you could test the click coordinates, I suppose...). (或者你可以测试点击坐标,我想......)。
If you need to support older browsers, though, do check which ones support pointer-events
: http://caniuse.com/#search=pointer-events 但是,如果您需要支持旧版浏览器,请检查哪些支持
pointer-events
: http : //caniuse.com/#search=pointer-events
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.