The problem of selecting all checkboxes can only be executed once

Phenomenon: When running for the first time, click select all the checkbox, you can select all, click again, you can cancel all. However, no matter how I clicked after that, it didn't work...

 

  1. <input type="checkbox" id="selectAll_top" />select all<br />  
  2. <input type="checkbox" name="sel" class="combinedPay" />1<br />  
  3. <input type="checkbox" name="sel" class="combinedPay" />2<br />  
  4. <input type="checkbox" name="sel" class="combinedPay" />3<br />  
  5.   
  6.   
  7. <script type="text/javascript">  
  8.     $("#selectAll_top").click(function(){  
  9.         if($("#selectAll_top").prop('checked')){  
  10.             $("#selectAll_end").attr("checked",true);  
  11.             $(".combinedPay").attr("checked",true);  
  12.         }else{  
  13.             $("#selectAll_end").attr("checked",false);  
  14.             $(".combinedPay").attr("checked",false);  
  15.         }  
  16.     });  
  17. </script> 

    Solution:

    Try changing attr to prop.
    Some versions of jquery have this problem,
    mainly the problem of attribute values ​​and state values.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325018003&siteId=291194637