2013-02-20 42 views

回答

1

你不jQuery这样做。使用只是CSS你得到它的工作。如下 -

#div1:hover .div1-sub-child { 
    background-color:yellow 
} 

使用jQuery -

$('#div1').hover({function(){ //this is called whn mouse enters the div 
    $(this).find('.div1-sub-child').css('background-color','red'); //your effect here 
},function(){ //this is called whn mouse leaves the div 
    $(this).find('.div1-sub-child').css('background-color','green'); //your effect here 
}) 
+0

谢谢你们帮助我...... – 2013-02-20 20:00:01

0

也许像

$(".div1-child").hover(
    function() { 
    $(this).find('.div1-sub-child').css(*** your new css ***); 
    }); 
+1

你的函数将选择所有具有div-sub-child类的元素,而不管它们在DOM中的位置。使用'$(this).find(selector)'使其相对于'this' – 2013-02-20 12:20:59

+0

感谢符文FS,请参阅编辑:) – alemangui 2013-02-20 12:26:03

1

尝试

$("#div1").hover(
function() 
{ 
    $(this).find('div.div1-sub-child').filter(':not(:animated)').animate(
    { 
     marginLeft:'9px' 
    },'slow'); 
}, 
function() 
{ 
    $(this).find('div.div1-sub-child').animate(
    { 
     marginLeft:'0px' 
    },'slow'); 
}); 

哈弗有两个callbacks一会火的时候,你hoverhoverOut

+0

谢谢你们帮助我 – 2013-02-20 20:07:13

0

使用jQuery

$('#div1').hover({function(){ //this is called whn mouse enters the div 
     $(this).find('.div1-sub-child').css('background-color','red'); //your effect here 
    },function(){ //this is called whn mouse leaves the div 
     $(this).find('.div1-sub-child').css('background-color','green'); //your effect here 
    }) 
0

添加特殊样式的div尝试:

$("#div1").hover(
    function() { 
    $(this).find('div.div1-sub-child').addClass("hover"); 
    }, 
    function() { 
    $(this).find('div.div1-sub-child').removeClass("hover"); 
    } 
); 
0

这是很多时候,当你使用jQuery和PHP的工作。而且也有办法很多对在这里做我要添加其中的一个。希望这可以帮助你。 ('#div1 .div1-child')。children()。addClass('addclass');