在jsp的for循环中创建一个表的行 [英] Creating rows of a table in a for loop in jsp
问题描述
在一个jsp中,我有一个表,我在这样的循环中创建了行,
$ p $ < table>
< tr>
< th>项目< / th>
< th>数量< / th>
Price< th>
< th>总计< / th>
< th>动作< / th>
< / tr>
< tr>
<%
String [] cartItems =(String [])request.getSession()。getAttribute(cartList);
for(int i = 0; i< cartItems.length; i ++){
%>
< td>
< input type =textid =itemPricemaxlength =5size =5style =border:none; value =$<%= cartItem [3]%> />
< / td>
<%}%>
< / tr>
< / table>
假设添加了5个这样的行,每行都有id = itemPrice,但是我想要行有:
id = itemPrice1 $ b $ id = itemPrice2 ..等等。
code>
我该怎么做?请帮忙..
< input type =textid =itemPrice< ;(%)= I%>中maxlength =5size =5style =border:none; value =$<%= cartItem [3]%> />
请注意id发生了什么。这只是句子中的计数器。
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]%>" />
Note what happened with the "id". It's just the counter in the for sentence.
这篇关于在jsp的for循环中创建一个表的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!