简体   繁体   English

JavaScript“文档”不能用作关键字

[英]JavaScript 'document' not working as a keyword

I have this code here in VSCode:我在 VSCode 中有这个代码:

const form = document.querySelector('form');

The error I am getting is:我得到的错误是:

C:\Program Files\nodejs\node.exe boot.js 
helloworld
c:\Users\frase\OneDrive\Desktop\html\boot.js:2
const form = document.querySelector('form');
             ^

ReferenceError: document is not defined
    at Object.<anonymous> (c:\Users\frase\OneDrive\Desktop\html\boot.js:2:14)
    at Module._compile (internal/modules/cjs/loader.js:1157:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1177:10)
    at Module.load (internal/modules/cjs/loader.js:1001:32)
    at Function.Module._load (internal/modules/cjs/loader.js:900:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47

Why is the document not working?为什么文件不起作用? The file name is referenced with the html file as <script src="boot.js"></script>文件名在 html 文件中被引用为<script src="boot.js"></script>

I have tried putting the script in the header and body tags.我曾尝试将脚本放在 header 和 body 标签中。

document is available only when you are running javascript in a browser.仅当您在浏览器中运行 javascript 时,文档才可用。 It is not available by default.默认情况下不可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM