Tag: checkbox

如何使用ejs获取节点js中checkbox的值?

我的代码: Html档案: <form action="/form" method="post" enctype="multipart/form-data"> Name: <input type="text" name="name" /><br> Email: <input type="email" name="email" /> <br> Age: <input type="number" name="age" /> <br> Address: <textarea name="address" rows="10" cols="15"> </textarea><br> Category: <select name="cat"> <option value="1">Php</option> <option value="2">NodeJs</option> <option value="3">jQuery</option> </select><br> Gender: <input type="radio" name="gen" value="m"/> Male <input type="radio" name="gen" value="f"/> Female Hobby: <input type="checkbox" name="hob[]" value="cri"/> […]

正确的方法来读取NodeJS中的checkbox数据

我在我的网页上有一个表单,并将其提交给NodeJS后端。 我在checkbox有问题。 当提交到服务器,我通过req.body.foods阅读他们,我得到的东西就像['on', 'on', 'on'] 。 但是我想要得到实际的价值,就是像['dairy', 'fish']等等。 我怎样才能做到这一点? <div class="col-sm-6"> <div class="checkbox"> <label><input name="food" type="checkbox" value="dairy">Dairy</label> </div> <div class="checkbox"> <label><input name="food" type="checkbox" value="meat">Meat</label> </div> <div class="checkbox"> <label><input name="food" type="checkbox" value="fish">Fish</label> </div> </div>

返回玉的checkbox值。 使用node.js,express和Mongoose

我保存了mongoDB中的checkbox值。 将值传递给页面 if (req.session.user.Single === undefined) {single_status= 'false'} else {single_status= ''}; res.render('user-profile', { Single: single_status, )}; 那我在玉里有这个 .col-md-4 label-option(for="checkbox") input(type="checkbox", checked="#{Single}", name='single', id='single') 在呈现的视图。 它出现checked =“false”,所以它总是被检查。 如何将阀门返回到checkbox以显示现有的已选中/未选中? <label-option for="checkbox"> <input type="checkbox" checked="false" name="single" id="single"> Single Status </label-option>

帕格(RIP翡翠)formscheckbox – 无论select多less,只返回一个值

我有一个写在帕格的表格。 我从窗体的POST中获取所有正确的参数,除了我的checkbox数组是一个包含一个值的string – 选定的最后一天。 每个checkbox有一个名称等于一个数组,所以表单应该返回所有选中的checkbox。 但是,这并没有发生。 以下是checkboxselect的相关代码: form#create-shift-form(action='/shifts/new', method='post') div.form-group p Select which days this shift should apply: div.checkbox-inline input.checkbox-input#create-shift-mon(type='checkbox', name='days[]', value='Mon') label(for='create-shift-mon') Mon div.checkbox-inline input.checkbox-input#create-shift-tue(type='checkbox', name='days[]', value='Tue') label(for='create-shift-tue') Tue div.checkbox-inline input.checkbox-input#create-shift-wed(type='checkbox', name='days[]', value='Wed') label(for='create-shift-wed') Wed div.checkbox-inline input.checkbox-input#create-shift-thur(type='checkbox', name='days[]', value='Thur') label(for='create-shift-thur') Thur div.checkbox-inline input.checkbox-input#create-shift-fri(type='checkbox', name='days[]', value='Fri') label(for='create-shift-fri') Fri div.checkbox-inline input.checkbox-input#create-shift-sat(type='checkbox', name='days[]', value='Sat') label(for='create-shift-sat') Sat div.checkbox-inline […]

Node Express Jade – checkbox布尔值

我正在使用Node + Express + Jade来渲染一些网页。 在表单上有2个checkbox。 当通过POST提交表单时,如果checkbox被选中,我得到req.body.checkbox1 -> 'on' ,如果没有选中,我得到req.body.checkbox1 -> undefined 有可能获取checkbox的值为true或false ? 这是我的服务器端testing代码 var bodyParser = require('body-parser'); var express = require('express'); var app = express(); app.use(bodyParser.urlencoded({extended: true})); app.use(express.static(__dirname + '/webroot')); app.set('views', __dirname + '/view'); app.set('view engine', 'jade'); app.listen(3001); app.get('/', function (req, res) { res.render('test'); }); app.post('/config', function (req, res) { console.log(req.body.t); console.log(req.body.f); res.redirect('/'); […]