$( "#bookings" ).validate({
rules: {
email: {
required: true,
email: true
},
message: {
email: {
required: "field is required",
email: "invalid email"
},
errorLabelContainer: $("ul", $('div#results')), wrapper: 'li',
errorContainer: $('div#results'),
errorPlacement: function(error, element) {
$('#results').append(error);
}
success: function(error){
error.remove();
}
});
<div id="results">
</div>
<form name="bookings" id="bookings" method="post" action="#">
<div class="item" style="clear:left;">
<label>E Mail *</label>
<input id="femail" name="email" type="text">
</div>
</form>
我想要实现的是错误出现在ONCE。到目前为止,我已成功删除。但是错误会一直反复追加,直到验证成功为止。
答案 0 :(得分:9)
<强> JS: - 强>
$("#bookings").validate({
rules: {
email: {
required: true,
email: true
},
message: {
email: {
required: "field is required",
email: "invalid email"
},
errorLabelContainer: $("ul", $('div#results')), wrapper: 'li',
errorContainer: $('div#results'),
errorPlacement: function (error, element) {
$('#results').append(error);
},
success: function (error) {
error.remove();
}
}
}
});
答案 1 :(得分:1)
摆脱您的errorLabelContainer
,wrapper
,errorContainer
,errorPlacement
和success
选项并将其改为:
wrapper: 'li',
errorLabelContainer:$('#results')
你所拥有的东西基本上是复制(很差)默认情况下Validation插件的功能。
看到它在这里工作:http://jsfiddle.net/hGNRG/1/(提示@ wiz-kid创建小提琴)。