日期:2014-05-16  浏览次数:20359 次

请问一个关于如何获取iterator遍历后的数据.
本帖最后由 tom6495 于 2013-12-23 15:18:40 编辑
我做的程序是这样的


我希望通过点击右侧的修改按钮,向后台程序传递“姓名”,“性别”,"ID"这三个属性,我写了这段代码,请大家看看,这段代码还是实现不了我要的效果。


<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'studentList.jsp' starting page</title>


<script type="text/javascript" src="js/my_ajax.js"></script>
<script type="text/javascript">
var name,sex;


function input1(o) {
document.getElementById("preName"+o).style.display="none";
document.getElementById("name"+o).style.display="block";
}

function input2(o) {
document.getElementById("preSex"+o).style.display="none";
document.getElementById("sex"+o).style.display="block";
}



</script>
</head>

<body>
This is my JSP page.
<br>
<table>
<tr>
<td>编号</td>
<td>姓名</td>
<td>性别</td>
<td>操作</td>
<td>操作</td>
</tr>
<s:iterator value="resultList" status="st" id="id">

<s:form>
<tr>
<td><s:property value="#id.id" />
</td>
<td onclick="input1(${st.index })">
<div id="preName${st.index }">
<s:property value="#id.name" />
</div> <input type="text" id="name${st.index}" name="name"
style="display:none" value='<s:property value="#id.name" />'>
<input id="id${st.index}" name="id" type="hidden"
value="${st.index+1}">
</td>
<td onclick="input2(${st.index })">
<div id="preSex${st.index }">
<s:property value="#id.sex" />
</div> <input type="text" id="sex${st.index }" name="sex"
style="display:none" value='<s:property value="#id.sex" />'>

</td>
<script>
function f<s:property value="#st.index" />(){
name=document.getElementById("name${st.index}").value;
alert(name+":"+<s:property value="${st.index}"/>);
ajax("updateStudent.action?id=${st.index+1}&t="+new Date().getTime()+"&name="+name,function(str){alert(str);},function(){});}
</script>
<!-- <td><s:submit value="修改" action="updateStudent" ></s:submit></td> -->
<td><input type="button" value="修改" 
onclick="f<s:property value="${st.index}"/>()"/>
</td>
<td><s:submit value="删除" action="deleteStudent"></s:submit>
</td>
</tr>
</s:form>
</s:iterator>
</table>
<form>
<s:submit value="注册" action="toAdd"></s:submit>
</form>

</body>
</html>