jQuery .on() click event catching dynamic 'data-' attribute in list of buttons to pass value to other function?

前端 未结 5 1194
误落风尘
误落风尘 2021-02-07 04:57

I have a dynamic table list of around 40 rows each with an edit button containing a date field. I also have the following click event script trying to attach to each button via

5条回答
  •  一生所求
    2021-02-07 05:13

    If you're changing the context of 'this' keyword to something else, you can retrieve the data directly from the 'event' object like so:

    $('element').on('click', function(event) {
        // 'this' here = externalObject
        this.fnFromExternalObject($(event.currentTarget).data('activate'));
    }.bind(externalObject));
    

    I hope the example above is clear...

提交回复
热议问题