开发者

Are jQuery events blocking

开发者 https://www.devze.com 2023-01-25 20:58 出处:网络
Are jQuery events blocking? For example does calling the following method return immediately? $(\"body\").trigger(\"myEventName\", myValue);

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

精彩评论

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