在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"
发布评论