无法读取属性';防止违约';javascript错误中未定义的
在控制台中,我使用e.preventDefault()方法得到了以下错误 我使用e作为函数参数无法读取属性';防止违约';javascript错误中未定义的,javascript,jquery,Javascript,Jquery,在控制台中,我使用e.preventDefault()方法得到了以下错误 我使用e作为函数参数 function function1(e){ e.preventDefault(); } 1533未捕获的TypeError:无法读取未定义的属性“preventDefault” 称为function1-like <a href="#none" onclick="function1()">Click Me</a> 您必须在使用的函数中传递事件
function function1(e){
e.preventDefault();
}
1533未捕获的TypeError:无法读取未定义的属性“preventDefault”
称为function1-like
<a href="#none" onclick="function1()">Click Me</a>
您必须在使用的函数中传递
事件
:
function1(event); // where you called it
例如:
<a href="#none" onclick="function1(event)">Click Me</a>
我从函数中删除事件,并通过以下方式调用函数:
保存
在JavaScript中:
函数jsFunction(){
警报(“呼叫”);
if($('#form1').bootstrapValidator('validate').has('has error').length){
警惕(“出了什么事”);
}否则{
警惕(“一切都很好”);
__doPostBack('','');
}
返回false;
}
您编写的函数有误。假设您在一个特定的按钮上使用函数,单击id为'clickBtn',那么您需要这样编写函数
$("#clickBtn").on("click", function(e){
e.preventDefault();
});
您未能在html中的in-luck事件中将事件作为参数传递。 因此,应将其写成以下示例:
<a href="#none" onclick="function1(event)">Click Me</a>
function function1(event){
e.preventDefault();
}
功能1(事件){
e、 预防默认值();
}
语法错误-函数(e)如果您在没有参数的情况下调用该函数,它将抛出该语法错误您如何使用该函数函数1
?在按钮单击事件上我调用该函数1在提交按钮单击上我调用该函数1您可以在问题中添加单击事件吗?保存函数jsFunction(事件){alert('call');if($('#form1').bootstrapValidator('validate').has('.has error').length){event.preventDefault();}else{alert('EVERYTHING IS GOOD');u doPostBack('',);}返回false;}请注意,您使用event
作为参数,但函数e
内部仍在使用。
<a href="#none" onclick="function1(event)">Click Me</a>
function function1(event){
e.preventDefault();
}