Rumah >hujung hadapan web >tutorial js >Buat kalkulator web dengan node.js express
Persekitaran:
Hos: WIN10
pemasangan ekspres:
1
Masukkan arahan:npm install -g express-generator
npm install -g express
Bina projek:
express -e calculator cd calculator && npm install
Kod sumber:
view/index.ejs: Tambah kotak inputroutes/index.js: Kira dan tolak data yang diserahkan Hasilvar express = require('express'); var router = express.Router(); /* GET home page. */ router.get('/', function(req, res, next) { res.render('index', { title: '计算器V1.0 by jdh', numa: 0, numb: 0, sum: 0 }); }); router.post('/', function (req, res) { console.log("接收:", req.body.num1, req.body.num2); var sum = parseFloat(req.body.num1) + parseFloat(req.body.num2); console.log('sum = ',sum); res.render('index', { title: '计算器V1.0 by jdh', // numa: req.body.num1, // numb: req.body.num2 numa: req.body.num1, numb: req.body.num2, sum: sum }); }); module.exports = router;
Tutorial Video JavaScript2
Manual Dalam Talian JavaScript>3. tutorial bootstrap