JavaScript 错误显示“确认不是函数”
当我提交表单时,我将 jQuery 与验证插件一起使用:
$('.frmProject:visible').validate( {
errorContainer: ".site_details:visible .messageBox1",
errorLabelContainer: ".site_details:visible .messageBox1 span.messagehere",
invalidHandler: function(form, validator) {
},
rules: {
site_id: {
required: true,
}
},
messages: {
site_id: "Project has no assigned site information. Click the marker on the map at left to specify the site where this project took place."
},
submitHandler: function(data) {
SaveProject();
}
});
在submitHandler 中,
function SaveProject(){
//... load variables with input contents
$.ajax({
url: 'ajax/save_project.php',
dataType: 'json',
data: 'id='+id+'&title='+title+'&project='+project+'§or='+sector+'&volunteer='+volunteer+'&lat='+lat+'&lng='+lng+'&name='+name+'&mun='+mun+'&prov='+prov,
success: function(data) {
//... load 'messages' object with stuff
$.each(messages, function(key, value) {
if (confirm(key)){
console.log(item);
}
});
}
});
}
当我提交经过验证的表单并且它到达每个循环内的确认时,我收到错误消息:“confirm 不是函数”。
如何向用户显示消息以供确认?
编辑:
当我在控制台中输入“confirm”时,我得到:
在 DOM 中检查显示:
window >确认() 该对象没有可显示的属性。
在脚本中检查将我带到 jquery-1.6.2.min.js 中的某个位置
I'm using jQuery with the validation plugin when I submit a form:
$('.frmProject:visible').validate( {
errorContainer: ".site_details:visible .messageBox1",
errorLabelContainer: ".site_details:visible .messageBox1 span.messagehere",
invalidHandler: function(form, validator) {
},
rules: {
site_id: {
required: true,
}
},
messages: {
site_id: "Project has no assigned site information. Click the marker on the map at left to specify the site where this project took place."
},
submitHandler: function(data) {
SaveProject();
}
});
In the submitHandler,
function SaveProject(){
//... load variables with input contents
$.ajax({
url: 'ajax/save_project.php',
dataType: 'json',
data: 'id='+id+'&title='+title+'&project='+project+'§or='+sector+'&volunteer='+volunteer+'&lat='+lat+'&lng='+lng+'&name='+name+'&mun='+mun+'&prov='+prov,
success: function(data) {
//... load 'messages' object with stuff
$.each(messages, function(key, value) {
if (confirm(key)){
console.log(item);
}
});
}
});
}
When I submit the validated form and it gets to the confirm inside the each loop, I get the error message: "confirm is not a function".
How can I present a message to the user for confirmation?
Edit:
When I type "confirm" into the console I get this:
Inspecting in DOM reveals:
window > confirm()
There are no properties to show for this object.
Inspecting in Script takes me to a place in jquery-1.6.2.min.js
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
确认函数是窗口对象的一部分。
The confirm function is part of the window object.
如果您分配一个不带 var 的变量,则将该变量分配给全局空间。在您的情况下,有一个字符串分配给了确认变量,该变量覆盖了本机确认方法。
If you assign a variable without var, you are assigning that variable to the global space. In your case there was a string assigned to the confirm variable that overrode the native confirm method.
定义任何带有属性 id ="confirm" 的 html 对象也会导致此错误
Defining any html object with attribute id ="confirm" also causes this error
我同时使用“jquery确认”和“数据表”,在我的情况下,“数据表”应该在“jquery确认”之前导入。
所以,在某些情况下,尝试重新订购........
I use both 'jquery confirm' and 'datatables', in my case, 'datatables' should be imported before 'jquery confirm'.
So, in some case, try ReOrder ........