【问题标题】:Doctype html errdoctype html 错误
【发布时间】:2021-04-01 14:21:40
【问题描述】:

我有一个错误,这里是代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button class="get" function="getInfo">Get Information</button>
    <script src="../server/app.js"></script>
    <script>
    function getInfo() {
        request('http://www.google.com', function (error, response, body) {
        console.log('Status: ' + response && response.statusCode)
        console.log('Body: ' + body)
    })
}
    </script>
</body>
</html>

而且报错很奇怪,看:

<!DOCTYPE html>
^

SyntaxError: Unexpected token '<'

提前感谢所有建议! P.S 抱歉英语不好!

【问题讨论】:

  • 此代码&lt;!DOCTYPE html&gt; 在您的文件中的什么位置?你保存的文件扩展名是什么?
  • 对不起,堆栈溢出不包括第一行,我的文件有.html扩展名
  • 某些东西正试图将 HTML 解析为非 HTML(很可能是 JS 或 JSON),但没有足够的上下文来说明什么。
  • 该错误何时何地出现?
  • 鉴于它被标记为node.js,甚至金钱都说它会变成stackoverflow.com/questions/57572302/…的另一个副本

标签: html node.js syntax-error


【解决方案1】:

我不确定,但我认为您正在使用 nodeJS 运行 html 文件。

确保您的命令是 node .\file.js 而不是 node .\file.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-17
    • 1970-01-01
    • 2012-02-18
    • 1970-01-01
    • 1970-01-01
    • 2011-12-11
    • 2012-06-05
    • 1970-01-01
    相关资源
    最近更新 更多