Maintaining the value of 'this' when using event listener

前端 未结 2 1334
太阳男子
太阳男子 2021-01-25 12:22

I have the following function:

onDocumentKeyUp: function (e) {
    if (e.keyCode === 27) {
       this.deactivate();
    }
}

I wanted to bind t

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-25 13:09

    Draw your attention on data parameter of the on method here: http://api.jquery.com/on/ Also you can utilize jQuery.proxy method: http://api.jquery.com/jQuery.proxy/

    Here is jsFiddle: jsFiddle

提交回复
热议问题