admin管理员组文章数量:1356745
I have an input button, which when it is disabled, and someone tries to click it, needs to display an alert.
How is it possible to display a javascript message despite being disabled?
Tried this with no luck:
<input type="submit" onclick="alert('click')" value="Disabled Input Button" disabled/>
I have an input button, which when it is disabled, and someone tries to click it, needs to display an alert.
How is it possible to display a javascript message despite being disabled?
Tried this with no luck:
<input type="submit" onclick="alert('click')" value="Disabled Input Button" disabled/>
-
See this: stackoverflow./a/7834293/3751213, however you may use
mousedown
event... – j809 Commented Jul 15, 2014 at 14:18 - Possible duplicate of stackoverflow./questions/7833854/… – Chris Lam Commented Jul 15, 2014 at 14:24
2 Answers
Reset to default 4Use onmousedown
instead of onclick
, which is only fired when it is 'allowed' to. Some browsers, particularly Chrome, appear to disable all DOM events when a form element is disabled. While I think this is out of spec, you can use the following workaround:
Instead of using the disabled
attribute, use CSS pointer-events
to achieve a similar effect, illustrated here:
button.disabled {
pointer-events:none;
}
And then just use <button class="disabled">
instead of <button disabled>
.
<span onclick="alert('This input is disabled')">
<input type="submit" value="Disabled Input Button" disabled/>
</span>
Wrapping it with another tag that has the on click function works.
本文标签: javascriptIf a disabled input button is clickeddisplay messageStack Overflow
版权声明:本文标题:javascript - If a disabled input button is clicked, display message - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744060259a2583999.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论