我基本上必須使該板的數字從1到50,並且無論何時單擊一個數字,其背景都會變爲不同的顏色。我能夠通過使<div>
點擊第一個做到這一點,但我不知道如何與被認爲具有值2。這裏是我的代碼,第二個做如何更改另一個div的背景,而不影響第一個div的背景
var Color = "#FF0";
function theFunction() {
if (Color == '#FF0') {
Color = '#F00';
} else {
Color = '#FF0';
}
document.getElementById('choose').style.backgroundColor = Color;
}
div#gameboard {
background: #CCC;
border: #999 2px solid;
width: 1200px;
height: 900px;
margin: 70px;
margin-top: 40px;
}
<div id="gameboard">
<div id="choose" style="width:240px; height:150px; margin-left:30px; margin-top:50px; background-color:#FF0; cursor: pointer; font-size:130px; text-align:center;" onclick="theFunction();">
1
</div>
<div id="chose" style="width:240px; height:150px; margin-left:30px; margin-top:50px; background-color:#FF0; cursor: pointer; font-size:130px; text-align:center;" onclick="theFunction();">
2
</div>
</div>
那麼我應該爲第二個div做什麼?謝謝
我也試過,但它並沒有悲傷地工作 –