Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DennisXie/75efde33ef6af71eed59e2e6acc8da7c to your computer and use it in GitHub Desktop.
Save DennisXie/75efde33ef6af71eed59e2e6acc8da7c to your computer and use it in GitHub Desktop.
表单禁止二次提交
$("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