javascript - 错误 "Uncaught SyntaxError: Unexpected end of input"

标签 javascript html debugging

我不知道为什么会出现此错误。我想我已经关闭了所有括号。

我试着用字母代替数字。

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/

相关文章:

debugging - 如何调试导致 100% cpu 使用的 node.js?

java - javac调试信息选项-g :vars do?是什么意思

javascript - 如果文本字段为空,则使用 JavaScript 应用 CSS 样式

javascript - 在nodejs的PUT方法中设置ID

javascript - 如果我在 Kriskowal 的 q 中多次拒绝/解决会发生什么?

html - 背景颜色和背景图像在 IE 和 Mozilla Firefox 中打印为 PDF 时不显示

html - 容器元素的 Tabindex 顺序

c# - 在 C# 中捕获调试输出

javascript - 在条件为真时操作其他元素,Reactjs jsx

javascript - 如何以秒为单位获取当前日期或/和时间