Moe*_*eet 44
像这样的东西?
<form onsubmit="do_something()">
function do_something(){
// Do your stuff here
}
Run Code Online (Sandbox Code Playgroud)
如果你return像下面的代码一样,你可以通过从do_something()函数返回false来阻止表单提交.
<form onsubmit="return do_something()">
function do_something(){
// Do your stuff here
return true; // submit the form
return false; // don't submit the form
}
Run Code Online (Sandbox Code Playgroud)
Lau*_*nas 25
如果您正在使用表单,则可以使用onsubmit事件.
使用jQuery你可以做到这一点
$('#myform').submit(function() {
// your code here
});
Run Code Online (Sandbox Code Playgroud)
您可以将事件处理程序绑定到submit事件(以下代码假设你有一个id在你的form):
document.getElementById("someForm").onsubmit = function() {
//Do stuff
};
Run Code Online (Sandbox Code Playgroud)