Home  >  Article  >  Web Front-end  >  Let the checkbox be unchecked and the checkbox that is about to be selected be unchecked_jquery

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

WBOY
WBOYOriginal
2016-05-16 16:42:121369browse

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;
}
});

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;
}
});
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