首页 > 解决方案 > 如何从这些输入中获取数据

问题描述

我正在尝试建立一个考勤页面,我只想知道如何从这些输入中获取数据。我应该如何命名这些输入,以便我可以检索隐藏输入和无线电输入的数据。

这是参会页面:

 <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)=>{ });

标签: node.jsexpress

解决方案


看看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
});

推荐阅读