Jquery模糊事件干扰所有其他事件
我有一个包含多个字段的表单。我在所有字段上都有 jquery 模糊事件处理程序,当您离开某个字段时,它们会进行一些验证。问题是,如果您曾经专注于某个字段,然后单击页面上的任何其他链接,它会验证该字段,但决不允许单击该链接(或提交表单)。
$('.required').bind('blur', function(event) {
validateAll($(event.target));
});
function validateAll(elm) {
//blah blah
return false;
}
validateAll 函数只是进行检查并在之后返回 false。
基本上,当用户专注于某个字段时,他们必须单击任何按钮两次才能使其工作。第一个激活模糊验证,然后第二个实际上单击链接。
对于发生的事情有什么想法吗?
I have a form with multiple fields. I have jquery blur event handlers on all the fields that do some validation when you navigate away from a field. The problem is, if you are ever focused on a field, and then you click on any other link on the page, it validates the field but never allows the link to be clicked (or form be submitted).
$('.required').bind('blur', function(event) {
validateAll($(event.target));
});
function validateAll(elm) {
//blah blah
return false;
}
The validateAll function just does a check and returns false after.
Basically, when a user is focused on a field, they must click any button twice in order for it to work. The first one activates the blur validation, and then second one actually clicks through the link.
Any ideas as to what is going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现了一些其他类似的帖子。
常见的解决方案是尝试在模糊事件处理程序中添加延迟,如下所示:
希望这会有所帮助......
I found a few other posts similar to this.
The common solution is to try adding a delay in your blur event handler, like so:
Hope this helps...
您没有在模糊处理程序中返回 validateAll,尽管您说它“只是进行检查并在之后返回 false”。如果它返回 false 来尝试阻止进一步的事件冒泡,您需要返回该值,而不是仅仅调用 validateAll (并对它返回的内容不执行任何操作)。
不明白其中任何一个会如何导致您所描述的问题,但也许我只是误解了这个问题。
You're not returning validateAll in your blur handler, although you said it "just does a check and returns false after". If it's returning false to try and prevent further event bubbling, you'd want to return that rather than just calling validateAll (and doing nothing with what it returns).
Don't see how any of that would cause the problem you're describing, but maybe I'm just misunderstanding the issue.