我正在为我的网站中的某些表单使用jquery验证插件。但是其中一个表单的验证不仅适用于IE7和8.但使用相同验证脚本的其他表单也可以。我试图调试并发现问题出在showErrors部分,当我使用“for in”JS循环遍历errorMap时,show对象不支持错误。知道如何解决这个问题吗?
这是我有的HTML
<form name="donate" id="form1" action="https://www.xxxx.xxx.xx/api/help" method="POST" target="_top">
<input type="hidden" name="face" id="faceinput" style="clear: both; margin:0; padding:0;">
<input type="hidden" name="image" id="imageinput" style="clear: both; margin:0; padding:0;">
<h3>Thank you for helping! </h3>
<h4>Please fill out the following details.</h4>
<label>Name: </label>
<input type="text" name="fullname" id="fullname" class="required" />
<div class="clearfix"></div>
<label>Email: </label>
<input type="text" name="email" id="email" class="required email" />
<div class="clearfix"></div>
<label>Amount: </label>
<input type="text" name="amount" id="amount" class="required number minStrict" /><input type="button" id="submitBtn" value="Donate" />
<div class="clearfix"></div>
<div id="error" style="display:none;">
Oops! The minimum amount to donate is $6. Don't wish to donate? Please click on the close button on the top right hand corner instead.
</div>
</form>
的JavaScript
$('#form1').validate({
onkeyup: false,
focusInvalid: false,
rules : {
amount : {
required : true,
number : true,
minStrict : 5
}
},
messages : {
fullname: "Please fill out your name",
email: {required:"Please fill out your email address",email:"Invalid email address"},
amount: {required:"Please fill out amount to donate",number:"Invalid amount",minStrict:"Minimum amount is 6$"}
},
showErrors: function(errorMap, errorList) {
alert('here');
for(error in errorMap){
alert(error);
/*if(error=="fullname" || error=="email" || error=="amount"){
//if(errorMap[error]=='Minimum amount is 6$') {
//$('div#error').show();
//}
//else {
$(':text[name='+error+']').val(errorMap[error]).addClass('error');//append err msg in all text field and hightlight
$('div#error').hide();
}
}*/
}
}
});
$('#submitBtn').click(function(){
if( $("#form1").valid()){
alert('here');
$('div#error').hide();
$('#form1').submit();
}
});
错误
SCRIPT438:Object不支持此属性或方法 validate.js,第26行5字符
通过添加var error ...
来解决for(errorMap中的var error){//
答案 0 :(得分:1)
我不知道为什么,但是使用
for(var error in errorMap){
似乎可以解决您在评论中发布的问题...