我不知道为什么会出现此错误。我想我已经关闭了所有括号。
我试着用字母代替数字。
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”的段落说“你输了”。如果你点击 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>
关于javascript - 错误 "Uncaught SyntaxError: Unexpected end of input",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57121319/