Home > Web Front-end > JS Tutorial > body text

两种不同的方法实现js对checkbox进行全选和反选_javascript技巧

WBOY
Release: 2016-05-16 16:48:34
Original
1159 people have browsed it

通过两种不同的方法实现用js来对checkbox进行全选和反选:

方法一:

1:js实现checkbox的 全选 功能:

复制代码 代码如下:

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

2:js实现checkbox的 反选 功能:
复制代码 代码如下:

function uncheckAll()
{
var code_Values = document.getElementsByTagName("input");
for(i = 0;i if(code_Values[i].type == "checkbox")
{
code_Values[i].checked = false;
}
}
}
Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!