这个是小弟根据数据库中的表数据动态生成的表格,如何实现点击其中的“+”按钮和“删除”按钮,分别提交到不同的jsp页面,并在提交时只传送点击按钮那行的数据或者那行的id。
请各位高手指点一下!<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>大纲管理</title>
</head>
<jsp:useBean id="cnBean" scope="page" class="db.connDB"/>
<body>
<script language="javascript">
</script>
<form action="mplist1.jsp" method="post">
<p>课程名</p>
<p>
  <input type="submit" name="Submit" value="删除大纲" />
</p>
<p>&nbsp; </p>
<table width="759" height="225" border="1">
  <tr>
    <th width="20">选中知识点</th>
    <th width="112">1级</th>
    <th width="112">2级</th>
    <th width="112">3级</th>
    <th width="112">4级</th>
    <th width="105">知识点描述</th>
    <th width="23">添加同级目录</th>
    <th width="23">添加子级目录</th>
    <th width="14">知识点重要级别</th>
    <th width="14">是否细致</th>
    <th width="42">删除知识点</th>
  </tr>
  <%
    ResultSet RS_result = cnBean.executeQuery("select * from AEP_Ken");
String Kname="";
String Kdescribe="";
int Kimportance=0;
String Kmeticulous="";
int Klevel=0;
int Korder=0;
while(RS_result.next())
{
Kname=RS_result.getString("Kenname");
Kdescribe=RS_result.getString("Kendescribe");
Kimportance=RS_result.getInt("Kenimportance");
Kmeticulous=RS_result.getString("Kenmeticulous");
Klevel=RS_result.getInt("Kenlevel");
Korder=RS_result.getInt("Kenorder");
   %>
   <tr>
<td><input type="checkbox" name="checkbox<%=Korder%>" value="checkbox" /></td>
<%
    int flag=Klevel;
int i=1;
while(i<5)
{
    if(i==flag)
{
%>
<td><input name="textfield<%=Korder%>1" type="text" value="<%=Kname%>" size="16"/></td>
<%
}
else
{
%>
<td>&nbsp;</td>
<%
}
i++;
}
%>
    <td>
      <input name="textfield<%=Korder%>2" type="text" value="<%=Kdescribe%>" size="15" />
    </td>
    <td>      <input type="submit" name="Submit1" value="+" /></td> 
    <td>      <input type="submit" name="Submit2" value="+" /></td>
    <td>
      <input name="textfield<%=Korder%>3" type="text" value="<%=Kimportance%>" size="2" />
    </td>
    <td><input name="textfield<%=Korder%>4" type="text" value="<%=Kmeticulous%>" size="2" /></td>
    <td>
     
      
          <input type="submit" name="Submit" value="删除" />    </td>
  </tr>
  <%
  }
  RS_result.close();
  %>
</table>
<p>&nbsp;</p>
<p>
  <input type="submit" name="Submit" value="保存修改" />
</p>
</form>
</body>
</html>

解决方案 »

  1.   

    form加上name属性
    <form name="myform" action="mplist1.jsp" method="post">将按钮的type属性由submit改为button
    设置onclick事件
    <input type="button" name="Submit2" value="+" onclick="on_click(1,这里放该行ID)"/>//type:1表示+;2表示删除
    function on_click(type,id){
    if(type==1){
    document.myform.action = "?.jsp?id="+id;
    }else if(type==2){
    document.myform.action = "?.jsp?id="+id;
    }
    document.myform.submit();
    }
      

  2.   

    漏掉一个<input type="button" name="Submit" value="删除" onclick="on_click(2,这里放该行ID)"/>