在jsp的for循环中创建一个表的行 [英] Creating rows of a table in a for loop in jsp

查看:315
本文介绍了在jsp的for循环中创建一个表的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆