我的代码出现了问题,因为我想按照按钮按下来改变我的元素
var segSelectedy = "a";
var segSelectedx = 1;
function keydown(e) {
if (e.keyCode == 37) {
//left
if (document.getElementById(segSelectedy + "" + (segSelectedx - 1)) != null) {
document.getElementById("Element" + segSelectedy + "" + segSelectedx).className == "unselected";
segSelectedx = segSelectedx - 1;
document.getElementById("Element" + segSelectedy + "" + segSelectedx).className == "selected";
}
} else if (e.keyCode == 39) {
//right
if (document.getElementById(segSelectedy + "" + (segSelectedx + 1)) != null) {
document.getElementById("Element" + segSelectedy + "" + segSelectedx).className == "unselected";
segSelectedx = segSelectedx + 1;
document.getElementById("Element" + segSelectedy + "" + segSelectedx).className == "selected";
}
}
}
document.onkeydown = keydown;

<body>
<table class="console">
<tr>
<th id="a1"><button id="Elementa1" class="selected">Steam Games</button></th>
<th id="a2"><button id="Elementa2" class="unselected">Settings</button></th>
</tr>
</table>
</body>
&#13;
答案 0 :(得分:2)
// *
// *
document.getElementById("Element" + segSelectedy + "" + segSelectedx).className = "unselected";
只需一个 =
,否则不是作业。
这适用于上述各行。