任何方式来重写.blur()如果.submit()在jQuery中被调用? [英] Any way to override .blur() if .submit() is called upon in jQuery?

查看:196
本文介绍了任何方式来重写.blur()如果.submit()在jQuery中被调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为网站编写CMS的自定义代码。当用户点击提交按钮(使用jQuery UI创建)时,它会调用按钮上的click事件,然后调用提交表单的提交事件。



<所述表单还检查特定字段以查看它们是否具有文本,并将显示错误消息并停用提交按钮,直到问题得到解决。要做到这一点,我目前使用的.focus(),其中有一个.blur()函数,检查是否错误是固定的,如果是的话(如果没有其他错误,重新激活按钮)。

现在,我遇到的问题是,如果用户随时编辑其中一个被检查的字段,如果他们没有点击它并尝试提交表单数据,.blur()函数接受控制(因为它应该如何编码),所以需要第二次点击来提交表单数据。



有没有办法让.submit()在jQuery中优先于.blur(),所以这个问题不会发生(现在我可以简单地告诉用户使用这个不做的步骤来引起它)如果你们需要代码,我可以尝试在这里发布一些内容。)

解决方案 / div>昨天晚上想了一会儿之后,我意识到如果在我调用blur()之前做了一个快速检查以确定错误是否可见,将解决我的问题(做了一个快速的测试,似乎有)。

感谢有关事件传播停止的建议,但我必须保持记住。


I'm writing up custom code for a CMS for a website. When a user clicks on the submit button (created with jQuery UI), it calls the click event on the button, which in turn calls a submit event, which submits the form.

Said form also checks specific fields to see if they have text, and will show error messages and deactivate the submit button until the issues are resolved. To do this, I currently use .focus(), which has a .blur() function inside it which checks to see if the error was fixed and removes the notice if so (and if there's no other errors, re-activates the button).

Now, the issue I have is that if the user edits one of the fields being checked at any time, if they don't click out of it and try submitting the form data, the .blur() function takes control (as it should by how this is coded), so it takes a second click to submit the form data.

Is there a way to have .submit() take precedence over .blur() in jQuery so this issue can't occur (for now I can simply tell the users using this to not do the steps to cause it)?

(If you guys need code I can try posting some bits of it in here.)

解决方案

After thinking about it a bit last night I realized that if I did a quick check to make sure if the error was visible or not before I called blur(), it would fix my problem (did a quick test and it seems to have).

Thanks for the suggestion about the event propagation stop, though, I'll have to keep that in mind.

这篇关于任何方式来重写.blur()如果.submit()在jQuery中被调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆