[英]How to get event that has fired the function?
Suppose that I've this: 假设我有这个:
<form onsubmit="Popup(this)">
when I press the submit
button the Popup
function is fired. 当我按下submit
按钮时, Popup
功能被触发。 How can I get the submit
event and prevent it? 如何获取并阻止submit
事件?
Popup: function(item)
Thanks. 谢谢。
try this: 尝试这个:
function( item ) {
alert( "Handler for .submit() called." );
item.preventDefault();
// rest of the code
}
OR 要么
$("#form_id").validate({
submitHandler: function (form) {
// do code
return false;
}})
Since you tagged your question with jQuery. 由于您使用jQuery标记了问题。
$('form').submit(Popup); //this inside the function is the form.
// The first parameter is the event.
And make sure to return false from Popup
并确保从Popup
返回false
If Popup
isn't a constructor, use camelCase naming 如果Popup
不是构造函数,请使用camelCase命名
Your existing code should work if you just modify it just a bit. 如果您只需稍作修改,您的现有代码就可以使用。 Add return
to your Popup
method call 将return
添加到您的Popup
方法调用中
<form onsubmit="return Popup(this)">
And at the end of your method declaration add return false
在方法声明的末尾添加return false
Popup: function(item){
// your code goes here
return false; //add this
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.