Can you set event.data with jquery trigger

后端 未结 11 558
轻奢々
轻奢々 2020-12-12 16:27

With jQuery .on() you can pass an optional parameter to set the event data. Can you do this with trigger as well?

11条回答
  •  情深已故
    2020-12-12 17:03

    It took me a while to understand the philosophy behind this. An event involves two entities: listener and dispatcher. The event.data field was intended to be used by the listener only. It's sort of like assigning a name to a phone number:

    $("(818)548-2733").on("incomingcall", null, "Mom", pickup);
    

    You could pick up the phone and wait for the other side to tell you that she is your Mom. Or you can use event.data to attach the extra information relevant to this event.

    The $.trigger and $.triggerHandler methods are called by the dispatcher side of an event. That's why they don't let you specify the event.data. Instead, you can use their extraParameters argument.

提交回复
热议问题