关于复选框全选的问题????

ming470612141 2008-01-16 10:55:01
怎样利用js将一组复选框全选中???请教一下!
...全文
89 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
王集鹄 2008-01-16
  • 打赏
  • 举报
回复
<script language="javascript" type="text/javascript">
function checkAll()
{
var checkArray = document.getElementsByName("box");
for(i =0; i < checkArray.length;i++)
checkArray[i].checked = true;
}
</script>
ming470612141 2008-01-16
  • 打赏
  • 举报
回复
而且用button的事件实现
ming470612141 2008-01-16
  • 打赏
  • 举报
回复
我是想一组相同名称的复选框实现全选功能
conis 2008-01-16
  • 打赏
  • 举报
回复
<!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=utf-8" />
<title>全选的例子</title>
[code=JScript]
<script language="javascript">
/*
作者:Conis
时间:15:33 2007/12/12
功能:根据一个CheckBox的选择状态,将指定容器内的所有CheckBox都置为与些CheckBox相同的状态。一般用于点中一个CheckBox,全选/全取消一组CheckBox
限制:所有的目标CheckBox必需在同一个容器中
参数:
oContainer:包含CheckBox的容器
oCheckAll:全选的CheckBox,目标容器中所有CheckBox都会与这个CheckBox的Checked状态一样
*/
function SelectAllCheckBox(oContainer, oCheckAll)
{
var oList = oContainer.getElementsByTagName("INPUT");
if (oList && oList.length)
{
for(var i = 0; i < oList.length; i ++)
{
if (oList[i].type != "checkbox" || oList[i] == oCheckAll) continue;
oList[i].checked = oCheckAll.checked;
}
}
}
</script>

</head>

<body>
<table width="15%" border="0" cellspacing="0" cellpadding="0" id="tableOne">
<tr>
<td><input type="checkbox" name="checkAll" id="chkAllOne" onclick="SelectAllCheckBox(document.getElementById('tableOne'), this)"/></td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox2" id="checkbox2" />
<input type="text" name="textfield" id="textfield" /></td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox3" id="checkbox3" /></td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox4" id="checkbox4" /></td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox5" id="checkbox5" /></td>
</tr>
</table>
</body>
</html>
[/code]
ming470612141 2008-01-16
  • 打赏
  • 举报
回复
en,全选
ming470612141 2008-01-16
  • 打赏
  • 举报
回复
利用事件触发选择所有的checkbox????

<html>
<head>
<title>采集模板生成模块</title>
<script type="text/javascript">
function checkAll(){
var checkArray = document.all("box");
for(i=0;i<checkArray[i];i++){
checkArray[i].checked=true;
}
}
</script>
</head>
<body>
<center>
<form name="ctcForm" action="" method="post">
<table id="markTable" border=2>
<caption>
请选择部门所管辖的指标:
</caption>
<tr>
<th>  </th>
<th align="center">指标编号</th>
<th align="center">指标名称</th>
</tr>
<tr>
<td>
<input type="checkbox" name="box">
</td>
<td>
<input type="checkbox" name="box">
</td>
<td>
<input type="checkbox" name="box">
</td>
</tr>
</table>
<br>
<table>
<tr>
<select id="ctcSelect">
<option value="atvdc">
年度目标值数据采集模板
</option>
<option value="mavdc">
每月完成值数据采集模板
</option>
</select>
</tr>
</table>
<br>
<table>
<tr>
<td>
<input type="button" name="buildModule" value="生成"
onClick="createModule();" />
</td>
<td>
<input type="button" name="allCheck" value="全选"
onClick="checkAll();" />
</td>
<td>
<input type="reset" name="reset" value="重置" />
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
王集鹄 2008-01-16
  • 打赏
  • 举报
回复
上面的例子可以吗?就是全选?
王集鹄 2008-01-16
  • 打赏
  • 举报
回复
问问题,如果能让回答的人方便的搭建调试环境,那么多省大家的时间?
<html>
<body>
<input type="checkbox" name="C1" value="ON">
<input type="checkbox" name="C2" value="ON">
<input type="checkbox" name="C3" value="ON">
<input type="checkbox" name="C4" value="ON">
<input type="checkbox" name="C5" value="ON">
</body>
</html>
ming470612141 2008-01-16
  • 打赏
  • 举报
回复
我是写了jsp里面的
王集鹄 2008-01-16
  • 打赏
  • 举报
回复
有现成的html吗?调试起来方便一些。
yousite1 2008-01-16
  • 打赏
  • 举报
回复
<input type=button value=全选 onclick=checkAll('checkbox1');>
yousite1 2008-01-16
  • 打赏
  • 举报
回复
真是无语:

<script language="javascript" type="text/javascript">
var bln = false;
function checkAll(chkname)
{
var checkArray = document.getElementsByName(chkname);
for(i =0; i < checkArray.length;i++)
if (!bln)
checkArray[i].checked = true;
else
checkArray[i].checked = false;

bln = !bln;
}
</script>

  • 打赏
  • 举报
回复
给你些例子
http://blog.csdn.net/lifeng_beijing/archive/2007/12/14/1936512.aspx

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧