是否可以使用JavaScript更改HTML按鈕的CSS類?使用JavaScript更改CSS類按鈕
我試過,但沒有奏效:
document.getElementById("btnChoice1").setAttribute("class", "redButton");
HTML按鈕
<button class="basicButton" id="btnChoice1">
CSS
.basicButton {
width:300px;
}
.redButton {
width:300px;
background-color:red;
}
檢查這個http://stackoverflow.com/questions/195951/change-an-elements-css-class-with-javascript –