当前位置:网站首页>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()
}
}
边栏推荐
- Problem - 922D、Robot Vacuum Cleaner - Codeforces
- sublime text 代码格式化操作
- 生成随机密码/验证码
- Spark的RDD(弹性分布式数据集)返回大结果集
- QT style settings of qcobobox controls (rounded corners, drop-down boxes, up expansion, editable, internal layout, etc.)
- ffmpeg命令行使用
- Market trend report, technical innovation and market forecast of China's desktop capacitance meter
- Summary of FTP function implemented by qnetworkaccessmanager
- Research Report on market supply and demand and strategy of Chinese table lamp industry
- Installation and configuration of MariaDB
猜你喜欢
Story of [Kun Jintong]: talk about Chinese character coding and common character sets
Chapter 5 detailed explanation of consumer groups
提交Spark应用的若干问题记录(sparklauncher with cluster deploy mode)
Codeforces Round #801 (Div. 2)A~C
Spark independent cluster dynamic online and offline worker node
< li> dot style list style type
Oneforall installation and use
Summary of game theory
业务系统从Oracle迁移到openGauss数据库的简单记录
Spark独立集群动态上线下线Worker节点
随机推荐
Raspberry pie 4b64 bit system installation miniconda (it took a few days to finally solve it)
MariaDB的安装与配置
指定格式时间,月份天数前补零
Acwing - game 55 of the week
Investigation report of bench type Brinell hardness tester industry - market status analysis and development prospect prediction
Chapter 6 rebalance details
QT模拟鼠标事件,实现点击双击移动拖拽等
力扣leetcode第 280 场周赛
It is forbidden to trigger onchange in antd upload beforeupload
Research Report on market supply and demand and strategy of China's four flat leadless (QFN) packaging industry
Installation and configuration of MariaDB
Raspberry pie 4B installation opencv3.4.0
第6章 Rebalance详解
解决Intel12代酷睿CPU单线程只给小核运行的问题
Codeforces Global Round 19
useEffect,函數組件掛載和卸載時觸發
Acwing: Game 58 of the week
Solve the problem that intel12 generation core CPU single thread only runs on small cores
力扣——第298场周赛
Advancedinstaller installation package custom action open file