How to pass arguments to addEventListener listener function?

前端 未结 30 2323
谎友^
谎友^ 2020-11-21 23:56

The situation is somewhat like-

var someVar = some_other_function();
someObj.addEventListener(\"click\", function(){
    some_function(someVar);
}, false);
<         


        
30条回答
  •  忘掉有多难
    2020-11-22 00:32

    You can add and remove eventlisteners with arguments by declaring a function as a variable.

    myaudio.addEventListener('ended',funcName=function(){newSrc(myaudio)},false);

    newSrc is the method with myaudio as parameter funcName is the function name variable

    You can remove the listener with myaudio.removeEventListener('ended',func,false);

提交回复
热议问题