Jquery check box to select and uncheck the example

  • 2020-03-30 01:07:47
  • OfStack


A: when you click the checkbox, select all the subcheckboxes, and then click to uncheck all the checkboxes

B: if one child check box is selected, the parent check box is selected. If all children check boxes are not selected, the parent check box is not selected

function selectAll(mainId,klass){
 $("." + klass).each(function(){
     if($("#" + mainId).attr("checked")== "checked"){
      $(this).attr("checked", "checked");

The above implementation selects and unchecks all subboxes, and the implementation of the data receives an array of check boxes in the controller

function checkSonCheckBox(father,son){
  if($(this).attr("checked")== "checked"){
//      Console.log (" at least one child check box selected!" );
//      Console. Log (" all child checkboxes not selected!" );

The above implementation allows one child check box to be selected so that all child check boxes are not selected so that the parent check box is not selected

Related articles: