$(".TipAllImg").mouseover(function(e){
var TipAllP = $(this).next().width();
if(e.cancelBubble){
e.cancelBubble = true;
}
if(e.stopPropagation){
e.stopPropagation();
}
$(this).next().css({"display":"block","width":"0"}).animate({width:TipAllP},"slow");
}
这个代码实现的功能是当鼠标放到一个标签上时,让他后面的标签显示。其中的e是代表event对象吗?
这两个if语句都有点看不太懂,能帮着稍微解释下吗?
如果想让鼠标移开时,让后面的标签消失,那不就是将这些代码全部复制,然后将最后一行的css中display:block改成display:none就行了吗?但是效果不好~请问应该怎么样做?

解决方案 »

  1.   

    判断是否取消冒泡具体参见http://www.jb51.net/article/9858.htm
      

  2.   

    不用if...了啥啥的, 只需要e.stopPropagation()就行了, jQuery封装了冒泡事件的.
      

  3.   

    if(e.cancelBubble){
    e.cancelBubble = true;
    }
    if(e.stopPropagation){
    e.stopPropagation();
    }
    这2个if的功能是取消事件冒泡,第一个if是为了兼容IE的,第二个是其他的主流浏览器所使用的代码。不过jquery已经封装了这些兼容性代码,直接e.stopPropagation()就行了。
    鼠标移开后消失的代码是:
    $(".TipAllImg").mouseout(function(e){
    e.stopPropagation();
    $(this).next().css('display', 'none');
    }
      

  4.   

    if(e.cancelBubble){
    e.cancelBubble = true;
    }
    if(e.stopPropagation){
    e.stopPropagation();
    }
    这2个if的功能是取消事件冒泡,第一个if是为了兼容IE的,第二个是其他的主流浏览器所使用的代码。不过jquery已经封装了这些兼容性代码,直接e.stopPropagation()就行了。
    鼠标移开后消失的代码是:
    $(".TipAllImg").hover(function(e){
        e.stopPropagation();
        var TipAllP = $(this).next().width();
        $(this).next().css({"display":"block","width":"0"}).animate({width:TipAllP},"slow");
    }, function(e){
        e.stopPropagation();
        $(this).next().css('display', 'none');
    });
      

  5.   

    三楼说的对,防止事件冒泡。就是在一个body中有一个onclick有一个事件,在body中有一个层,层中也有一个onclick事件,你到底要不要把div中发生的事件传递到body上去。就是这个意思。