node.js - 如何从这些输入中获取数据
问题描述
我正在尝试建立一个考勤页面,我只想知道如何从这些输入中获取数据。我应该如何命名这些输入,以便我可以检索隐藏输入和无线电输入的数据。
这是参会页面:
<table class="table table-responsive">
<form action="" method="POST">
<tr>
<th>s.no</th>
<th>Name</th>
<th>Roll</th>
<th>status</th>
</tr>
<% for(var i=0;i<student.length;i++) {%>
<tr>
<td><%= i+1 %></td>
<td><%= student[i].name %>
<input type="hidden" name="name<%= i %>" value="<%= student[i].name %>">
</td>
<td><%=student[i].roll_no%>
<input type="hidden" name="name<%= i %>" value="<%= student[i].roll_no %>">
</td>
<td>
<input type="radio" name="status<%= i %>" value="Absent">Absent
<input type="radio" name="status<%= i %>" value="Present">Present
</td>
</tr>
<%}%>
</table>
<button type="submit" >submit</button>
</form>
我应该在 app.js 页面上做什么
app.post('/attendance',(req,res,student)=>{ });
解决方案
看看https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/forms这是一个很好的教程。
在您的情况下,我不记得 html5 提交是否将值附加到请求正文中,您可以执行类似的操作
app.post('/attendance',(req,res,student)=>{
var nameone = req.body.name1 // or just use console.log(req.body) too see all props
});
推荐阅读
- java - 无法初始化 ObjectInputStream
- javascript - vue-tables-2 分页不限制每页数量
- gem5 - 如何仅分析 gem5 中来宾源代码的给定兴趣领域的统计信息?
- reactjs - 我正在对每个输入更改进行异步调用,然后通过响应设置状态。但是状态不是用最新的通话数据设置的
- javascript - 如何同时更改文本和 svg 的颜色?
- jquery - 如何选择第一个嵌套元素
- c# - 在 C# 中对数组列表进行排序关于其子元素
- python - 如何抓取两个 URL 并将每个 url 的元素放在一个表中?
- laravel - 我可以隐藏实际的下载链接吗?
- ios - iOS 版本的 React Native 应用底部有空栏,iPhone X 系列除外