0
我做了一個菜單,其中有8個啓用/禁用javascript函數按鈕,我使用相同的JavaScript代碼來運行所有8個按鈕,但使用不同的css類爲他們,所以我可以讓他們上班。我的問題是,如何讓他們工作到何處,當你點擊他們的每一個功能。多個javascript按鈕(啓用/禁用)
JavaScript代碼:我用這個代碼7次以上與RED1紅2等綠1 Green2的等
// Left Menu function controls(className) {
if (className == "red") {
document.getElementById('Skip').setAttribute('class','green');
// You can define your play music statements here
} else {
document.getElementById('Skip').setAttribute('class','red');
// You can define your stop music statements here
} }
if (className == "red1") {
document.getElementById('Text').setAttribute('class','green1');
// You can define your play music statements here } else {
document.getElementById('Text').setAttribute('class','red1');
// You can define your stop music statements here } }
CSS代碼:相同的代碼對所有8個按鈕.red1 .red2等.green1 .green2等
.red {
background: red;
height: 30px;
width: 30px;
border-radius: 50px;
border: 1px solid #000;}
.green {
background: green;
height: 30px;
width: 30px;
border-radius: 50px;
border: 1px solid #000;}
HTML代碼:等
Skip <button id="Skip" class="red" onclick="controls(this.getAttribute('class'))">Play</button>
Text <button id="Text" class="red1" onclick="controls(this.getAttribute('class'))">Play</button>
和6多個按鈕與相同的碼RED2 RED3。
我的Javascript ID document.getElementById('Skip')。和我的按鈕ID ID =「跳過」。它僅適用於一個JavaScript代碼和按鈕。 – akamerc 2012-07-22 20:42:39
演示[http://jsfiddle.net/xQ3PT/42/](http://jsfiddle.net/xQ3PT/42/)當您單擊第一個時,第二個會變綠,但它們都需要在你點擊變成紅綠色。 – akamerc 2012-07-22 21:20:14