我用在jsp页面中用循环显示了数据库一个表格,每行数据后面有一个修改按钮
点修改按钮的时候,就弹出一个子窗口,在子窗口中怎样获得该选中行中的数据?
点修改按钮的时候,就弹出一个子窗口,在子窗口中怎样获得该选中行中的数据?
解决方案 »
- 求助~如何统计HHTP的请求数和响应数
- jsp:usebean报错~
- 帮忙看看!为什么checkbox为null呢?
- Java的迷茫!!寻求侠士的解答
- 急!!!请问:如何在JSP中实现图片附件上传?!可以不用jspsmart组件上传吗?
- 两个已经打开的jsp页面,在其中一个jsp页面上操作,另一个jsp相关内容变化,不刷新
- JSP中的Bean问题。请高手帮忙指点。急,在线等!!!!
- linux 下怎么使用sigar获取硬件信息
- http://211.155.27.180 这个网站怎么样
- SSH框架
- 请教一个oracle数据合并过滤主键的问题
- Struts2怎样接收checkbox表单传送的参数
如果没有的话,你在循环的时候放一个index,传递过去也可以。
function modifi(sno){
var obj = window.open("testA.jsp","newwin","width=200px,hight=10px");
}
</script>
</head>
<body>
<table border="1" width="100%">
<tr>
<td><input type="text" name="sno" id="name" value="<%=request.getAttribute("sno") %>" /></td>
<td></td>
</tr>
<tr>
<td>编号</td>
<td>姓名</td>
<td>性别</td>
<td>院系</td>
<td>操作</td>
</tr>
<%
List<Table> list = (ArrayList<Table>)request.getAttribute("list");
for(int i=0;i<list.size();i++){
Table table = list.get(i);
String tr="tr"+i;
%>
<tr><input type="hidden" id="tr<%=i%>"/>
<td id="Sno"><%=table.getSno()%></td>
<td id="Sname"><%=table.getSname()%></td>
<td id="Ssex>"><%=table.getSsex()%></td>
<td id="Sdep"><%=table.getSdep()%></td>
<td>
<input type="button" value="修改" onclick="modifi('<%=table.getSno()%>')"/>
/<input type="button" id="<%=table.getSno()%>" value="删除" onclick="remove('<%=table.getSno()%>');"/>
</td>
</tr>
<%}%></table>
改成
var obj = window.open("testA.jsp"+sno,"newwin","width=200px,hight=10px");
错了 是
var obj = window.open("testA.jsp?sno="+sno,"newwin","width=200px,hight=10px");
Table table = list.get(i);
String tr="tr"+i;
%>
<tr><input type="hidden" id="tr<%=i%>"/>
<td id="Sno"><%=table.getSno()%></td>
<td id="Sname"><%=table.getSname()%></td>
<td id="Ssex>"><%=table.getSsex()%></td>
<td id="Sdep"><%=table.getSdep()%></td>
<td>
<input type="button" value="修改" onclick="modifi('<%=table.getSno()%>')"/>
/<input type="button" id="<%=table.getSno()%>" value="删除" onclick="remove('<%=table.getSno()%>');"/>
</td>
</tr>
<%}%>每一行是循环得出的
所以就能取到每一行的数据
懂了不
只传递一个ID 然后回后台再查询一次,然后才显示
如果一定要用
var obj = window.open("testA.jsp?sno="+sno,"newwin","width=200px,hight=10px");
这种方法 中文会乱码
可以 改成form的post提交方式<form name="form1" action="testA.jsp" method="post">
<input type="hidden" name="sno" id="sno">
<input type="hidden" name="Sname" id="Sname">
<input type="hidden" name="Ssex" id="Ssex">
<input type="hidden" name="Sdep" id="Sdep">
<form>
<script>
function modifi(this){
var tds = obj.parentNode.parentNode.getElementsByTagName("td");
document.getElementById("sno").value = tds[0].innerHTML;
document.getElementById("Sname").value = tds[1].innerHTML;
document.getElementById("Ssex").value = tds[2].innerHTML;
document.getElementById("Sdep").value = tds[3].innerHTML;
window.form1.submit();
}
</script>