【发布时间】:2020-01-19 17:06:21
【问题描述】:
我有两个buttons 和一个function 称为'starta',它有parameter'oi'。
我的问题是,ID 为 'ooii' 的 button 不应该正常工作,而不应该同时工作吗?有人能解释一下这两个按钮都起作用的原因吗?
function starta(oi) {
document.getElementById(oi).style.backgroundColor = "green";
}
button.rond {
width: 60px;
height: 60px;
}
<table>
<tr>
<td class="np"><button style="background-color:yellow" id="y" class="rond" onclick="starta('y')">alotus</button></td>
</tr>
<tr>
<td class="np"><button style="background-color:yellow" id="ooii" class="rond" onclick="starta('ooii')">alotus</button></td>
</tr>
</table>
【问题讨论】:
-
oi是一个变量,与 ID 为"ooii"的字符串或元素无关,尽管有(某种)相似性。为什么不在document.getElementById上方添加console.log(oi)?然后,尝试将oi更改为adhajsdasgdasgdh,看看它是否仍然有效。
标签: javascript html css function button