未定义Node.js文件 [英] Node.js document is not defined
本文介绍了未定义Node.js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么node.js无法识别document.GetElementById? 它说"ReferenceError:未定义文档". 我该怎么办?
Why node.js does not recognize document.GetElementById? It says 'ReferenceError: document is not defined'. What can I do?
ReferenceError: document is not defined
at Object.<anonymous> (C:\Users\Desktop\main.js:9:18)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
推荐答案
document
relates to the DOM (Document Object Model) in a web browser.
Node.js不是浏览器Javascript.它是一台服务器,类似于PHP或Perl,因此,您无法访问浏览器的DOM或执行任何特定于基于浏览器的Javascript的操作.
Node.js, however, is not browser Javascript. It is a server, much like PHP or Perl, and as such, you can't access the browser's DOM or do anything specific to browser-based Javascript.
您可以使用的最接近的方法是使用browserify 在客户端代码中包含Node.js模块.
The closest you could get is using something like browserify to include Node.js modules in your client-side code.
这篇关于未定义Node.js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文