日期:2014-05-17  浏览次数:20966 次

代码怎么样改可以让复选框可以全选和全不选啊
代码怎么样改可以让复选框可以全选和全不选啊[b][/b][size=18px][/size]<%@page import="cn.com.chengang.InsertAndSelect"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf8"%>
<%@page import="java.sql.*"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<%
String action = request.getParameter("action");
String name0 = request.getParameter("name0");
String name1 = request.getParameter("name1");
String name2 = request.getParameter("name2");
String id = request.getParameter("id");
String sql ="";
if ("insert".equals(action)) {
sql = "insert into test_table (name0,name1,name2) values('"+ name0 +"','"+ name1 +"','"+name2+"') ";
new InsertAndSelect().insert(sql);
}else if("update".equals(action)){
sql = "update test_table set name0='"+name0+"' ,name1='"+name1+"' ,name2='"+name2+"' where id="+id;
new InsertAndSelect().update(sql);
}else if("delete".equals(action)){
sql = "delete from test_table where id ="+id;
new InsertAndSelect().del(sql);
}
%>


<script type="text/javascript">
function doSearch() {
var list = document.getElementsByName("cb");
for(var i=0;i<list.length;i++){
var check=list[i]; 
if(check.checked==true)
alert(check.value);

}

}

function doUpdate(){
var id;
var list = document.getElementsByName("cb");
for(var i=0;i<list.length;i++){
var check=list[i];
if(check.checked==true){
id=check.value;
break;
}
}
document.location.href="update.jsp?id="+id;
}

function doDelete(){
var id;
var list = document.getElementsByName("cb");
for(var i=0;i<list.length;i++){
var check=list[i]; 
if(check.checked==true){
id=check.value;
}
}
document.location.href="adel()?id="+id;
}



</script>




<title>JSP读取数据库</title>
</head>

<body>
<table border="1" align="center">
<tr>
 
<th></th>
<th>id</th>
<th>name0</th>
<th>name1</th>
<th>name2</th>
</tr>
<tr>
<td><input type="checkbox" name="cb" value="<%=rs.getInt("id")%>"/> </td>

<td onclick="update('<%=rs.getInt("id")%>')"><%=rs.getInt("id")%></td>
<td><%=(rs.getString("name0")==null ? "&nbsp":rs.getString("name0"))%></td>

<td><%=(rs.getString("name1")==null ? "&nbsp":rs.getString("name1"))%></td>

<td><%=(rs.getString("name2")==null ? "&nbsp":rs.getString("name2"))%></td>

</tr>
<%
}
} catch (Exception ex) {
ex.printStackTrace();
}
%>

</table>

<table align="center" >
<tr>
<td bgcolor="black"><input type="button" value="search" onclick="doSearch()"/></td>
<t