js避免onmouseover onmouseout多次触发

 //------------------------------------------------------------
function contains(parentNode, childNode) 
{
    if (parentNode.contains) {
        return parentNode != childNode && parentNode.contains(childNode);
    } else {
        return !!(parentNode.compareDocumentPosition(childNode) & 16);
    }
}
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;

}

//把以上代码copy,然后在onmouseover="abc(event,this)"

function abc(e, obj)

{

  if(checkHover(e,obj)){

//..这里写你要做的事情即可。
        }

}

你可能感兴趣的:(js避免onmouseover onmouseout多次触发)