function addValidEvent(item,event,func)
{
if (item.addEventListener)
{
item.addEventListener(event, func, false);
}
else
if (item.attachEvent)
{
item.attachEvent("on" + event, func);
} else {
//todo
}
}
我这样调用它
addValidEvent(element, "mouseover", inRadio(element));
inRadio 这是其他函数,我需要注册它而不在 addValidEvent 调用中调用 inRadio 。
如何正确传递 param 这样的函数?
最佳答案
将其作为函数传递。现在您正在调用 inRadio 方法。像这样做
addValidEvent(element, "mouseover", function() {inRadio(element); });
关于Javascript函数作为其他函数的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9279500/