当前位置:编程学习 > JSP >>

jsp+js实例批量删除数据

jsp+js实例批量删除数据

jsp获取数据存入数据,然后生成合法sql语句
String action =request.getParameter("action");
String[] name=request.getParameterValues("box");
String deng="";
String spl=",";
if( action == null )
{
 action="my";
}
if( action.equals("deleteall") && name != null )
{
 int length = name.length-1;
 for(int i=0;i<=length;i++)  
 {  
     if( i == length )
  {
   deng = deng+name[i];
  }else{
   deng = deng+name[i]+spl;
  }
 }
 Statement stmt_dxh=conn.createStatement();
 String Sql="delete from hl_jobbook where ID in("+deng+")";
 int den=stmt_dxh.executeUpdate(Sql);
  if (den>0){
   out.print("<script type="text/javascript"> alert

("批量删除已成功删除!"); window.location.href='Manage_JobBook.jsp';

</script>"); 
  }
 stmt_dxh.close();

}

下面是js全选代码

<script language="javascript" >
  function b(obj)
    {
        var m = document.getElementsByName('box');
  var btn = myform.btn.value;   
        var l = m.length;
        for ( var i=0; i< l; i++)
        {
            m[i].checked == true
                ? m[i].checked = false
                : m[i].checked = true;
        }
  if( btn == '全选' )
  {
   myform.btn.value ='反选';
  }
  else
  {
   myform.btn.value ='全选';
  }
    }
 </script>

html代码
<form action="?action=deleteall"  method="post" name="myform" >
<input name="box" type="checkbox" class="input_focus" value="<%

=Rs3.getString("id")%>" />
<input type="button" name="btn" size="50" value="全选"  onclick="b

(this.value)"/>
       
      <label>
      <input type="submit" name="Submit" value="删除所选简历" 

onclick="return confirm('确认删除所选择简历吗,删除后无法恢复');" />
      </label>
</form>

补充:Jsp教程,J2ME开发
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,