In fact, sometimes I think IE is good. Onmouseenter and onmouseleave are supported. FF is not supported. It is encapsulated. If you do not know the value of mouseenter, you can use mouseleave for your own purposes.
/* -------------------------------------------------- * // The encapsulated event listening function allows common browsers to support mouseenter and mouseleave. // By default, Internet Explorer supports onmuseenter and onmouseleavefunction addevent (El, type, handler, capture) {If (typeof El. addeventlistener! = 'Undefined') {If (type = 'mouseenter') {el. addeventlistener ('mouseover', findelement (handler), capture);} else if (type = 'mouseleave ') {el. addeventlistener ('mouseout', findelement (handler), capture);} else {el. addeventlistener (type, handler, capture) ;}} else if (typeof el. attachevent! = 'Undefined') {el. attachevent ('on' + type, Handler);} else {El ['on' + type] = handler ;}} function findelement (handler) {return function (E) {// The relatedtarget event attribute returns the node associated with the event's target node. // For A Mouseover event, this attribute is the node that leaves when the mouse pointer moves over the target node. // For A mouseout event, this attribute is the node that the mouse pointer enters when it leaves the target. // This attribute is useless for other types of events. VaR parent = E. relatedtarget; // The final result of parent is either null or this; while (parent & parent! = This) parent = parent. parentnode; // when parent is this, you do not need to execute the function. Whether it is mouseenter or mouseleave, I have been entangled in it for a long time. If (parent! = This) handler. call (this, e) ;};};/* -------------------------------------------------- * // function test var $ = function (ID) {return document. getelementbyid (ID);} addevent (window, 'load', function () {var li = $ ('guide'), submenu = $ ('submenu '); addevent (Li, 'mouseenter', function () {submenu. style. display = 'block'; document. title = 'in'}) addevent (Li, 'mouseleave ', function () {submenu. style. display = 'none'; document. title = 'out '})});
HTML:
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">