JavaScript错误显示“确认不是函数",提示“不是函数". [英] JavaScript error says "confirm is not a function"
问题描述
提交表单时,我正在使用带有验证插件的jQuery:
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();
}
});
在submitHandler中,
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?
当我在控制台中输入"confirm"时,我得到以下提示:
When I type "confirm" into the console I get this:
检查DOM会发现:
窗口> Confirm()没有可显示该对象的属性.
在Script中进行检查会将我带到jquery-1.6.2.min.js中的一个地方
Inspecting in Script takes me to a place in jquery-1.6.2.min.js
推荐答案
如果分配不带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.
这篇关于JavaScript错误显示“确认不是函数",提示“不是函数".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!