鼠标移上去显示一个下拉,移开下拉隐藏

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/nanshan_hzq/article/details/50684261
第一种
$("#op1").hover(function(e) {
        $("#op2").show(); 
    },function(){ 
        $("#op2").hide(); 
    });
    $("#op2").hover(function(){//对按钮的处理 
        $(this).parent().children("#op2").show(); 
    },function(){ 
        $(this).parent().children("#op2").hide();    
    });    
第二种
$("#d1").hover(function(e) {
        $("#d2").show(); 
    },function(){ 
        $("#d2").hide(); 
    });
    $("#d2").hover(function(){//对按钮的处理 
        $("#d2").show(); 
    },function(){ 
        $("#d2").hide();    
    }); 
鼠标移上去显示一个下拉,移开下拉隐藏

区别是 $(this).parent().children("#op2").hide();    找到父类级别,在定位子级
parent() 获得当前匹配元素集合中每个元素的父元素,使用选择器进行筛选是可选的。

children找到类名为 "selected" 的所有 div 的子元素,并将其设置为蓝色:
$("div").children(".selected").css("color", "blue");

猜你喜欢

转载自blog.csdn.net/nanshan_hzq/article/details/50684261