迭代调用js方法

gds2014 2016-05-13 11:27:35
表格显示多个数据:产品ID,名称,数量,单位,这些数据在两张表中,用struts2中的<s:iterator />显示部分数据:产品ID和数量,其他数据想在每次迭代过程中利用AJAX查询数据库中得到其它数据用于显示,怎么解决?



  <struts:iterator value="supplierInventoryList">  
<script type="text/javascript">getProductInfo();</script>
<tr>
<td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1" id="productID"><struts:property value="productId"/></span></div></td>
<td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1" id="name"></span></div></td>
<td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1" id="unit"></span></div></td>
<td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1" id="price"></span></div></td>
<td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1"><struts:property value="quantity"/></span></div></td>
<td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1"><struts:property value="updateDate"/></span></div></td>
</tr>
</struts:iterator>


function getProductInfo()
{
var productIDvalue=document.getElementById("productID").value; //获取id为productID标记的元素
createXmlHttp();
xmlHttp.onreadystatechange=writeProductInfo;//设置回调函数
xmlHttp.open("GET","<%=basePath %>product_ajax.jsp?productID="+productIDvalue,true);
xmlHttp.send(null);
}


这样写的话无法调用getProductInfo(),有没有好的解决方法,多谢了!!!
...全文
285 5 打赏 收藏 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2016-05-14
  • 打赏
  • 举报
回复
id="productID<struts:property value="productId"/>"><struts:property value="productId"/> <script type="text/javascript">getProductInfo("productID<struts:property value="productId"/>");</script>
slwsss 2016-05-13
  • 打赏
  • 举报
回复
<struts:iterator value="supplierInventoryList"> <tr> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1" id="productID"><struts:property value="productId"/></span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1" id="name"></span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1" id="unit"></span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1" id="price"></span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1"><struts:property value="quantity"/></span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1"><struts:property value="updateDate"/></span></div></td> </tr> <script type="text/javascript">getProductInfo("参数ID");</script> </struts:iterator> function getProductInfo(id) { var productIDvalue=document.getElementById(id).value; //获取id为productID标记的元素 createXmlHttp(); xmlHttp.onreadystatechange=writeProductInfo;//设置回调函数 xmlHttp.open("GET","<%=basePath %>product_ajax.jsp?productID="+productIDvalue,true); xmlHttp.send(null); }
gds2014 2016-05-13
  • 打赏
  • 举报
回复
引用 1 楼 slwsss 的回复:
<struts:iterator value="supplierInventoryList"> <tr> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1" id="productID"><struts:property value="productId"/></span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1" id="name"></span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1" id="unit"></span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1" id="price"></span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1"><struts:property value="quantity"/></span></div></td> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1"><struts:property value="updateDate"/></span></div></td> </tr> <script type="text/javascript">getProductInfo("参数ID");</script> </struts:iterator> function getProductInfo(id) { var productIDvalue=document.getElementById(id).value; //获取id为productID标记的元素 createXmlHttp(); xmlHttp.onreadystatechange=writeProductInfo;//设置回调函数 xmlHttp.open("GET","<%=basePath %>product_ajax.jsp?productID="+productIDvalue,true); xmlHttp.send(null); }
只能显示一行呀,<s:iterator />中每次迭代过程中span的id怎么区分?
gds2014 2016-05-13
  • 打赏
  • 举报
回复
谢谢你,但这样只能显示一行呀

52,778

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧