我有這樣的一組代碼:僅影響一個元素[jquery的]
$('.rightMainP').hover(function() {
$('#rightMain img:first-child').attr('src', '../Images/whiteSidewaysNub.png')
}, function() {
$('#rightMain img:first-child').attr('src', '../Images/graySidewaysNub.png')
});
我也有多個#rightMain
的div。當我將鼠標懸停在一個上面時,我希望它的相應圖像可以更改。
我的問題是,當我將鼠標懸停在rightMain
格,每格rightMain
變化的每一個形象,而不是從第一rightMain
DIV只有圖像。
我該如何讓它懸停在多個元素中的一個元素上只會更改相應元素的圖像而不是所有元素?
<div id="answers">
<div id="leftInfo">
<img src="../Images/junglrLarge.png"/><a href="">TESTUSER</a><br /><span>Level 6</span>
</div>
<div id="rightMain">
<img class="graySidewaysNub" src="../Images/graySidewaysNub.png"></img>
<p class="rightMainP">This is my answer!</p>
<div class="rate"><img src="../Images/incLike.png"/>0 <img src="../Images/alert.png"/></div>
</div>
<div id="leftInfo">
<img src="../Images/junglrLarge.png"/><a href="">TESTUSER</a><br /><span>Level 6</span>
</div>
<div id="rightMain">
<img class="graySidewaysNub" src="../Images/graySidewaysNub.png"></img>
<p class="rightMainP">Wow, I think this above answer is stupid...</p>
</div>
</div>
</div>
<script>
$('.answerSpace').bind('focus', function(){ $('.opacProf').removeClass("opacProf").addClass('normProf');
$('.answerSubmit').stop().animate({
opacity: "1"
}, 500);
$('.answerSpace').css({'background-color' : '#ffffff', 'color' : '#333'}); });
$('.rightMainP').hover(function(){$('#rightMain img:first-child').attr('src','../Images/whiteSidewaysNub.png')},function(){$('#rightMain img:first-child').attr('src','../Images/graySidewaysNub.png')});
</script>
你能告訴我們你的HTML嗎? – 2011-04-17 07:48:42