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

Let the checkbox be unchecked and the checkbox that is about to be selected be unchecked_jquery

WBOY
Release: 2016-05-16 16:42:12
Original
1374 people have browsed it

I encountered a problem while working on a project today. The selected checkbox needs to be left empty, and the checkbox to be selected needs to be unchecked. Finally, I found a method that works well, and I hereby record it.

$("input[type='checkbox']").each(function(){
if(this.checked){
this.checked=false;
}
});
Copy after login

Principle: Loop through each input of type checkbox. If it is selected, set its checked attribute to false and it will be ok.

Of course, if you want to achieve the effect of reverse selection, just add a little more. The code is as follows:

$("input[type='checkbox']").each(function(){
if(this.checked){
this.checked=false;
}

if(!(this.checked)){
this.checked=true;
}
});
Copy after login
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!