简体   繁体   English

为什么禁用提交按钮会阻止触发我的提交事件处理程序,我该如何解决?

[英]Why does disabling a submit button prevent my on submit event handler from being triggered, and how do I work around this?

event handler gets called 事件处理程序被调用

<form>
    <input/>
    <button onclick="this.form.submit();">submit</button>
</form>​

event handler does not get called 事件处理程序未调用

<form>
    <input/>
    <button onclick="var btn=this;btn.disabled=true;setTimeout(function(){btn.disabled=false;},1500);this.form.submit();">submit</button>
</form>​

Without modifying the <button> HTML, is there some way I can bind an event the to the form submit? 在不修改<button> HTML的情况下,是否可以通过某种方法将事件绑定到表单提交? It doesn't seem to fire if I disable the button before submitting the form. 如果我在提交表单之前禁用了按钮,似乎不会触发。


I think this only happens in Chrome (tested on Ubuntu and Win7). 我认为这只会在Chrome (在Ubuntu和Win7上测试过)中发生。 Both fiddles work in Win7 Firefox 11. 两者都可以在Win7 Firefox 11中使用。

如果将函数移出按钮元素,则效果很好http://jsfiddle.net/272tw/8/,或者如果您需要将其保留在按钮中,并将其放在anon函数中,则该函数也可以http://jsfiddle.net / 272tw / 9 /

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM