我有一个使用 jQuery 的页面:http ://treethink.com/services 我想做的是,如果那里显示幻灯片或子页面,请更改按钮的背景颜色和颜色。
为此,我尝试说,如果显示某个 div,则某个按钮的背景颜色会发生变化。但是,您可以在那里看到它无法正常工作,它正在更改 Web 的颜色,但没有删除颜色更改,并在您更改页面时在不同的按钮上添加颜色更改。
这是整体代码:
/* Hide all pages except for web */
$("#services #web-block").show();
$("#services #print-block").hide();
$("#services #branding-block").hide();
/* When a button is clicked, show that page and hide others */
$("#services #web-button").click(function() {
$("#services #web-block").show();
$("#services #print-block").hide();
$("#services #branding-block").hide();
});
$("#services #print-button").click(function() {
$("#services #print-block").show();
$("#services #web-block").hide();
$("#services #branding-block").hide();
});
$("#services #branding-button").click(function() {
$("#services #branding-block").show();
$("#services #web-block").hide();
$("#services #print-block").hide();
});
/* If buttons are active, disable hovering */
if ($('#services #web-block').is(":visible")) {
$("#services #web-button").css("background", "#444444");
$("#services #web-button").css("color", "#999999");
}
if ($('#services #print-block').is(":visible")) {
$("#services #print-button").css("background", "#444444");
$("#services #print-button").css("color", "#999999");
}
if ($('#services #branding-block').is(":visible")) {
$("#services #branding-button").css("background", "#444444");
$("#services #branding-button").css("color", "#999999");
}
谢谢,
韦德