Can you set event.data with jquery trigger

后端 未结 11 562
轻奢々
轻奢々 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 16:38

    This was the approach I took.

    $('#foo').on('click', { init: false }, function(e, data) {
            data = data || e.data;
            console.log(data.init); // will be true in the trigger, and false in the click.
        })
        .trigger('click', { init: true });
    

提交回复
热议问题