Implementation code of jQuery all select and all not select event binding

  • 2021-07-13 04:22:39
  • OfStack

No more nonsense, just post the code for everyone. The specific code is as follows:

<td width="82%" colspan="3">
<input type="checkbox" id="all"> All selection &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="checkbox" id="reverse"> Reverse selection 
<td width="82%" colspan="3">
<s:checkboxlist name="resUuids" list="resList" listKey="uuid" listValue="name"></s:checkboxlist>
// All selection 
// Select all the following components 
//$("[name=resUuids]")   Is multiple components, and the whole is an array of objects 
// Get the state of the current component first 
// Set all components to the corresponding state 
//$(this).attr("checked") What exactly is the value obtained 
//alert($(this).attr("checked"));    //undefined
//js Grammar rules, except false,FALSE,"false","FALSE",05 All values except values are identified as true
var flag = $(this).attr("checked");
$("[name=resUuids]").attr("checked",flag == "checked");
// Reverse selection 
      // Switch the state of all components to the reverse state of the original state 
      // When multiple components are selected by the selector, any data obtained from the component is compared with the 1 Components to operate 
      // Iterate each component so that its operation state is inverse of the original state of the corresponding component 
        // Use each Operation implements the operation on each component 
        var flag = $(this).attr("checked"); 
        $(this).attr("checked", !(flag =="checked"));
// Binding component 
      // Set the selected all state to a comprehensive state value based on all components 
    function checkSelect(){
      var allFlag = true;
        var flag = $(this).attr("checked") == "checked";
        //&: Bit operation and    &&: Logical and 
        allFlag = allFlag && flag; 

Related articles: