admin管理员组文章数量:1418025
I have a question regarding events.
Basically, I want to run a jquery method when the user clicks a link to leave the page. In this method I want to check a few things before they leave, so I know I can call:
e.preventDefault();
But what if I want the event to continue after I prevent the event?
Any suggestions how to approach this?
Thank you!
I have a question regarding events.
Basically, I want to run a jquery method when the user clicks a link to leave the page. In this method I want to check a few things before they leave, so I know I can call:
e.preventDefault();
But what if I want the event to continue after I prevent the event?
Any suggestions how to approach this?
Thank you!
Share Improve this question asked Oct 30, 2012 at 15:40 Base33Base33 3,2154 gold badges28 silver badges31 bronze badges1 Answer
Reset to default 4If the method is synchronous you can just call it from within the event handler. The default action will not be executed until the handler returns, so you have as much time as you want to decide if you want to prevent it or not.
If the method is async things get more plicated. Since it will not be possible to wait on the method you will have to unconditionally prevent the default action and trigger it again conditionally -- probably with .trigger()
or .triggerHandler()
-- after the async method has pleted.
本文标签: javascriptHow to pause an event in jQueryStack Overflow
版权声明:本文标题:javascript - How to pause an event in jQuery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745267945a2650716.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论