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

jQuery method to implement checkbox selection_jquery

WBOY
Release: 2016-05-16 15:56:18
Original
1052 people have browsed it

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

Copy after login

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.

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