开发者

Are jQuery events blocking

Are jQuery events blocking?

For example does calling the following method return immediately?

$("body").trigger("myEventName", myValue);

My testing seems to suggest they are. If this is correct does this mean I can return values from my custom events?

var myResult = $("body").trigger("myEventName", myValue);

Clearly this doesnt work as this returns the jQuery object. So can values 开发者_C百科be returned?


You can use the .triggerHandler() method for this, it returns whatever the last event handler for that event on that selector returns (instead of a jQuery object for chaining), just use it like this:

var myResult = $("body").triggerHandler("myEventName", myValue);

You can give it a try here.

Check out the documentation page for the list of differences from .trigger().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜