2016-08-24 68 views
0

下面是我的jQuery這裏如何讓複選框使用jQuery檢查數據在Struts Action類數據和Ajax,請跟我說清楚如何發送選中複選框使用jQuery和Ajax Struts Action類

<script> 
    $(document).ready(function() { 
    $('#dataTables-example').DataTable({ 
     responsive : true, 
     "order":[],    
     "columnDefs": [ { 
     "targets": 0, 
     "orderable": false, 
     "className": "dt-center" 
     }]        
    }); 

    $("#selectall").click(function() { 
     $('.case').prop('checked', this.checked);    
     if ($('.case').prop('checked', this.checked)) { 
      count = this.checked ? $(".case").length : 0; 
      smsCount.innerHTML = count; 
     } 
     });   

     $(".case").click(function() { 
     count = $(".case:checked").length; 

     if ($(".case").length == $(".case:checked").length) { 
      $("#selectall").prop("checked", true); 
     } else { 
      $("#selectall").prop("checked", false); 
     } 

     smsCount.innerHTML = count; 
     }); 
    }); 
    }); 
</script> 

Full coding with html table

回答

0

在動作類

private Boolean example; 
public Boolean getExample() { return example; } 
public void setExample(Boolean example) { this.example = example; } 

添加值的屬性創建變量和getter和setter的複選框(S)

<input type="checkbox" class="case" value="true" name="example"/>

然後使用jquery的Ajax()函數通過POST將其發送或GET

$.ajax({ 
    url: yoururl, 
    method:'POST', 
    data: $('.case').serialize() 
}); 

當請求被提交的示例變量將是真或假取決於如果該複選框檢查與否。

+0

'input'-tag缺少名稱:'' – beendr

+0

Good catch,thx – steven35