当前位置:网站首页>Native JS realizes the functions of all selection and inverse selection -- Feng Hao's blog
Native JS realizes the functions of all selection and inverse selection -- Feng Hao's blog
2022-07-06 16:39:00 【Feng Hao (grow up)】
Ideas : First, we get the nodes
Traverse each node Get checked Properties of
Then we change checked The attribute of changes the selected state
We let them all vote for true
We use ! To achieve results
The knowledge points used this time are :
document.getElementsByName(‘name attribute ’): Check all name by name Attribute's element node object
document.getElementById('id name '): adopt id Name get an element node object
onclick: Mouse click event
html part :
<input id = 'quan' type="checkbox" value = ' Future generations '> Future generations
<input type="checkbox" name="items" value=" football " > football
<input type="checkbox" name="items" value=" Basketball " > Basketball
<input type="checkbox" name="items" value=" badminton " > badminton
<input id= "fan" type="checkbox" value=" Reverse election "> Reverse election
js part
var items = document.getElementsByName('items');
var quan = document.getElementById('quan');
var fan = document.getElementById('fan');
function fan1(){
var index = 0;
for(var i =0;i<items.length;i++){
items[i].checked = !items[i].checked;
if(items[i].checked==true){
index ++;
}
}
if(index == 3){
quan.checked = true;
}else{
quan.checked =false;
}
}
quan.onclick=function(){
if(quan.checked ==true){
console.log(items[0].checked);
for(var i = 0;i < items.length;i++){
console.log(items[i].checked);
items[i].checked = true;
fan.checked=false;
}
} else{
for(var i = 0;i < items.length;i++){
// console.log(items[i].checked);
items[i].checked = !true;
fan.checked=false;
}
}
};
fan.onclick =function(){
if(fan.checked== true){
fan1()
}else{
fan1()
}
}
边栏推荐
- Chapter 2 shell operation of hfds
- 日期加1天
- input 只能输入数字,限定输入
- Anaconda下安装Jupyter notebook
- Codeforces Round #799 (Div. 4)A~H
- AcWing——第55场周赛
- Codeforces Round #800 (Div. 2)AC
- Raspberry pie 4b64 bit system installation miniconda (it took a few days to finally solve it)
- Educational Codeforces Round 130 (Rated for Div. 2)A~C
- Codeforces Round #798 (Div. 2)A~D
猜你喜欢
Chapter 5 namenode and secondarynamenode
MariaDB的安装与配置
Tree of life (tree DP)
Browser print margin, default / borderless, full 1 page A4
Spark independent cluster dynamic online and offline worker node
使用jq实现全选 反选 和全不选-冯浩的博客
提交Spark应用的若干问题记录(sparklauncher with cluster deploy mode)
It is forbidden to trigger onchange in antd upload beforeupload
Chapter 6 rebalance details
视频压缩编码和音频压缩编码基本原理
随机推荐
Study notes of Tutu - process
Codeforces Round #799 (Div. 4)A~H
QT模拟鼠标事件,实现点击双击移动拖拽等
Market trend report, technical innovation and market forecast of tabletop dishwashers in China
Market trend report, technological innovation and market forecast of double door and multi door refrigerators in China
(lightoj - 1370) Bi shoe and phi shoe (Euler function tabulation)
Advancedinstaller installation package custom action open file
Chapter III principles of MapReduce framework
Acwing: Game 58 of the week
Base dice (dynamic programming + matrix fast power)
原生js实现全选和反选的功能 --冯浩的博客
Chapter 6 rebalance details
The "sneaky" new asteroid will pass the earth safely this week: how to watch it
Remove the border when input is focused
FLV格式详解
Codeforces Round #801 (Div. 2)A~C
CMake Error: Could not create named generator Visual Studio 16 2019解决方法
AcWing——第55场周赛
Problem - 1646C. Factorials and Powers of Two - Codeforces
< li> dot style list style type