jQuery .trigger() multiple events

前端 未结 4 1816
北海茫月
北海茫月 2020-12-29 23:22

I\'m writing a jQuery plugin and using .on and .trigger as my pub/sub system. However, I want to trigger multiple events in different scenarios.

4条回答
  •  猫巷女王i
    2020-12-30 00:21

    What you have is fine... you can't trigger multiple events using a comma separated list. The trigger() constructor only takes an event name and optional additional parameters to pass along to the event handler.

    An alterternative would be to trigger all events attached to an element, however, this may not meet your needs if you need to trigger specific events in different senarios:

    $.each($this.data('events'), function(k, v) {
        $this.trigger(k);
    });​
    

提交回复
热议问题