js仿百度音乐全选操作
作者:光明大神棍 时间:2024-04-18 10:03:41
本文实例为大家分享了js全选操作的具体代码,供大家参考,具体内容如下
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
*{margin:0;padding:0;}
ul{list-style:none;}
#content{width:300px;border:1px solid #ccc;margin:20px auto;}
#content ul{width:300px;}
#content ul li,#content div{width:300px;height:50px;line-height:50px;border-bottom:1px dotted #ccc;text-indent:20px;}
#content ul li:nth-child(odd) {background:#f1f1f1;}
#content ul li.active,#content ul li:hover{background:#99FFCC;}
</style>
<script>
window.onload = function () {
var oDiv = document.getElementById('content');
var checkAll = document.getElementById('checkAll');
var aLi = oDiv.getElementsByTagName('li');
var aInput = oDiv.getElementsByTagName('input');
for ( var i = 0; i < aInput.length; i++ ) {
aInput[i].index = i;
aInput[i].onclick = function () {
aLi[this.index].className = this.checked ? 'active' : '';
}
}
checkAll.onclick = function () {
for ( var i = 0; i < aInput.length; i++ ) {
if(!aInput[i].checked) aInput[i].checked = true;
aLi[i].className = 'active';
}
}
}
</script>
</head>
<body>
<div id="content">
<ul>
<li>
<input type="checkbox"/>
<span>私奔</span>
<span>梁博</span>
</li>
<li>
<input type="checkbox"/>
<span>北京</span>
<span>杜甫</span>
</li>
<li>
<input type="checkbox"/>
<span>花人</span>
<span>李白</span>
</li>
<li>
<input type="checkbox"/>
<span>神话</span>
<span>光良</span>
</li>
<li>
<input type="checkbox"/>
<span>神话</span>
<span>光良</span>
</li>
<li>
<input type="checkbox"/>
<span>神话</span>
<span>光良</span>
</li>
<li>
<input type="checkbox"/>
<span>神话</span>
<span>光良</span>
</li>
<li>
<input type="checkbox"/>
<span>神话</span>
<span>光良</span>
</li>
<li>
<input type="checkbox"/>
<span>神话</span>
<span>光良</span>
</li>
</ul>
<div>
<input id="checkAll" type="checkbox" />全选
</div>
</div>
</body>
</html>
标签:js,全选
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
深入透析样式表滤镜(下)
2011-06-14 09:49:19
兼容主流浏览器的【表情插入】源码
2010-07-02 13:02:00
![](https://img.aspxhome.com/file/UploadPic/20107/2/loveliness-32s.gif)
Python导入模块包原理及相关注意事项
2023-01-26 04:46:31
![](https://img.aspxhome.com/file/2023/6/97266_0s.png)
Python内置数据结构列表与元组示例详解
2021-08-17 21:28:14
![](https://img.aspxhome.com/file/2023/1/78801_0s.png)
十行Python3代码实现去除pdf文件水印
2022-02-27 10:50:15
![](https://img.aspxhome.com/file/2023/0/102780_0s.jpg)
MySQL安装失败的原因及解决步骤
2024-01-17 18:22:27
![](https://img.aspxhome.com/file/2023/5/69835_0s.jpg)
详解Python的Django框架中manage命令的使用与扩展
2021-01-04 05:09:27
每个分类取最新的几条的SQL实现代码
2024-01-27 04:44:20
基于vue实现微博三方登录流程解析
2024-05-03 15:08:42
![](https://img.aspxhome.com/file/2023/5/130225_0s.png)
CentOS下php使用127.0.0.1不能连接mysql的解决方法
2023-11-15 08:25:52
Python实现多个视频合成一个视频的功能
2021-10-31 12:57:44
![](https://img.aspxhome.com/file/2023/7/107247_0s.png)
使用pytorch完成kaggle猫狗图像识别方式
2023-04-10 08:39:01
![](https://img.aspxhome.com/file/2023/2/134582_0s.jpg)
python去除空格和换行符的实现方法(推荐)
2021-08-26 02:58:13
javascript中的面向对象
2024-04-18 10:54:33
Python通过递归遍历出集合中所有元素的方法
2022-08-28 01:36:43
详解python文件的操作和异常的处理
2021-06-07 04:05:37
![](https://img.aspxhome.com/file/2023/4/131264_0s.jpg)
如何实现SQL Server 2005快速Web分页
2009-01-21 14:51:00
在MySQL中使用子查询和标量子查询的基本操作教程
2024-01-15 15:00:08
![](https://img.aspxhome.com/file/2023/4/118454_0s.png)
Python高并发和多线程有什么关系
2023-12-08 04:24:47
PHP PDO函数库(PDO Functions)第1/2页
2024-05-08 09:38:45