我正在尝试构建node.js
应用,而我只是想在getElementById
内插入window.onload
函数。当我打算编写以下代码时;
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 '); \
在
node index.js
上定义服务器端元素不起作用吗?它在如下所示的终端上产生错误,我找不到
具有相同错误的正确示例。
/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。他们有一个很好的例子。