简体   繁体   English

如何解决文档未定义错误?

[英]How can I solve document is not defined error?

I am getting this error I thought I would be because of the node.js but I am not sure of it.我收到这个错误,我以为我会是因为 node.js,但我不确定。 How can I solve it ?我该如何解决?

[Running] node "c:\Users\Lenovo\Desktop\projectjs\index.js"
c:\Users\Lenovo\Desktop\projectjs\index.js:1
var counter = document.getElementById("count-el")
              ^

ReferenceError: document is not defined
    at Object.<anonymous> (c:\Users\Lenovo\Desktop\projectjs\index.js:1:15)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47

 var counter = document.getElementById("count-el") var count = 0 function increment() { count = count + 1 counter.innerText = count }
 <body> <div> <h1>People entered:</h1> <h2 id="count-el">0</h2> <button id="increment-btn" onclick="increment">INCREMENT</button> </div> <script src="index.js"></script> </body>

Your JavaScript is designed to be embedded in an HTML document, loaded by a <script> element and executed by a web browser.您的 JavaScript 旨在嵌入 HTML 文档中,由<script>元素加载并由 Web 浏览器执行。

It is not designed to run in Node.js which isn't centred around documents at all.它不是为在根本不以文档为中心的 Node.js 中运行而设计的。

Open the HTML document in a web browser.在 Web 浏览器中打开 HTML 文档。 It already has a <script> element.它已经有一个<script>元素。

暂无
暂无

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

相关问题 如何解决“ReferenceError: expect is not defined”错误信息? - How can I solve “ReferenceError: expect is not defined” error message? 我如何解决电子错误:“缓冲区未定义”? - How i can solve Electron error: "Buffer is not defined"? 我该如何解决 [Vue 警告]:数据()中的错误:Laravel Vue 中的“ReferenceError:total is not defined” - How can i solve [Vue warn]: Error in data(): “ReferenceError: total is not defined” in Laravel Vue 我该如何解决 React App 中的这个错误? (“组件”未定义 no-undef) - How can I solve this error in React App? ('Component' is not defined no-undef) 如何解决这个 firebase is not defined 错误? - how to solve this firebase is not defined error? 如何解决“未捕获的ReferenceError:未定义blob”? - How can I solve “Uncaught ReferenceError: blob is not defined”? 我该如何解决“没有方法&#39;appendTo&#39;错误? - How can i solve a "no method 'appendTo' error? 如何解决错误“此表达式不可构造”? - How can I solve error “This Expression is not constructable”? Error Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first,我该如何解决这个问题? - Error Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first, how can i solve this? $(document).ready 时如何解决''Uncaught ReferenceError: $ is not defined' - How to solve ''Uncaught ReferenceError: $ is not defined' when $(document).ready
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM