在這裏我有一個等級(缺點,平均優勢)和按鈕JS代碼,所有這些參數。
但我有一個問題,當我點擊劣勢,平均和優勢按鈕,它必須失去它的顏色,如果之前點擊這些按鈕,這也是一樣的,如果我點擊平均或優勢,因爲其他按鈕必須失去他們的顏色,只有點擊按鈕才能獲得顏色。問題在哪裏。我把代碼中的一個的jsfiddle:
$(".ca_button, .ca_button1").click(function() {
$this = $(this);
if ($this.is("a")) {
$this = $this.parent();
}
$par = $this.parent();
$par.find(".ca_button, .ca_button1").css("background-color", "#bababa");
if ($(this).hasClass("ca_button1")) {
$this.find("a").css("background-color", "#0F0");
} else {
$this.find("a").css("background-color", "#F00");
}
return false;
});
http://jsfiddle.net/mwsvP/1/ – 2013-03-14 14:26:23