<script language="javascript">
function CheckAll(form)
{ ///定义函数checkall,参数为form
for (var i=0;i<form.elements.length;i++)
///循环,form.elements.length得到表单里的控件个数
{
///把表单里的内容依依付给e这个变量
var e = form.elements[i];
if (e.name != ’chkall’)
e.checked = form.chkall.checked;
}
}
</script>
<form id="form1" name="form1" method="post" action="">
<table width="200" cellspacing="1" cellpadding="0">
<tr>
<td width="26">全选</td>
<td width="169"><input name="chkall" type="checkbox" id="chkall" value="all" onclick="CheckAll(this.form)" /></td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="1" /></td>
<td>1 标题1</td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="2" /></td>
<td>2 标题2</td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="3" /></td>
<td> 3 标题3</td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="4" /></td>
<td>4 标题4</td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="5" /></td>
<td>5 标题5</td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="6" /></td>
<td>6 标题6</td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="7" /></td>
<td>7 标题7</td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="8" /></td>
<td>8 标题8</td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="9" /></td>
<td>9 标题9</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="删除" /></td>
</tr>
</table>
</form>
如需传值到另一文件
delete.asp文件:
<!--#include file="inc/conn.asp"-->
<%
Num=request.form("checkbox1").count
if Num=0 then
Response.Write ("请选择要删除的新闻")
Response.End
end if
ids=request.Form("checkbox1")
sqlStr="Delete * From indexad Where id in ("&ids&")"
conn.execute(sqlStr)
Response.redirect(request.servervariables("http_referer"))
Response.End
%>
方法2
<%
Num=request.form("DelID").count
if Num=0 then
Response.Write ("请选择要删除的新闻")
Response.End
end if
for i=1 to Num
set rs=Server.CreateObject("adodb.Recordset")
sql="Select * from News where NewsID="&request.form("DelID")(i)
rs.open sql,conn,1,1
if not rs.eof then
conn.execute("Delete From News Where NewsID="&request.form("DelID")(i))
conn.execute("Delete From Review Where NewsID="&request.form("DelID")(i))
else
Response.Write ("新闻删除失败")
Response.End
end if
rs.close
set rs=nothing
next
Response.Write ("成功将选定新闻删除")
Response.End
%>