在jsp中的for循环中创建表的行

2024-04-14

在 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 语句中的计数器。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在jsp中的for循环中创建表的行 的相关文章

随机推荐