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>