jQuery .on() method - passing argument to event handler function

前端 未结 6 1381
别那么骄傲
别那么骄傲 2021-01-31 07:49

I have the following script which does not work



        
6条回答
  •  伪装坚强ぢ
    2021-01-31 08:50

    Actually, there is a very neat simple way to achieve this, with no extra clutter and no anonymous functions, using JS bind():

    $(document).on('dblclick', ADS.bind(null, 'hello'));
    

    First parameter is the value you want "this" to have inside callback function.

    MOre info in Mozilla Developer Network: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind

提交回复
热议问题