checkbox 全选操作
2024-09-04 09:43:03
<html>
<head></head>
<body>
<div id="places">
<input type="checkbox" name="chx" value="1" onclick="_check_status(this)"/>香港
<input type="checkbox" name="chx" value="2" onclick="_check_status(this)"/>澳门
<input type="checkbox" name="chx" value="3" onclick="_check_status(this)"/>深圳
<input type="checkbox" name="chx" value="4" onclick="_check_status(this)"/>台北
<input type="checkbox" name="chx" value="5" onclick="_check_status(this)"/>乌镇
</div> <div id="allplaces">
<input type="checkbox" id="checkall" name="chx" value="0" onclick="_check_all(this)"/>全选
</div>
</body>
<script>
//点击“全选”, 所有地方都选上
function _check_all(obj)
{
var nodes = document.getElementById("places").childNodes;
if(obj.checked)
{
for (var i=0; i < nodes.length; i++)
{
if(nodes[i].type == "checkbox")
{
nodes[i].checked = true;
}
}
}
else
{
for (var i=0; i < nodes.length; i++)
{
if(nodes[i].type == "checkbox")
{
nodes[i].checked = false;
}
}
}
} //每一个checkbox的状态校验
function _check_status(obj)
{
var nodes = document.getElementById("places").childNodes;
if(obj.checked)
{
for (var i=0; i < nodes.length; i++)
{
if((nodes[i].type == "checkbox") && !nodes[i].checked)
{
document.getElementById("checkall").checked = false;
return;
}
} document.getElementById("checkall").checked = true;
}
else
{
document.getElementById("checkall").checked = false;
}
} </script>
</html>
最新文章
- asp.net MVC 应用程序的生命周期
- getopt()和getopt_long()用法
- myeclipse下构建maven web项目
- Swift游戏实战-跑酷熊猫 08 产生源源不断的移动平台
- Winform_ComBox三种赋值方式
- lstm-思想2
- Sublime Text3 个人使用心得
- SQL server聚合函数、数学函数、字符串函数
- (转)C++静态库与动态库
- STM32F051 IAP源代码分享
- HTML中发送方式(method)中get和post的比较
- ZOJ 1530 - Find The Multiple
- Composer简介及使用实例
- margin:0 auto是什么意思
- centos7安装zabbix4.2
- 20155227《网络对抗》Exp3 免杀原理与实践
- 关于Unity中3D声音的使用
- 12月6日 看Active Record validation ; 做jdstore ,注意gem bootstrap 版本只支持bootstrap3。
- Python的hasattr() getattr() setattr() 函数使用方法
- 48位MAC转化为唯一的128位IPV6地址
热门文章
- 【找规律】【DFS】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem A. Arithmetic Derivative
- 【AC自动机】HDU中模板题
- Nginx简单认识
- HDU 4417 Super Mario(划分树)
- 推荐一篇讲arm架构gcc内联汇编的文章
- jquery-qrcode 生成和读取二维码
- 扩展 jQuery datebox控件按钮
- java发送http的get和post请求
- python中在ubuntu中安装虚拟环境及环境配置
- HDU 4372 - Count the Buildings(组合计数)