如何解决在jsp的for循环中创建表的行
| 在一个jsp中,我有一个表,我正在像这样的循环中创建其行,<table>
<tr>
<th>Item</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
<th>Actions</th>
</tr>
<tr>
<%
String[] cartItems = (String[]) request.getSession().getAttribute(\"cartList\");
for (int i = 0; i < cartItems.length; i++) {
%>
<td>
<input type=\"text\" id=\"itemPrice\" maxlength=\"5\" size=\"5\" style=\"border:none;\" value=\"$<%= cartItem[3]%>\" />
</td>
<% } %>
</tr>
</table>
假设添加了5个这样的行,每行将具有id = itemPrice,但我希望这些行具有:
id=itemPrice1
id=itemPrice2.. and so on..
我该怎么做呢?请帮忙..
解决方法
<input type=\"text\" id=\"itemPrice<%=i%>\" maxlength=\"5\" size=\"5\" style=\"border:none;\" value=\"$<%= cartItem[3]%>\" />
注意“ id”发生了什么。它只是for语句中的计数器。
,我说这应该有效(未经测试):
将id=\"itemPrice\"
替换为id=\"itemPrice${i+1}\"
这样,您将在html中插入value5ѭ的值。
如果这不起作用,请尝试id=\"itemPrice<%=i+1%>\"
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。