html ---javascript全选...
时间:2010-08-10 来源:wxj_snow
HTML ---javascript全选
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>全选</title>
<script type="text/javascript">
function checkEvent(name,allCheckId)
{
var allCK=document.getElementById(allCheckId);
if(allCK.checked==true)
checkAll(name);
else
checkAllNo(name);
}
function checkAll(name)
{
var names=document.getElementsByName(name);
var len=names.length;
if(len>0)
{
var i=0;
for(i=0;i<len;i++)
{
names[i].checked=true;
}
}
}
function checkAllNo(name)
{
var names=document.getElementsByName(name);
var len=names.length;
if(len.length)
{
var i=0;
for(i=0;i<len;i++)
{
names[i].checked=false;
}
}
}
function reserveCheck(name){
var names=document.getElementsByName(name);
var len=names.length;
if(len>0)
{
var i=0;
for(i=0;i<len;i++)
{
if(names[i].checked)
names[i].checked=false;
else
names[i].checked=true;
}
}
}
</script>
</head>
<body>
<form>
<table>
<tr>
<td><input type="checkbox" name="ck" value="1" />苹果</td>
</tr>
<tr>
<td><input type="checkbox" name="ck" value="1" />桔子</td>
</tr>
<tr>
<td><input type="checkbox" name="ck" value="1" />香蕉</td>
</tr>
<tr>
<td><input type="checkbox" name="ck" value="1" />葡萄</td>
</tr>
<tr>
<td><input type="checkbox" name="ck" value="1" />桃子</td>
</tr>
<tr>
<td><input type="checkbox" id="ckReserve" onclick="reserveCheck('ck','ckReserve')" />全选</td>
</tr>
</table>
</form>
</body>
</html>