javascript-将事件和参数传递给使用addEventListener调用的函数

时间:2018-07-07 12:47:28

标签: javascript event-handling parameter-passing addeventlistener

window.addEventListener("keyup", eventkeyup(event, something), false);

    function eventkeyup(event, something) {

    //could not be able to get the event object here.

}

如何使用此功能访问事件?

1 个答案:

答案 0 :(得分:0)

传递函数本身,而不返回其值undefined

window.addEventListener("keyup", eventkeyup(something), false);

function eventkeyup(something) {
    return function(event){
       // you have event and something here
    }
}