问题
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