我用在jsp页面中用循环显示了数据库一个表格,每行数据后面有一个修改按钮
点修改按钮的时候,就弹出一个子窗口,在子窗口中怎样获得该选中行中的数据?

解决方案 »

  1.   

    每个数据不是有个ID吗,根据每行的ID去查找
      

  2.   

    要么每行数据有唯一标识,一般是ID,点击按钮的时候传递过去就行了
    如果没有的话,你在循环的时候放一个index,传递过去也可以。
      

  3.   

    <script language="javascript">
    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>
      

  4.   

    var obj = window.open("testA.jsp","newwin","width=200px,hight=10px");
    改成
    var obj = window.open("testA.jsp"+sno,"newwin","width=200px,hight=10px");
      

  5.   


    错了 是
    var obj = window.open("testA.jsp?sno="+sno,"newwin","width=200px,hight=10px");
      

  6.   

    其中?sno中的sno就是你传到后面的参数
      

  7.   

    建议不要用window.open,浏览器会阻止弹出窗口的。用模态对话框:showModalDialog,可以直接传对象。
      

  8.   

    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>
    <%}%>每一行是循环得出的
      

  9.   

    我知道 但是你每一行的table.getSno()的值是不一样的啊 你onclick方法里面传入的值不一样
    所以就能取到每一行的数据
    懂了不
      

  10.   

    建议你不要把所有数据都传递过去。
        只传递一个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>