javascript - How to pause an event in jQuery? - Stack Overflow

I have a question regarding events.Basically, I want to run a jquery method when the user clicks a link

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 badges
Add a ment  | 

1 Answer 1

Reset to default 4

If 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745267945a4619571.html

相关推荐

  • javascript - How to pause an event in jQuery? - Stack Overflow

    I have a question regarding events.Basically, I want to run a jquery method when the user clicks a link

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信