使用循环将ID添加到复选框 [英] add id to checkbox using loop

查看:98
本文介绍了使用循环将ID添加到复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用节点js,并表示将JSON显示为HTML表。现在表显示
,我想添加一个复选框列以跟踪用户选择了哪些行。
,因此我在循环中添加了一个复选框,该复选框根据JSON生成表。
,但是我无法使用循环变量向每个复选框添加ID。

I'm using node js and express to display a JSON as an HTML table. now that the table is showing I'd like to add a checkbox column to keep track of what rows the user has selected. so I added a checkbox in the loop that generates the table from the JSON. but I can't add an id to each checkbox using my loop variable.

如果有人可以帮助我解决这个问题,我将非常高兴。

if somebody could help me clear out this issue I'd be really really glad.

    <!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Test</title>
    <link href='https://fonts.googleapis.com/css?family=Open+Sans:300' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" type="text/css" href="/css/table.css">
 </head>
<body align="left">
 <form action="/results" method="post">
<div class="container">
<table class="table" align="left">
      <thead>
        <tr>
        <th>Download </th>
        <th>Title</th>
        <th>time </th>
        <th>seeds </th>
        <th> size </th>
        <th> provider </th>
        <th> link </th>
      </thead>


  <tbody>
      <% for (var i = 0; i < torrents.length; i++) { %>
        <tr>
          <td> <input type="checkbox" id=<%i%> > </td> <!-- the problematic line-->
          <td> <%= torrents[i].title%> </td>
          <td> <%= torrents[i].time%> </td>
          <td> <%= torrents[i].seeds%> </td>
          <td> <%= torrents[i].size%> </td>
          <td> <%= torrents[i].provider%> </td>
          <td> <%= torrents[i].link%> </td>
   </tr>
<% }%>
  </tbody>
</table>
</body>
</div>


<input type="submit" class="ghost-button" value="Download selected torrents to seedbox">
</form>
</html>


推荐答案

您使用了<%'Scriptlet'标记,用于控制流,无输出

You used <% 'Scriptlet' tag, this is for control-flow, no output

应为<%=

这篇关于使用循环将ID添加到复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆