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

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

I have the following script which does not work



        
6条回答
  •  天命终不由人
    2021-01-31 08:29

    As Anthony Grist pointed out, the .on() method is expecting a function reference at that part; you're evaluating a function which returns nothing (null).

    However, one fun feature of JavaScript is that everything is an object, including functions. With a small modification, you can change ADS() to return an anonymous function object instead:

    function ADS(e){ 
        return function(){ alert(e); };
    }
    

    http://jsfiddle.net/cSbWb/

提交回复
热议问题