?
这篇文章分析的不错:http://www.cnblogs.com/shaojun/archive/2011/03/16/1986249.html
?
?
?
//一下三个函数解决mouseover,mouseout多次触发的问题
??? ??? ??? function contains(parentNode, childNode) {
??? ??? ??? ??? try{
??? ??? ??? ??? ??? if (parentNode.contains) {
??? ??? ??? ??? ??? return parentNode != childNode && parentNode.contains(childNode);
??? ??? ??? ??? ??? } else {
??? ??? ??? ??? ??? return !!(parentNode.compareDocumentPosition(childNode) & 16);
??? ??? ??? ??? ??? }
??? ??? ??? ??? }catch(e){}
??? ??? ??? }???
??? ??? ???
??? ??? ??? function checkHover(e,target){
??? ??? ??? ??? if (getEvent(e).type=="mouseover") {
??? ??? ??? ??? return !contains(target,getEvent(e).relatedTarget||getEvent(e).fromElement) && !((getEvent(e).relatedTarget||getEvent(e).fromElement)===target);
??? ??? ??? ??? } else {
??? ??? ??? ??? return !contains(target,getEvent(e).relatedTarget||getEvent(e).toElement) && !((getEvent(e).relatedTarget||getEvent(e).toElement)===target);
??? ??? ??? ??? }
??? ??? ??? }
??? ??? ???
??? ??? ??? function getEvent(e){
??? ??? ??? ??? return e||window.event;
??? ??? ??? }
?
?
myElement.onmouseover = function (e){ if (checkHover(e, this )){ do someting... } } myElement.onmouseout = function (e){ if (checkHover(e, this )){ do someting... } }