Javascript 有关使用节点js在html中单击按钮的信息
这是我的代码: file.htmlJavascript 有关使用节点js在html中单击按钮的信息,javascript,html,node.js,Javascript,Html,Node.js,这是我的代码: file.html <html> <head> </head> <body> <form> <input type="button" value="hello1" onClick="window.location.reload()"/> <input type="button" value="hello2" onClick="window.location.reload()" /&
<html>
<head>
</head>
<body>
<form>
<input type="button" value="hello1" onClick="window.location.reload()"/>
<input type="button" value="hello2" onClick="window.location.reload()" />
</form>
</body>
我的问题是:在http.createServer(function(req,res){…})中是否可以区分单击了什么按钮?这个问题可能看起来很愚蠢,因为两个按钮都做相同的事情,但我需要能够做一件事。谢谢大家
var http=require('http');
var fs = require('fs');
var server = http.createServer(function(req, res){
displayForm(res);
});
function displayForm(res) {
fs.readFile('file.html', 'utf8', function (err, data) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
res.end();
});
}
server.listen(port, 'ip');
console.log("Server running at http://ip:port/");