把每个checkbox的id起的有规则一些,像2维数组那样
如: c00 c01 c02 .....
c10 c11 .......
......
然后就可以在一个循环里处理了,如:
for(i=0;i<4;i++)
{
document.getElementByID("c0"+i).checked;
}
如: c00 c01 c02 .....
c10 c11 .......
......
然后就可以在一个循环里处理了,如:
for(i=0;i<4;i++)
{
document.getElementByID("c0"+i).checked;
}
解决方案 »
- 判断不起作用return false 会阻止提交
- 求助,滚动图片,如何选中到指定位置
- 关于click以后得冒泡反应的问题,如何能控制click以后只在某一个div里面生效,不会传递到其他的div里面去。
- 10分的小问题 在线等
- 求一个“三级下拉式菜单" 100分送
- 按钮代替链接 跳转前提示问题
- 100分---讨论:tom 是如何实现这个效果的。。。
- 如何在同一个页面,在一个td里, 点击 这个td里面的字如 "换色" 可以把这个td 的bgcolor换成另外一种color呀
- 又一个javascript脚本(能使)打开后是乱码,谁知道为什么???????
- 如何动态改变span区域的样式?比如<span onmouseover="this.runtimeStyle.borderBottomColor='FF0000'">test</span>当鼠标移上时没有变化
- 动态显示下拉框的一段代码的错误,求教!
- 关于动态隐藏按钮
然后判断type是否是checkbox,参考
dhtml手册http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/dhtml_reference_entry.asphttp://msdn.microsoft.com/workshop/author/dhtml/reference/methods/getelementsbytagname.asp
<!--
function fnc1()
{
for(var i=0;i<document.all.length;i++)
{
if(document.all(i).type == 'checkbox') document.all(i).checked = true;
}
} function fnc2(strid)
{
for(var i=0;i<document.all.length;i++)
{
if(document.all(i).type == 'checkbox' && document.all(i).parentElement.id == strid) document.all(i).checked = true;
}
} function fnc3(obj)
{
var o = obj.parentElement.parentElement.getElementsByTagName('INPUT');
for(var i=0;i<o.length;i++)
{
o[i].checked = true;
}
}
//-->
</script><table>
<tr>
<td id=1>添<input type=checkbox onclick="fnc2(this.parentElement.id);">加
<td id=2>添<input type=checkbox onclick="fnc2(this.parentElement.id);">加
<td id=3>添<input type=checkbox onclick="fnc2(this.parentElement.id);">加
<td id=4>添<input type=checkbox onclick="fnc2(this.parentElement.id);">加
</tr>
<tr>
<td id=1>行<input type=checkbox onclick="fnc3(this);">
<td id=2><input type=checkbox>
<td id=3><input type=checkbox>
<td id=4><input type=checkbox>
</tr>
<tr>
<td id=1>行<input type=checkbox onclick="fnc3(this);">
<td id=2><input type=checkbox>
<td id=3><input type=checkbox>
<td id=4><input type=checkbox>
</tr>
<tr>
<td id=1>行<input type=checkbox onclick="fnc3(this);">
<td id=2><input type=checkbox>
<td id=3><input type=checkbox>
<td id=4><input type=checkbox>
</tr>
</table>
<p>全选<input type=checkbox onclick="fnc1();"></p>
<!--
function fnc1(obj)
{
for(var i=0;i<document.all.length;i++)
{
if(document.all(i).type == 'checkbox') document.all(i).checked = obj.checked;
}
} function fnc2(strid,obj)
{
for(var i=0;i<document.all.length;i++)
{
if(document.all(i).type == 'checkbox' && document.all(i).parentElement.id == strid) document.all(i).checked = obj.checked;
}
} function fnc3(obj)
{
var o = obj.parentElement.parentElement.getElementsByTagName('INPUT');
for(var i=0;i<o.length;i++)
{
o[i].checked = obj.checked;
}
}
//-->
</script><table>
<tr>
<td id=1>添<input type=checkbox onclick="fnc2(this.parentElement.id,this);">加
<td id=2>添<input type=checkbox onclick="fnc2(this.parentElement.id,this);">加
<td id=3>添<input type=checkbox onclick="fnc2(this.parentElement.id,this);">加
<td id=4>添<input type=checkbox onclick="fnc2(this.parentElement.id,this);">加
</tr>
<tr>
<td id=1>行<input type=checkbox onclick="fnc3(this);">
<td id=2><input type=checkbox>
<td id=3><input type=checkbox>
<td id=4><input type=checkbox>
</tr>
<tr>
<td id=1>行<input type=checkbox onclick="fnc3(this);">
<td id=2><input type=checkbox>
<td id=3><input type=checkbox>
<td id=4><input type=checkbox>
</tr>
<tr>
<td id=1>行<input type=checkbox onclick="fnc3(this);">
<td id=2><input type=checkbox>
<td id=3><input type=checkbox>
<td id=4><input type=checkbox>
</tr>
</table>
<p>全选<input type=checkbox onclick="fnc1(this);"></p>