我试图阻止使用jQuery Tools Validation进行双重提交,并且鉴于我们在这里使用的onFail,我遇到了一些麻烦。有任何想法吗?尝试使用计时器/超时,但这真的只是一个可怕的解决方案。
$("form").submit(function(){
$('input[type=submit]').click(function(event){
event.preventDefault();
});
});
$("form").bind("onFail", function(e, errors) {
// we are only doing stuff when the form is submitted
if (e.originalEvent.type == 'submit') {
// loop through Error objects and add the border color
$.each(errors, function() {
var input = this.input;
input.stop(true).effect("shake", { times:3 }, 75);
input.css({borderColor: '#D94E27'}).focus(function() {
input.css({borderColor: '#444'});
});
});
}
});
$("form").validator({
message: '<div class="errormessages"></div>',
position: 'center right',
offset: [0, 0]
});
答案 0 :(得分:0)
啊找到了它:
$("form").validator({
message: '<div class="errormessages"></div>',
position: 'center right',
offset: [0, 0]
}).bind("onFail", function(e, errors) {
// we are only doing stuff when the form is submitted
if (e.originalEvent.type == 'submit') {
// loop through Error objects and add the border color
$.each(errors, function() {
var input = this.input;
input.stop(true).effect("shake", { times:3 }, 75);
input.css({borderColor: '#D94E27'}).focus(function() {
input.css({borderColor: '#444'});
});
});
}
}).submit(function(e) {
// client-side validation passed
if (!e.isDefaultPrevented()) {
$("button[type=submit], input[type=submit]").attr('disabled', true);
}
});