在我的表单中,我使用 jquery form validate plugin验证表单。但问题是错误消息在每个字段下方多次显示。正如您在下面的屏幕截图中看到的那样。 这在 Chrome 中正常工作,但在 Firefox 中不正常。
.
我发现这个错误发生在我使用字段 name="id"
<input name="id" class=""/>
我正在使用以下代码
$('document').ready(function(){
$("#form").validate({
rules : {
"id":{
required:true,
digits:true
},
"user_login":{
required:true
},
"user_pass":{
required:true
}
},
messages: {
"id":{
required: "This field is required"
},
"user_login":{
required: "This field is required"
},
"user_pass":{
required: "This field is required"
}
},
submitHandler: function(form){
var formData = $('#form').serialize();
$('#form').unbind("submit"); // fix for IE
$.ajax({
url: "",
data:formData,
type:"POST",
error: function(error){
},
success: function(data) {
}
});
return false;
});
});
如何避免在每个字段中附加多条错误消息。
编辑:我的 HTML 代码是
<form id="form" name="" method="POST" action="">
<ul class="formstyle">
<li>
<label>Id</label>
<input type="text" name="id" class="" />
</li>
<li>
<label>User Login</label>
<input type="text" name="user_login" class="" />
</li>
<li>
<label>User Pass</label>
<input type="text" name="user_pass" class="" />
</li>
<li>
<input type="submit"/>
</li>
</ul>
</form>
最佳答案
在如下所示的表格标签内使用表单时,可能会发生同样的问题:
<table width="600">
<form id="form" name="" method="POST" action="">
... (rest of the table elements)
</form>
</table>
要解决此问题,您需要在表单标签内提供表格标签,如下所示:
<form id="form" name="" method="POST" action="">
<table width="600">
... (rest of the table elements)
</table>
</form>
希望这对您有所帮助。
关于jquery - 错误 : Jquery form validate plug is appending duplicate error messages per field in firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7832467/