关于复选框全选的问题 我现在做的一个页面是有很多复选框的(动态生成的选项前都复选框)在最下面还有一个复选框旁边有“全选” 当我点击全选的复选框时所有的复选框就都选上了,这样做怎么做啊!又会的么?我不会!但是现在用!那位高手帮帮我!谢谢了! 如果可以告诉我怎么取复选框的值就更好了!呵呵!谢谢大家了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <form method="post"><div><input type="checkbox" name="chkall" onclick="checkall(this.form)" />选择当前记录</div> <input type="checkbox" name="id" value="1" /><input type="checkbox" name="id" value="2" /><input type="checkbox" name="id" value="3" /><input type="checkbox" name="id" value="4" /><input type="checkbox" name="id" value="5" /></form> <script type="text/javascript"> function checkall(f) { for(var i=0;i<f.elements.length;i++) { var e=f.elements[i]; if(e.name!='chkall') e.checked=f.chkall.checked; } }</script> <input type="checkbox" name="id" value="1" /><input type="checkbox" name="id" value="2" /><input type="checkbox" name="id" value="3" /><input type="checkbox" name="id" value="4" /><input type="checkbox" name="id" value="5" />用你代码生成就ok了.加分 ^t^ 刚写的代码你可以参考一下<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>组成员管理-TEST</title><script type="text/javascript" >function allCheck(oAllChkBox) { var oForm = document.getElementById('resForm'); var oChkBoxes = oForm['item[]']; for( i=0;i<oChkBoxes.length;i++ ) { oChkBoxes[i].checked = oAllChkBox.checked; alert(oChkBoxes[i].value); }} </script></head><body><form id="resForm" name="resForm" method="post" action="" > <table width="10%" border="0"> <tr align="center"> <td ><input type="checkbox" name="item[]" value="1"></td> </tr> <tr align="center"> <td width="35%" height="19"><input type="checkbox" name="item[]" value="2"></td> </tr> <tr align="center"> <td width="35%" height="19"><input type="checkbox" name="item[]" value="3"></td> </tr> <tr align="center"> <td width="35%" height="19"><input type="checkbox" name="item[]" value="4"></td> </tr> </table> <input type="checkbox" name="allChk" onclick="allCheck(this);"> 全选 </form><br /></body></html> <script language="JavaScript"><!--function chkClk(obj){ var chks=document.getElementsByName(obj.name); //alert(chks.length); if(obj.flag){ for(var i=1;i<chks.length;i++) chks[i].checked=obj.checked; } else{ for(var i=1;i<chks.length;i++) if(chks[i].checked==false){ chks[0].checked=false; break; } else{ if(i==chks.length-1) chks[0].checked=true; } }}//--></script><input type="checkbox" onclick="chkClk(this)" name="type1" flag="main">typetext<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li><li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li><li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li><li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li><li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li><li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li><br><br><input type="checkbox" onclick="chkClk(this)" name="type2" flag="main">typetext<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li><li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li><li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li><li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li><li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li><li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li> function allchoose(){ var src=document.getElementsByTagName("INPUT"); var check = event.srcElement; if(check.checked==false) { for(var i=0;i <src.length;i++) { if(src[i].type=="checkbox") src[i].checked=false; } } else { for(var i=0;i <src.length;i++) { if(src[i].type=="checkbox") src[i].checked=true; } }}<input type="checkbox" onclick="allchoose()" />全选 <input type="checkbox">0 <input type="checkbox">1 <input type="checkbox">2 <input type="checkbox">3 <input type="checkbox">4 <input type="checkbox">5 <input type="checkbox">6 <input type="checkbox">6 <input type="checkbox">7 <input type="checkbox">8 <input type="checkbox">8 <input type="checkbox">9 一个基础性问题。请指点。 FireFox 如何强制从缓存中读取 js问题 JS怎么让页面Top? 请问用什么方式能实现在javascipt语言中调用动态链接库,并接收到windows消息? 动态生成的checkbox如何获得length 求 javascript 字符替换 函数 如何获得存放网页的主机的IP或域名? 求日期控件 自认为有点难的问题,求解!! 急救!SOS 想做一个类似.NET环境中那个动态弹出工具栏的效果
<div><input type="checkbox" name="chkall" onclick="checkall(this.form)" />选择当前记录</div>
<input type="checkbox" name="id" value="1" />
<input type="checkbox" name="id" value="2" />
<input type="checkbox" name="id" value="3" />
<input type="checkbox" name="id" value="4" />
<input type="checkbox" name="id" value="5" />
</form> <script type="text/javascript">
function checkall(f)
{
for(var i=0;i<f.elements.length;i++)
{
var e=f.elements[i];
if(e.name!='chkall')
e.checked=f.chkall.checked;
}
}
</script>
<input type="checkbox" name="id" value="2" />
<input type="checkbox" name="id" value="3" />
<input type="checkbox" name="id" value="4" />
<input type="checkbox" name="id" value="5" />
用你代码生成就ok了.加分 ^t^
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>组成员管理-TEST</title><script type="text/javascript" >function allCheck(oAllChkBox)
{
var oForm = document.getElementById('resForm');
var oChkBoxes = oForm['item[]'];
for( i=0;i<oChkBoxes.length;i++ )
{
oChkBoxes[i].checked = oAllChkBox.checked;
alert(oChkBoxes[i].value);
}
}
</script>
</head><body>
<form id="resForm" name="resForm" method="post" action="" >
<table width="10%" border="0">
<tr align="center">
<td ><input type="checkbox" name="item[]" value="1"></td>
</tr>
<tr align="center">
<td width="35%" height="19"><input type="checkbox" name="item[]" value="2"></td>
</tr>
<tr align="center">
<td width="35%" height="19"><input type="checkbox" name="item[]" value="3"></td>
</tr>
<tr align="center">
<td width="35%" height="19"><input type="checkbox" name="item[]" value="4"></td>
</tr>
</table>
<input type="checkbox" name="allChk" onclick="allCheck(this);"> 全选
</form>
<br />
</body>
</html>
<!--
function chkClk(obj){
var chks=document.getElementsByName(obj.name);
//alert(chks.length);
if(obj.flag){
for(var i=1;i<chks.length;i++)
chks[i].checked=obj.checked;
}
else{
for(var i=1;i<chks.length;i++)
if(chks[i].checked==false){
chks[0].checked=false;
break;
}
else{
if(i==chks.length-1) chks[0].checked=true;
}
}
}
//-->
</script><input type="checkbox" onclick="chkClk(this)" name="type1" flag="main">typetext
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type1">typetext</li>
<br><br>
<input type="checkbox" onclick="chkClk(this)" name="type2" flag="main">typetext
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
<li><input type="checkbox" onclick="chkClk(this)" name="type2">typetext</li>
{
var src=document.getElementsByTagName("INPUT");
var check = event.srcElement;
if(check.checked==false)
{
for(var i=0;i <src.length;i++)
{
if(src[i].type=="checkbox")
src[i].checked=false;
}
}
else
{
for(var i=0;i <src.length;i++)
{
if(src[i].type=="checkbox")
src[i].checked=true;
}
}
}
<input type="checkbox" onclick="allchoose()" />全选
<input type="checkbox">0
<input type="checkbox">1
<input type="checkbox">2
<input type="checkbox">3
<input type="checkbox">4
<input type="checkbox">5
<input type="checkbox">6
<input type="checkbox">6
<input type="checkbox">7
<input type="checkbox">8
<input type="checkbox">8
<input type="checkbox">9