我有一个输入按钮,当它被禁用时,有人试图点击它,需要显示警报。如果点击禁用的输入按钮,显示消息
尽管被禁用,如何显示javascript消息?
,没有运气尝试这样做:
<input type="submit" onclick="alert('click')" value="Disabled Input Button" disabled/>
我有一个输入按钮,当它被禁用时,有人试图点击它,需要显示警报。如果点击禁用的输入按钮,显示消息
尽管被禁用,如何显示javascript消息?
,没有运气尝试这样做:
<input type="submit" onclick="alert('click')" value="Disabled Input Button" disabled/>
<span onclick="alert('This input is disabled')">
<input type="submit" value="Disabled Input Button" disabled/>
</span>
用另一个具有点击功能的标签包装它。
使用onmousedown
而不是onclick
,当 '允许的',其仅触发。某些浏览器(尤其是Chrome)在禁用表单元素时会禁用所有DOM事件。虽然我认为这是不符合规范的,可使用以下解决方法:
除了使用disabled
属性,而是使用CSS pointer-events
来达到类似的效果,illustrated here:
button.disabled {
pointer-events:none;
}
,然后只用<button class="disabled">
而不是<button disabled>
。
看到这个:http://stackoverflow.com/a/7834293/3751213,但是你可以使用'mousedown'事件... – j809
http://stackoverflow.com/questions/7833854/jquery-detect的可能重复-click-on-disabled-submit-button –