当前位置:网站首页>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()
}
}
边栏推荐
- Codeforces Round #801 (Div. 2)A~C
- Bisphenol based CE Resin Industry Research Report - market status analysis and development prospect forecast
- Click QT button to switch qlineedit focus (including code)
- QT实现圆角窗口
- QT有关QCobobox控件的样式设置(圆角、下拉框,向上展开、可编辑、内部布局等)
- Pull branch failed, fatal: 'origin/xxx' is not a commit and a branch 'xxx' cannot be created from it
- 875. Leetcode, a banana lover
- Generate random password / verification code
- Summary of FTP function implemented by qnetworkaccessmanager
- QT implementation fillet window
猜你喜欢
软通乐学-js求字符串中字符串当中那个字符出现的次数多 -冯浩的博客
Codeforces Round #802(Div. 2)A~D
MP4格式详解
Problem - 922D、Robot Vacuum Cleaner - Codeforces
FLV格式详解
antd upload beforeUpload中禁止触发onchange
Solve the problem that intel12 generation core CPU single thread only runs on small cores
新手必会的静态站点生成器——Gridsome
第5章 NameNode和SecondaryNameNode
Problem - 922D、Robot Vacuum Cleaner - Codeforces
随机推荐
Kubernetes cluster deployment
视频压缩编码和音频压缩编码基本原理
Discussion on QWidget code setting style sheet
Codeforces Round #800 (Div. 2)AC
(lightoj - 1370) Bi shoe and phi shoe (Euler function tabulation)
Codeforces Round #798 (Div. 2)A~D
Codeforces Round #799 (Div. 4)A~H
Li Kou - 298th weekly match
Tree of life (tree DP)
生成随机密码/验证码
Educational Codeforces Round 130 (Rated for Div. 2)A~C
Input can only input numbers, limited input
原生js实现全选和反选的功能 --冯浩的博客
< li> dot style list style type
Market trend report, technical innovation and market forecast of tabletop dishwashers in China
Solve the problem that intel12 generation core CPU single thread only runs on small cores
Research Report of desktop clinical chemical analyzer industry - market status analysis and development prospect prediction
300th weekly match - leetcode
Codeforces Round #798 (Div. 2)A~D
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines