我有以下内容:
$("#pmtForm").validate({
rules: {
acct_name: "required",
acct_type: "required",
acct_routing: {
required: true,
digits: true,
exactLength:9
},
acct_num: {
required: true,
digits: true
},
c_acct_routing:{
equalTo: '#acct_routing'
},
c_acct_num: {
equalTo: '#acct_routing'
}
},
messages: {
acct_name: "<li>Please enter an account name.</li>",
acct_type: "<li>Please choose an account type.</li>",
acct_routing: "<li>Please enter a routing number.</li>",
acct_num: "<li>Please enter an account number.</li>",
c_acct_routing: "<li>Please confirm the routing number.</li>",
c_acct_num: "<li>Please confirm the account number.</li>"
},
// errorContainer: '#div.error',
errorPlacement: function(error, element) {
$('#errorList').html("");
$('#errorList').append(error);
$('div.error').attr("style","display:block;");
}
});
我正在尝试将错误消息插入到表单上方的 div 中。我的问题是如果我删除这一行: $('#errorList').html(""); 然后它第一次正确显示错误消息。如果我再次点击提交,它会将另一组消息附加到 div。如果我保留 $('#errorList').html(""); 那么我只会收到一条错误消息。
如何刷新 errorList 使其不会重复并正确显示错误消息?
提前致谢。