【发布时间】:2018-11-02 09:54:30
【问题描述】:
我正在尝试将 Javascript 变量值放入 Expression JS 服务器中的 html 表单中,但我不知道如何解决这个问题。
我只想将 x、y 和 res 的值放入 id 为“firstvalue”、“secondvalue”、“result”的表单中,我该怎么做?
我知道这听起来很简单,但我真的迷路了。
// No use of the template system
var express = require('express'),
logger = require('morgan');
var app = express();
var x = 1;
var y = 2;
var res = x+y;
// Determining the contents of the middleware stack
app.use(logger('dev')); // Place an HTTP request recorder on the stack - each request will be logged in the console in 'dev' format
app.use(express.static(__dirname + '/public')); // Place the built-in middleware 'express.static' - static content (files .css, .js, .jpg, etc.) will be provided from the 'public' directory
// Route definitions
app.get('/', function (req, res) {
res.writeHead(200, {"Content-Type": "text/html; charset=utf-8"});
res.write('<p1 id=firstnumber>x</h1>');
res.write('<p1 id=secondnumber>y</p1>');
res.write('<p1 id=result>res</h1>');
res.end();
// Send a response to the browser
})
// The application is to listen on port number 3000
app.listen(3000, function () {
console.log('The application is available on port 3000');
});
【问题讨论】:
标签: javascript html node.js express