Use event arguments with other arguments?

喜夏-厌秋 提交于 2020-01-06 01:30:13

问题


Here's what I want to do:

function someEvent(e) {
}

onxxxx="someEvent()"

and turn that into:

function someEvent(e, arg1, arg2) {
}

onxxxx="someEvent(???)"

So basically, I want to pass other arguments including the default event one, but I'm not sure quite how to


回答1:


You can pass the event object as an argument:

onxxxx="someEvent(event, arg1, arg2);"

event must be literal event here.

Within the eventhandler function you find them like so:

function someEvent(e, a, b) {
    // e === event object
    // a === arg1
    // b === arg2
}



回答2:


You could use anonymous functions:

var arg1 = "12345 - test", arg2 = 42;

onxxxxx = function(e) {
    someEvent.call(this, e, arg1, arg2);
};


来源:https://stackoverflow.com/questions/21946909/use-event-arguments-with-other-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!