我想在点击时更改按钮的颜色.我是在蓝色的Bootstrap按钮上进行的.但我的代码不起作用.
使用我的JavaScript代码,它不会改变颜色.
这是javascirpt代码:
var b1 = document.getElementById("btnOUS"); var b2 = document.getElementById("btnchiefdom"); var b2 = document.getElementById("btndistrict"); var b2 = document.getElementById("btnfacility"); b1.onclick = function() { b1.style.background = "green"; b2.style.background = ""; } b2.onclick = function() { b1.style.background = ""; b2.style.background = "green"; } b2.onclick = function() { b1.style.background = ""; b2.style.background = "green"; } b2.onclick = function() { b1.style.background = ""; b2.style.background = "green"; }
Gilberto Sán.. 8
看到这个功能示例:
$("button").click(function(){
$("button").removeClass("active");
$(this).addClass("active");
});
.active {
background-color: green !important;
}
看到这个功能示例:
$("button").click(function(){
$("button").removeClass("active");
$(this).addClass("active");
});
.active {
background-color: green !important;
}