jQuery errorPlacement [英] jquery errorPlacement
本文介绍了jQuery errorPlacement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下内容:
$("#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(");那么我只会收到一条错误消息.
I am trying to insert the error messages to a div above the form. My problem is if I remove this line : $('#errorList').html(""); then it displays the error messages correctly the first time. If i hit the submit one more time, it will append another set of messages to the div. If I keep $('#errorList').html(""); then I will get only one error message.
如何刷新errorList,以使其不会重复出现并正确显示错误消息?
How do I refresh the errorList so it doesn't repeat itself and displays the error messages correctly?
提前谢谢.
推荐答案
这有效:
$("#addPmtAcctForm").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_num'
}
},
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>"
},
errorLabelContainer: $("ul", $('div.error')), wrapper: 'li',
errorContainer: $('div.error'),
errorPlacement: function(error, element) {
$('#errorList').append(error);
}
});
这篇关于jQuery errorPlacement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文