在jsp中的for循环中创建表的行(Creating rows of a table in a for loop in jsp)

编程入门 行业动态 更新时间:2024-10-27 22:19:58
在jsp中的for循环中创建表的行(Creating rows of a table in a for loop in jsp)

在一个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..

我该怎么做呢? 请帮忙..

In a jsp I have a table whose rows I am creating in a loop like this,

<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>

Suppose 5 such rows are added, every row will have the id=itemPrice, but I want the rows to have:

id=itemPrice1 id=itemPrice2.. and so on..

How do I do this? Please help..

最满意答案

<input type="text" id="itemPrice<%=i%>" maxlength="5" size="5" style="border:none;" value="$<%= cartItem[3]%>" />

注意“id”发生了什么。 这只是句子中的反击。

<input type="text" id="itemPrice<%=i%>" maxlength="5" size="5" style="border:none;" value="$<%= cartItem[3]%>" />

Note what happened with the "id". It's just the counter in the for sentence.

更多推荐

itemPrice,id,电脑培训,计算机培训,IT培训"/> <meta name="description"

本文发布于:2023-07-20 05:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1194829.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Creating   jsp   rows   loop   table

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!