【发布时间】:2020-04-10 12:43:23
【问题描述】:
Node.js 停止运行 javascript 代码
我的文件结构
app.js
index.html
index.js
但如果我在没有节点的情况下运行它,它的工作和警报来了
app.js
var http = require('http');
var fs = require('fs');
const PORT=80;
fs.readFile('./index.html', function (err, html) {
if (err) throw err;
http.createServer(function(request, response) {
console.log(request.addListener.name);
response.writeHeader(200, {"Content-Type": "text/html"});
response.write(html);
response.end();
}).listen(PORT);
console.log(`Server running at http://127.0.0.1/`);
});
index.html
<html>
<head>
<script src="index.js"></script>
</head>
<body>
<button onclick="start()">onclick</button>
</body>
</html>
index.js
function start(){
alert('start');
}
任何人,请建议我如何通过单击按钮或更改输入数据在节点上运行时调用 Javascript 函数的解决方案。
【问题讨论】:
-
你必须创建静态服务器和服务器静态文件。检查网络,无法加载 index.js
标签: javascript html node.js dom-events onclicklistener