Home > Web Front-end > JS Tutorial > Detailed explanation of JavaScript's functions of selecting all and inverting selection (with code examples)

Detailed explanation of JavaScript's functions of selecting all and inverting selection (with code examples)

藏色散人
Release: 2022-08-06 13:48:02
forward
2094 people have browsed it

This article will introduce to you how native js implements the functions of selecting all and inverting selection. I hope it will be helpful to friends in need!

## Idea: First we get the node

		遍历每个节点 获取到checked的属性
		然后我们通过改变checked的属性改变选中的状态
		全选的时候我们让他们都为true 
		反选的时候我们使用!达到效果
Copy after login

Detailed explanation of JavaScripts functions of selecting all and inverting selection (with code examples)

The knowledge points used this time are:

document.getElementsByName(‘name属性’):选中所有的name为name属性的的元素节点对象
document.getElementById('id名称'): 通过id名称获取一个元素节点对象
onclick:鼠标点击事件
Copy after login

html part:

<input> 全选
<input>足球
<input>篮球
<input>羽毛球
<input>反选
Copy after login

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 quan.onclick="function(){" fan.onclick></items.length>
Copy after login

Detailed explanation of JavaScripts functions of selecting all and inverting selection (with code examples)##Related recommendations: [

JavaScript video tutorial

The above is the detailed content of Detailed explanation of JavaScript's functions of selecting all and inverting selection (with code examples). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template