我正在尝试构建一个 node.js
应用程序,我只是尝试在 window.onload
中插入一个 getElementById
函数。当我打算制作 node index.js
下面的代码时;
var http = require('http');
function handler(req, res) {
var form = '';
if (req.method == "GET") {
form = '<!doctype html> \
<html lang="en"> \
<head> \
<meta charset="UTF-8"> \
<meta http-equiv="X-UA-Compatible" content="text/html"> \
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> \
<title>XYZ HR</title> \
</head> \
<body> \
<form name="myForm" action="" onsubmit="return ajax();"method="post">\
<br> \
<input type="file" id="myResume" accept=".txt,.doc,.docx,.pdf,.jpg"> \
</form> \
<hr> \
<button type="submit" id="submitBTN" onclick="">Submit</button> \
<div id="displayResume"></div> \
<script src="http://code.jquery.com/jquery-latest.min.js"></script> \
<script> \
window.onload = function () { \
var myResume = document.getElementById('
myResume '); \
Is that not working on
node.js
to define elements server-side? It produce an error on the terminal like below and I couldn't find a proper example with same error.
/Users/erhanyasar/Documents/Web/www/arete/HR/node/index.js:30
var myResume = document.getElementById('myResume'); \
^^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:423:7)
at startup (bootstrap_node.js:147:9)
最佳答案
嗯,在nodejs中服务端渲染没有问题。只需使用任何模板引擎即可,例如 http://olado.github.io/doT/index.html 。他们有关于如何做到这一点的很好的例子。
关于node.js - Node.js 上的 getElementById 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44463507/