javascript 表单中checkbox全选 if (document.all[i].type=='checkbox'){document.all[i].checked=true;} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <html><script>window.onload=function(){ var form=document.getElementById("f1"); var inputs=form.getElementsByTagName("input"); var cbs=[]; for(var i=0;i<inputs.length;i++){ if(inputs[i].type!="checkbox"){ continue; }else if(inputs[i].id=="checkall"){ form.checkallCB=inputs[i]; form.checkallCB.onclick=checkAll; }else{ inputs[i].onclick=commonCheck; cbs.push(inputs[i]); } } form.cbs=cbs;}function checkAll(){ var form=this.form; var cbs=form.cbs; for(var i=0;i<cbs.length;i++){ cbs[i].checked=this.checked; }}function commonCheck(){ var form=this.form; var checkall=form.checkallCB; if(this.checked==false)checkall.checked=false;}</script><body><form name='f1' id='f1'><table><tr><td><input type="checkbox" id="checkall" />全选/取消</td><tr><tr><td><input type="checkbox" /></td><tr><tr><td><input type="checkbox" /></td><tr><tr><td><input type="checkbox" /></td><tr><tr><td><input type="checkbox" /></td><tr><tr><td><input type="checkbox" /></td><tr><tr><td><input type="checkbox" /></td><tr></table></form></body></html> <script language="javascript">var count;var tcount;function cball(obj){count=0;var a=document.all.tags("input");tcount=a.length-1for (i=0;i<tcount+1;i++){if (a[i].type=="checkbox" && a[i]!=obj) { a[i].checked=obj.checked; count++;}}}function cnall(obj){if (!obj.checked){document.getElementById("all").checked=false; count--;} else count++;if (count==tcount) {document.getElementById("all").checked=true; }}</script> <form name='' id=''><table><tr><td> <input id="all" name="allcheckbox" type="checkbox" title='全选/取消' onclick="cball(this)">全选<br/> </td></tr><tr><td> <input name="m1" type="checkbox" onclick='cnall(this)'><br/> </td></tr><td> <input name="m2" type="checkbox" onclick='cnall(this)'><br/> </td></tr> <td> <input name="m3" type="checkbox" onclick='cnall(this)'><br/> </td></tr> <td> <input name="m4" type="checkbox" onclick='cnall(this)'><br/> </td></tr> <td> <input name="m5" type="checkbox" onclick='cnall(this)'><br/> </td></tr> <td> <input name="m6" type="checkbox" onclick='cnall(this)'><br/> </td></tr></table></form> javascript高手的进来帮我看一下问题,谢谢 js能否控制pos打印机打小票 求一正则 时间相加的问题?当前时间加上20分钟 让程序员变成正常人(转载) ★★★★☆高分求随机排列问题。不够再加! iframe和frame有什么区别吗? JavaScript有没有说明文档 Django框架下使用JavaScript的问题 如何用javascript搜寻相同值并打印出来 很奇怪 求:鼠标拖拽改变div尺寸的代码,要兼容各种浏览器
<script>
window.onload=function(){
var form=document.getElementById("f1");
var inputs=form.getElementsByTagName("input");
var cbs=[];
for(var i=0;i<inputs.length;i++){
if(inputs[i].type!="checkbox"){
continue;
}else if(inputs[i].id=="checkall"){
form.checkallCB=inputs[i];
form.checkallCB.onclick=checkAll;
}else{
inputs[i].onclick=commonCheck;
cbs.push(inputs[i]);
}
}
form.cbs=cbs;
}
function checkAll(){
var form=this.form;
var cbs=form.cbs;
for(var i=0;i<cbs.length;i++){
cbs[i].checked=this.checked;
}
}
function commonCheck(){
var form=this.form;
var checkall=form.checkallCB;
if(this.checked==false)checkall.checked=false;
}
</script>
<body>
<form name='f1' id='f1'>
<table>
<tr><td><input type="checkbox" id="checkall" />全选/取消</td><tr>
<tr><td><input type="checkbox" /></td><tr>
<tr><td><input type="checkbox" /></td><tr>
<tr><td><input type="checkbox" /></td><tr>
<tr><td><input type="checkbox" /></td><tr>
<tr><td><input type="checkbox" /></td><tr>
<tr><td><input type="checkbox" /></td><tr>
</table>
</form>
</body>
</html>
<script language="javascript">
var count;
var tcount;
function cball(obj)
{count=0;
var a=document.all.tags("input");
tcount=a.length-1
for (i=0;i<tcount+1;i++)
{if (a[i].type=="checkbox" && a[i]!=obj)
{ a[i].checked=obj.checked;
count++;}
}
}
function cnall(obj)
{
if (!obj.checked)
{document.getElementById("all").checked=false;
count--;
} else count++;
if (count==tcount)
{document.getElementById("all").checked=true;
}}
</script> <form name='' id=''>
<table>
<tr>
<td>
<input id="all" name="allcheckbox" type="checkbox" title='全选/取消' onclick="cball(this)">全选<br/>
</td>
</tr>
<tr>
<td>
<input name="m1" type="checkbox" onclick='cnall(this)'><br/>
</td>
</tr>
<td>
<input name="m2" type="checkbox" onclick='cnall(this)'><br/>
</td>
</tr>
<td>
<input name="m3" type="checkbox" onclick='cnall(this)'><br/>
</td>
</tr>
<td>
<input name="m4" type="checkbox" onclick='cnall(this)'><br/>
</td>
</tr>
<td>
<input name="m5" type="checkbox" onclick='cnall(this)'><br/>
</td>
</tr>
<td>
<input name="m6" type="checkbox" onclick='cnall(this)'><br/>
</td>
</tr>
</table>
</form>