当前位置:网站首页>Select all select none JS code implementation
Select all select none JS code implementation
2022-06-13 06:38:00 【A-linWeb】
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> </head> <style> * {
margin: 0;
padding: 0;
box-sizing: border-box;
}
li {
list-style: none;
}
#box1 {
width: 500px;
margin: 20px 0 0 10px;
}
#box1 h1 {
font-size: 35px;
}
#box1 input, #box2 input, #box3 input, #box4 input {
margin: 5px 8px 5px 5px;
}
#box2, #box3, #box4 {
margin: 20px 0 0 50px;
}
#box2 h2, #box3 h2, #box4 h2 {
font-size: 25px;
margin-top: 20px;
}
#box2 ul, #box3 ul, #box4 ul {
margin-top: 15px;
}
#box2 ul li, #box3 ul li, #box4 ul li {
font-size: 17px;
}
</style>
<body>
<div id="box1">
<h1><input id="quanXuan" type="checkbox" /> Future generations </h1>
</div>
<div id="wrap">
<div id="box2">
<h2><input class="input" id="haiEr" type="checkbox" /> haier </h2>
<ul class="first">
<li><input type="checkbox" data-id="0" /> Air conditioner </li>
<li><input type="checkbox" data-id="0" /> TV </li>
<li><input type="checkbox" data-id="0" /> Washing machine </li>
<li><input type="checkbox" data-id="0" /> The refrigerator </li>
</ul>
</div>
<div id="box3">
<h2><input class="input" id="huaWei" type="checkbox" /> Huawei </h2>
<ul class="second">
<li><input type="checkbox" data-id="1" /> Air conditioner </li>
<li><input type="checkbox" data-id="1" /> TV </li>
<li><input type="checkbox" data-id="1" /> Washing machine </li>
<li><input type="checkbox" data-id="1" /> The refrigerator </li>
</ul>
</div>
<div id="box4">
<h2><input class="input" id="meiDi" type="checkbox" /> beauty </h2>
<ul class="third">
<li><input type="checkbox" data-id="2" /> Air conditioner </li>
<li><input type="checkbox" data-id="2" /> TV </li>
<li><input type="checkbox" data-id="2" /> Washing machine </li>
<li><input type="checkbox" data-id="2" /> The refrigerator </li>
</ul>
</div>
</div>
<script>
var allcheck = document.querySelector("#quanXuan");// Future generations
var singlechecks = document.querySelectorAll(".input");// Single select all box
var inputs = document.querySelectorAll("input");// All selection boxes
var checks = document.querySelectorAll("#wrap input");
var uls = document.querySelectorAll('ul')
var lis = document.querySelectorAll("li"); // Future generations Totally unselected allcheck.addEventListener("click", function () {
inputs.forEach((v) => {
v.checked = this.checked;
});
}); // Single singlechecks.forEach((v, i) => {
v.addEventListener("click", function () {
var childs = uls[i].children Array.from(childs).forEach((v) => {
v.children[0].checked = this.checked
var checkedInputs = document.querySelectorAll("#wrap input:checked");// All selected selection boxes
allcheck.checked = checkedInputs.length === checks.length
})
});
}); lis.forEach(v => {
v.addEventListener('click',function(){
// console.log(v.parentElement.querySelectorAll('input'));
var all = v.parentElement.previousElementSibling.children[0]
// console.log(all);
var singles = v.parentElement.querySelectorAll('input')
var singleChecks = v.parentElement.querySelectorAll('input:checked')
all.checked = singleChecks.length === singles.length
var checkedInputs = document.querySelectorAll("#wrap input:checked");// All selected selection boxes
allcheck.checked = checkedInputs.length === checks.length
})
})
</script>
</body>
<ml>
边栏推荐
- Thread correlation point
- Interface oriented programming in C language
- App performance test: (III) traffic monitoring
- 【sketchup 2021】草图大师中CAD文件的导入与建模(利用cad图纸在草图大师中建立立面模型)、草图大师导出成品为dwg格式的二维、三维、立面效果到cad中打开预览】
- IOError(Errors.E050.format(name=name))
- [JS] array flattening
- Overview of demoplayer program framework design of ijkplayer
- Wechat applet (get location)
- Hidden and wx:if
- MFS details (VII) -- MFS client and web monitoring installation configuration
猜你喜欢

Analysis of 43 cases of MATLAB neural network: Chapter 10 classification of discrete Hopfield Neural Network -- evaluation of scientific research ability of colleges and Universities

欧姆龙平替国产大货—JY-V640半导体晶元盒读写器

智能文娱稳步发展,景联文科技提供数据采集标注服务

Jetpack - basic use of room

SSM framework integration -- > simple background management

《MATLAB 神经网络43个案例分析》:第10章 离散Hopfield神经网络的分类——高校科研能力评价

Analyzing server problems using jvisualvm

机器学习笔记 - 监督学习备忘清单

Wechat applet (get location)

The web server failed to start Port 7001 was already in use
随机推荐
Kotlin collaboration -- context and exception handling
'ipconfig' is not an internal or external command, nor is it a runnable program or batch file.
package-lock. json
线程相关点
Multithreading tests network conditions. Machines in different network segments use nbtstat to judge whether they are powered on
Two uses of bottomsheetbehavior
Hidden and wx:if
Comprehensive overview of ijkplayer contour features for ijkplayer code walk through
Using async await in applets
无刷直流电机矢量控制(四):基于滑模观测器的无传感器控制
Kotlin data flow - flow
Introduction to applet layout
[FAQs for novices on the road] about technology management
Uniapp secondary encapsulates uview components, and the parent component controls display and hiding
[solution] camunda deployment process should point to a running platform rest API
Array operations in JS
Scrcpy source code walk 3 what happened between socket and screen refresh
IOError(Errors.E050.format(name=name))
Kotlin collaboration - simple use of collaboration
Subtotal of constraintlayout