【发布时间】:2015-11-14 13:17:03
【问题描述】:
为什么 node.js 不能识别 document.GetElementById? 它说'ReferenceError:文档未定义'。 我能做什么?
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
【问题讨论】:
-
因为... node.js 没有像浏览器那样内置的 DOM。
-
@KevinB:您可以发布该答案以便可以接受吗?谢谢。
-
@Felix Remus 已经有了。
-
考虑到您正在尝试根据 ID 获取值而我只是在尝试做同样的事情,这个答案可能对您更有用stackoverflow.com/questions/7977945/html-parser-on-node-js
-
改用
window.document.getElementById
标签: javascript node.js