0

我有几个按钮:

<button class="image1-button"><img src="images/button_unselected.png"></button>
<button class="image1-button"><img src="images/button_unselected.png"></button>
<button class="image1-button"><img src="images/button_unselected.png"></button>
<button class="image1-button"><img src="images/button_unselected.png"></button>

当我按下其中之一时,会发生以下情况:

$(".image1-button").click(function(){
$(this).find("img").attr("src", "images/button_selected.png");
});

我怎么能说另一个,意味着不是(这个)获取始终只有当前按下的按钮具有“button_selected”的src“images/button_unselected”

谢谢你!

4

2 回答 2

2

像这样:

$(".image1-button").click(function(){
    //Reset all
    $(".image1-button").find("img").attr("src", "images/button_unselected.png");
    //mark current
    $(this).find("img").attr("src", "images/button_selected.png");
});
于 2013-02-11T13:21:07.670 回答
0

$(".image1-button").click(function(){
  $(this).find("img").attr("src", "images/button_selected.png")
  $(this).siblings().find("img").attr("src", "images/button_unselected.png")
});

于 2013-02-11T13:24:37.803 回答