4

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!

4

1 回答 1

4

如果方法是同步的,您可以从事件处理程序中调用它。在处理程序返回之前不会执行默认操作,因此您有尽可能多的时间来决定是否要阻止它。

如果方法是异步的,事情会变得更加复杂。由于无法等待该方法,因此您必须无条件地阻止默认操作并在异步方法完成后有条件地再次触发它 - 可能使用.trigger()or 。.triggerHandler()

于 2012-10-30T15:41:49.090 回答