js loads the list of data, and selects all checkboxes

<th name="id"><input type="checkbox" name="checkItemsAll" class="checkItemsAll" onclick="swapCheck()"/></th>

The checkbox checkbox added to the header adds the click event swapCheck()

<tbody id="store_tbody"></tbody>

//Load data list
function loadStoreList(schemeId)

{
$.ajax({
        url: "<%=path%>/ui/psmSaleOrder/listStoreByScheme?schemeId="+schemeId,
        type: 'GET',
        async:true,
        contentType : 'application/json',

}).done(function (result)

{
    if(result!=null)

 {

  $("#store_tbody").empty(); //The table header is empty

      for(i=0;i<result.length; i++)
   {
        var _trs="<tr><input type=\"hidden\" name=\"item_hid\" value='"+result[i].id+"'/>";
      _trs+= '<td><input type=\"checkbox\" name=\"checkItem\" class=\"checkItem\"> <input type=\"hidden\"       name=\"item_hid\" value="'+result[i].id+'"/></td>'
    _trs+='<td title="'+result[i].enterpriseName+'">'+nulltoBlankAndSubstr(result[i].enterpriseName)+'</td>';
  _trs+= '<td>'+nulltoBlank(result[i].city)+'</td>';
  _trs+= '<td>'+nulltoBlank(result[i].name)+'</td>';
  _trs+= '<td>'+nulltoBlank(result[i].storeAddr)+'</td>';
  _trs+= '<td>'+nulltoBlank(result[i].shopHours)+'</td>';
  _trs+= '<td>'+nulltoBlank(result[i].orderTelephone)+'</td>';
  _trs+= '<td>'+nulltoBlank(result[i].busLine)+'</td>';
  _trs+="</tr>"; 
  $("#store_tbody").append(_trs)
    }
    }

}).fail(function (data)

{
    layer.alert('Load failed');
});


//checkbox 全选/取消全选  
var isCheckAll = false;  
function swapCheck()
{  
    if(isCheckAll) 
    {
        $("#store_tbody input[type='checkbox']").each(function() 
        {  
            this.checked = false;  
        });  
            isCheckAll = false;  
    } 
    else 
    {  
        $("#store_tbody input[type='checkbox']").each(function() 
        {  
            this.checked = true;  
        });  
        isCheckAll = true;  
    }  
}


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326660023&siteId=291194637