Home  >  Article  >  Web Front-end  >  jQuery method to implement checkbox selection_jquery

jQuery method to implement checkbox selection_jquery

WBOY
WBOYOriginal
2016-05-16 15:56:181037browse

The example in this article describes how jQuery implements checkbox selection. Share it with everyone for your reference. The specific analysis is as follows:

Use checkbox to select all and deselect all. If you use toggle, there will be a problem that the checkbox cannot display the check mark.

Use the click event and judge based on the checked attribute.

Example:

$("#chkRreviewOffline").click(function(){ 
  if(this.checked){ 
    $('#review-offline .btn_checkbox input[type=checkbox]').each(function(index){ 
      this.checked=true; 
    }); 
  }else{ 
    $('#review-offline .btn_checkbox input[type=checkbox]').each(function(index){ 
      this.checked=false; 
    }); 
  } 
}); 
$('#review-offline .btn_checkbox input[type=checkbox]').each(function(index){ 
  $(this).click(function(){ 
    if(this.checked){ 
      //console.log('checked'); 
    }else{ 
      //console.log('not checked'); 
      $("#chkRreviewOffline").get(0).checked=false; 
    } 
  }); 
});

Among them, the following each() method is used to cancel all the selected checkboxes when other checkboxes on the page are unselected.

I hope this article will be helpful to everyone’s jQuery programming.

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