Created
May 11, 2018 02:45
-
-
Save DennisXie/75efde33ef6af71eed59e2e6acc8da7c to your computer and use it in GitHub Desktop.
表单禁止二次提交
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("form").submit(function() { | |
$(this).submit(function() { | |
return false; | |
}); | |
return true; | |
}); | |
$( "#target" ).submit(function( event ) { | |
alert( "Handler for .submit() called." ); | |
event.preventDefault(); | |
}); | |
Now when the form is submitted, the message is alerted. | |
This happens prior to the actual submission, so we can cancel | |
the submit action by calling .preventDefault() on the event | |
object or by returning false from our handler. | |
We can trigger the event manually when another element is clicked: | |
该回调函数会在提交表单前运行,禁用默认方法或者返回false可以禁止提交 | |
ref: https://api.jquery.com/submit/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment