gpt4 book ai didi

javascript - 使用循环将 id 添加到复选框

转载 作者:行者123 更新时间:2023-12-01 01:29:08 25 4
gpt4 key购买 nike

我正在使用 Node js 和 Express 将 JSON 显示为 HTML 表。现在表格显示我想添加一个复选框列来跟踪用户选择的行。所以我在循环中添加了一个复选框,用于从 JSON 生成表。但我无法使用循环变量向每个复选框添加 id。

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

    <!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'标签,这是用于控制流,无输出

应该是<%=

关于javascript - 使用循环将 id 添加到复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53459729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com