javascript - jQuery '.click(callback)' prevents the default event -
I'm trying to stop double-clicking on a form button , for which element Has been disabled for a few seconds.
& lt; Form action = "#" method = "POST" & gt; & Lt; Input type = "text" / & gt; & Lt; Input type = "password" /> & Lt; Button class = "myButton" type = "submit" & gt; Send & lt; / Button & gt; & Lt; / Form & gt; Var = this; This.element = $ (". MyButton"); This.element.click (function (e) {this.element.prop ("disabled", true); window.setTimeout (function () {that.element.prop ("disabled", false);}, 2000); }); It succeeds in enabling / deactivating, but the .click () function prevents the promotion of events (automatically? O_o), and Page < Note
PS - Any solution should be cross-browser and should be compatible with IE8. By disabling the button
, you are blocking the operation of the post. Then disable the form you want to do and then use the JavaScript call to actually submit the form. It may look like this:
$ ('. Mybutton'). Click (function () {$ button = $ (this); $ button.attr ('disabled', true); $ Button.closest ('form'). Submit (); setTimeout (function () {$ button. Attr ('disabled', false);}, 2000);});
Comments
Post a Comment