In IE, there are onmouseenter and onmouseleave.
Unfortunately, FF does not. I want to explain again, why does FF not reference such a good function?
There is also onpropertychange in IE, ah, FF, none...
A js section is introduced in the comparison example to be compatible with FF's onmouseenter and onmouseleave .:CopyCodeThe Code is as follows: var XB =
{
Evthash: [],
Iegetuniqueid: function (_ ELEM)
{
If (_ ELEM = Window) {return 'thewindow ';}
Else if (_ 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 );}
Else if (_ evtname = 'mouseleave ')
{_ ELEM. addeventlistener ('mouseout', XB. mouseenter (_ FN), _ usecapture );}
Else
{_ ELEM. addeventlistener (_ evtname, _ FN, _ usecapture );}
}
Else if (typeof _ ELEM. attachevent! = 'Undefined ')
{
Var key = '{fnkey: OBJ _' + XB. iegetuniqueid (_ ELEM) + ': EVT _' + _ evtname + ': FN _' + _ FN + '}';
VaR F = XB. evthash [Key];
If (typeof F! = 'Undefined ')
{Return ;}
F = function ()
{
_ Fn. Call (_ ELEM );
};
XB. evthash [Key] = F;
_ ELEM. attachevent ('on' + _ evtname, F );
// Attach unload event to the window to clean up possibly ie memory leaks
Window. attachevent ('onunload', function ()
{
_ ELEM. detachevent ('on' + _ evtname, F );
});
Key = NULL;
// F = NULL;/* Don't null this out, or we won't be able to detach it */
}
Else
{_ ELEM ['on' + _ evtname] = _ FN ;}
},
Removeevent: function (_ ELEM, _ evtname, _ FN, _ usecapture)
{
If (typeof _ ELEM. removeeventlistener! = 'Undefined ')
{_ ELEM. removeeventlistener (_ evtname, _ FN, _ usecapture );}
Else if (typeof _ ELEM. detachevent! = 'Undefined ')
{
Var key = '{fnkey: OBJ _' + XB. iegetuniqueid (_ ELEM) + ': evt' + _ evtname +': FN _ '+ _ FN + '}';
VaR F = XB. evthash [Key];
If (typeof F! = 'Undefined ')
{
_ ELEM. detachevent ('on' + _ evtname, F );
Delete XB. evthash [Key];
}
Key = NULL;
// F = NULL;/* Don't null this out, or we won't be able to detach it */
}
},
Mouseenter: function (_ PFn)
{
Return function (_ EVT)
{
VaR reltarget = _ EVT. relatedtarget;
If (this = reltarget | XB. isachildof (this, reltarget ))
{Return ;}
_ PFN. Call (this, _ EVT );
}
},
Isachildof: function (_ parent, _ child)
{
If (_ parent ==_child) {return false };
While (_ Child & _ child! = _ Parent)
{_ Child = _ child. parentnode ;}
Return _ child = _ parent;
}
};
This articleArticleSource of cssrain.cn original link: http://www.cssrain.cn/article.asp? Id = 952