替代window.event.srcElement效果的可兼容性的函数_javascript技巧
时间:2021-07-01 10:21:17
帮助过:111人阅读
代码如下:
function getEvent()
{
var i = 0;
if(document.all){
return window.event;
}
func = getEvent.caller;
while(func != null)
{
var arg0 = func.arguments[0];
if(arg0)
{
if(arg0.constructor == MouseEvent)
{
return arg0;
}
}
func = func.caller;
}
return null;
}
函数中要引用须传参e才能等到:
代码如下:
function buttonOver(e)
{
e = getEvent();
var obj = e.srcElement || e.target;
if (obj.runtimeStyle){
obj.runtimeStyle.cssText = "background-color:#FFFFFF";
}
else
obj.style.background = "#FFFFFF";
}