手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >javascript 兼容FF的onmouseenter和onmouseleave的代码
javascript 兼容FF的onmouseenter和onmouseleave的代码
摘要:IE下有onmouseenter和onmouseleave来解决。可惜ff就没有。我再想,为什么这么好的功能,为什么ff不引用呢?还有ie中...

IE下有onmouseenter和onmouseleave来解决。

可惜ff就没有。我再想,为什么这么好的功能,为什么ff不引用呢?

还有ie中的onpropertychange,哎,ff中都没有。。。

对比例子中引入了一段js,来兼容FF的onmouseenter和onmouseleave.:

复制代码 代码如下:

varxb=

{

evtHash:[],

ieGetUniqueID:function(_elem)

{

if(_elem===window){return'theWindow';}

elseif(_elem===document){return'theDocument';}

else{return_elem.uniqueID;}

},

addEvent:function(_elem,_evtName,_fn,_useCapture)

{

if(typeof_elem.addEventListener!='undefined')

{

if(_evtName=='mouseenter')

{_elem.addEventListener('mouseover',xb.mouseEnter(_fn),_useCapture);}

elseif(_evtName=='mouseleave')

{_elem.addEventListener('mouseout',xb.mouseEnter(_fn),_useCapture);}

else

{_elem.addEventListener(_evtName,_fn,_useCapture);}

}

elseif(typeof_elem.attachEvent!='undefined')

{

varkey='{FNKEY::obj_'+xb.ieGetUniqueID(_elem)+'::evt_'+_evtName+'::fn_'+_fn+'}';

varf=xb.evtHash[key];

if(typeoff!='undefined')

{return;}

f=function()

{

_fn.call(_elem);

};

xb.evtHash[key]=f;

_elem.attachEvent('on'+_evtName,f);

//attachunloadeventtothewindowtocleanuppossiblyIEmemoryleaks

window.attachEvent('onunload',function()

{

_elem.detachEvent('on'+_evtName,f);

});

key=null;

//f=null;/*DON'Tnullthisout,orwewon'tbeabletodetachit*/

}

else

{_elem['on'+_evtName]=_fn;}

},

removeEvent:function(_elem,_evtName,_fn,_useCapture)

{

if(typeof_elem.removeEventListener!='undefined')

{_elem.removeEventListener(_evtName,_fn,_useCapture);}

elseif(typeof_elem.detachEvent!='undefined')

{

varkey='{FNKEY::obj_'+xb.ieGetUniqueID(_elem)+'::evt'+_evtName+'::fn_'+_fn+'}';

varf=xb.evtHash[key];

if(typeoff!='undefined')

{

_elem.detachEvent('on'+_evtName,f);

deletexb.evtHash[key];

}

key=null;

//f=null;/*DON'Tnullthisout,orwewon'tbeabletodetachit*/

}

},

mouseEnter:function(_pFn)

{

returnfunction(_evt)

{

varrelTarget=_evt.relatedTarget;

if(this==relTarget||xb.isAChildOf(this,relTarget))

{return;}

_pFn.call(this,_evt);

}

},

isAChildOf:function(_parent,_child)

{

if(_parent==_child){returnfalse};

while(_child&&_child!=_parent)

{_child=_child.parentNode;}

return_child==_parent;

}

};

本篇文章来源于cssrain.cn原文链接:http://www.cssrain.cn/article.asp?id=952

【javascript 兼容FF的onmouseenter和onmouseleave的代码】相关文章:

JavaScript中的parse()方法使用简介

JavaScript正则表达式的分组匹配详解

用javascript动态注释掉HTML代码

浅谈javascript的call()、apply()、bind()的用法

javascript获取文档坐标和视口坐标

JavaScript实现Iterator模式实例分析

JavaScipt中Function()函数的使用教程

JavaScript静态的动态

深入理解JavaScript的React框架的原理

JavaScript中操作字符串之localeCompare()方法的使用

精品推荐
分类导航