In Console I got following error using e.preventDefault() method I used e as a function parameter
在Console中我使用e.preventDefault()方法得到以下错误我使用e作为函数参数
function function1(e){
e.preventDefault();
}
1533 Uncaught TypeError: Cannot read property 'preventDefault' of undefined
1533 Uncaught TypeError:无法读取未定义的属性'preventDefault'
3 个解决方案
#1
5
You have to pass event
in the used function:
您必须在used函数中传递事件:
function1(event); // where you called it
Make sure you call this function within an event handler. Such as :
确保在事件处理程序中调用此函数。如 :
$(document).click(function(event){
function1(event);
});
#2
0
i remove event from function and invoke function in this way
我从函数中删除事件并以这种方式调用函数
onserverclick="btnSave_OnServerClick" onclick="return jsFunction();">Save
onserverclick =“btnSave_OnServerClick”onclick =“return jsFunction();”> Save
In javascript
function jsFunction() {
alert('call');
if ($('#form1').
bootstrapValidator('validate').has('.has-error').length) {
alert('SOMETHING WRONG');
} else {
alert('EVERYTHING IS GOOD');
__doPostBack('<%=btnSave.UniqueID%>', '');
}
return false;
}
#3
0
You are writing the function wrong. Suppose you are using function on a particular button click having id as 'clickBtn' then you need to write function like this.
你写错了函数。假设您在特定按钮上使用函数,单击id为“clickBtn”,那么您需要编写这样的函数。
$("#clickBtn").on("click", function(e){
e.preventDefault();
});
#1
5
You have to pass event
in the used function:
您必须在used函数中传递事件:
function1(event); // where you called it
Make sure you call this function within an event handler. Such as :
确保在事件处理程序中调用此函数。如 :
$(document).click(function(event){
function1(event);
});
#2
0
i remove event from function and invoke function in this way
我从函数中删除事件并以这种方式调用函数
onserverclick="btnSave_OnServerClick" onclick="return jsFunction();">Save
onserverclick =“btnSave_OnServerClick”onclick =“return jsFunction();”> Save
In javascript
function jsFunction() {
alert('call');
if ($('#form1').
bootstrapValidator('validate').has('.has-error').length) {
alert('SOMETHING WRONG');
} else {
alert('EVERYTHING IS GOOD');
__doPostBack('<%=btnSave.UniqueID%>', '');
}
return false;
}
#3
0
You are writing the function wrong. Suppose you are using function on a particular button click having id as 'clickBtn' then you need to write function like this.
你写错了函数。假设您在特定按钮上使用函数,单击id为“clickBtn”,那么您需要编写这样的函数。
$("#clickBtn").on("click", function(e){
e.preventDefault();
});