解决HTML内部元素的Mouse事件干扰(实例,兼容ff,ie)

方法有两种,settimeout感觉不怎么好用,用另一种

function out(id, event)
{
    var parent = document.getElementById(id)
    if(typeof(HTMLElement)!="undefined") //给firefox定义contains()方法,ie下不起作用
    {
        HTMLElement.prototype.contains=function(obj)
        {
            while(obj!=null&&typeof(obj.tagName)!="undefind"){ //通过循环对比来判断是不是obj的父元素
                if(obj==this) return true;
                obj=obj.parentNode;
            }
            return false;
        };
    }

    if ($.browser.mozilla)
    {
        if (!parent.contains(event.relatedTarget)) { //如果是子元素
            $("#"+id).fadeOut(3000, function(){
                $("#"+id+" .todaydiary_list").hide();
            });
        }
    }
    else
    {
        if (!parent.contains(event.toElement)) {
            $("#"+id).fadeOut(3000, function(){
                $("#"+id+" .todaydiary_list").hide();
            });
        }
    }
}

你可能感兴趣的:(解决HTML内部元素的Mouse事件干扰(实例,兼容ff,ie))