js控制全选,很实用
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="page" uri="/WEB-INF/mytag/pagetag.tld"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
// 说明:Javascript 控制 CheckBox 的全选与取消全选
function checkAll(name) {
var el = document.getElementsByTagName('input');
var len = el.length;
for(var i=0; i<len; i++){
if((el[i].type=="checkbox") && (el[i].name==name)){
el[i].checked = true;
}
}
}
function clearAll(name) {
var el = document.getElementsByTagName('input');
var len = el.length;
for(var i=0; i<len; i++){
if((el[i].type=="checkbox") && (el[i].name==name)){
el[i].checked = false;
}
}
}
</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<input type="checkbox" name="ids" id="ids" value="" onClick="if(this.checked==true) { checkAll('ids'); } else { clearAll('ids'); }">
<input type="checkbox" onChange="checkAll()" name="ids" id="ids" >
</td>
</tr>
</table>
</body>
</html>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="page" uri="/WEB-INF/mytag/pagetag.tld"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
// 说明:Javascript 控制 CheckBox 的全选与取消全选
function checkAll(name) {
var el = document.getElementsByTagName('input');
var len = el.length;
for(var i=0; i<len; i++){
if((el[i].type=="checkbox") && (el[i].name==name)){
el[i].checked = true;
}
}
}
function clearAll(name) {
var el = document.getElementsByTagName('input');
var len = el.length;
for(var i=0; i<len; i++){
if((el[i].type=="checkbox") && (el[i].name==name)){
el[i].checked = false;
}
}
}
</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<input type="checkbox" name="ids" id="ids" value="" onClick="if(this.checked==true) { checkAll('ids'); } else { clearAll('ids'); }">
<input type="checkbox" onChange="checkAll()" name="ids" id="ids" >
</td>
</tr>
</table>
</body>
</html>