Home >Web Front-end >JS Tutorial >Two different methods to implement js to select all and invert the checkbox_javascript skills

Two different methods to implement js to select all and invert the checkbox_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:48:341270browse

Two different methods are used to implement the full selection and inverse selection of the checkbox using js:

Method 1:

1: js implements the full selection function of the checkbox:

Copy code The code is as follows:

function checkAll()
{
var code_Values ​​= document.getElementsByTagName(" input");
for(i = 0;i < code_Values.length;i ){
if(code_Values[i].type == "checkbox")
{
code_Values[i ].checked = true;
}
}
}

2: js implements the checkbox anti-selection function:
Copy code The code is as follows:

function uncheckAll()
{
var code_Values ​​= document.getElementsByTagName("input");
for(i = 0;i < code_Values.length;i ){
if(code_Values[i].type == "checkbox")
{
code_Values[i].checked = false;
}
}
}
Statement:
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