Get the name (type) of the event that was fired (triggered)

后端 未结 3 1809
梦谈多话
梦谈多话 2020-12-30 18:25

I have the following code:

$(\'#button\').on(\'click change\', function() {
    alert(\'Who fired me, click or change?\');
});

How can I kn

3条回答
  •  太阳男子
    2020-12-30 19:04

    @Vega solution is correct for simple events. However, if you namespace your events, (i.e. player.play) then you must get the namespace as well. For example, lets say I trigger the event:

    $('#myElement').trigger('player.play');
    

    Then to get the full event name, you need to do the following:

    $('#myElement').on('player.play', function(e) {
        console.log('Full event name: ' + e.type + '.' + e.namespace);
    });
    

提交回复
热议问题