2013-02-20 20 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');