jQuery 验证 invalidHandler 与警报仍然在 Firefox 中提交?
根本无法理解这一点。 使用验证 jQuery (1.6.2) 和验证插件 (1.8.1)。 如果单击提交按钮,则以下 invalidHandler 代码可以在所有浏览器中正常工作。 但是,如果在 Firefox(无论如何版本 5 和 6)中填写任何字段后通过按键盘上的 Enter 来提交表单,您会收到有关错误数量的警报,但表单仍然会提交! 该表单在其他浏览器中不会提交,如果删除警报线,则在 Firefox 中可以正常工作。但我们需要警报,所以如果有人对如何解决这个问题有任何想法,我们将非常感激 - 我不习惯仅在 Firefox 中发生的事情! :)
invalidHandler: function(form, validator) {
var errors = validator.numberOfInvalids();
if (errors)
{
var message = (errors == 1)
? '1 field has an error. It has been highlighted'
: errors + ' fields have errors. They have been highlighted';
alert(message);
//return false;
}
}
Can't fathom this at all.
Using validate jQuery (1.6.2) with validate plugin (1.8.1).
Have the following invalidHandler code which works fine in all browsers if the submit button is clicked.
However, if the form is submit by hitting enter on the keyboard after filling any field in, in Firefox (versions 5 and 6 anyway), you get the alert about the number of errors but the form still submits anyway!
The form is not submit in other browsers, and if the alert line is removed, it works fine in Firefox. But we need the alert, so if anyone has any ideas on how to fix this it would be greatly appreciated - I'm not used to things acting up just in Firefox! :)
invalidHandler: function(form, validator) {
var errors = validator.numberOfInvalids();
if (errors)
{
var message = (errors == 1)
? '1 field has an error. It has been highlighted'
: errors + ' fields have errors. They have been highlighted';
alert(message);
//return false;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过取消注释
return false
?JQuery 文档 表明
false
将:Have you tried uncommenting out
return false
?JQuery documentation indicates that
false
will:我也出现过这个问题。我认为发生的是对alert() 的调用阻止了invalidHandler 函数的执行,这破坏了jQuery.validate 正常运行的方式。
您可以做的是通过 setTimeout 调用启动警报窗口,这不会阻止 invalidHandler 代码的执行:
Hacky,但有效!
I've had this issue occur as well. What I think is going on is that a call to alert() blocks execution of the invalidHandler function, which breaks the way jQuery.validate would normally function.
What you can do is launch an alert window via a setTimeout call, which doesn't block execution of your invalidHandler code:
Hacky, but works!