我不知道为什么会收到此错误。我想我已经关闭了所有括号。
我尝试用ID字母代替数字。
function check(x,y) {
coor = "'" + x + y + "'";
if (document.getElementById(coor).classList.contains("bomb")) {
document.getElementById('WoL').innerHTML = "You lose.";
}
}
HTML:
<div class = "grid-square" onclick = "check(1,8)" id = "18">?</div>
我希望输出使ID为“ WoL”的段落显示为“ You loss”。如果您单击div,它就是炸弹。
function check(x,y) {
coor = x.toString() + y.toString();
if (document.getElementById(coor).classList.contains("bomb")) {
document.getElementById('WoL').innerHTML = "You lose.";
}
}
check(1,1);
<div id="WoL"></div>
<div class="bomb" id="11">A tile containing a bomb</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句