table表单全选

//全选表单代码不全,仅关键信息
<table cellpadding = "3" class = "data-grid" >
    < thead >
    < tr >
    < th >< input type = "checkbox" id = "checkAll" name = "checkAll" /></ th >

<tbody>
     <% if (listCRExtendMsg != null && listCRExtendMsg.size() > 0) { %>
          <%
             int index = 0;
              for (CRExtendMsg data : listCRExtendMsg) { %>
      < tr >
      < td >< input type = "checkbox" name = "checkItem" value = " <%= data.getId() %> " /></ td >
//js代码
//勾选复选框
$( function (){
           var $thr = $( 'table thead tr' );      //这是获取表头的复选框
          var $tbr = $( 'tbody tr td' );
           var $checkAll = $thr.find( 'input' );
          
          $checkAll.click( function (event){ 
              /*将所有行的选中状态设成全选框的选中状态*/  
              $tbr.find( 'input' ).prop( 'checked' ,$( this ).prop( 'checked' )); 
              /*阻止向上冒泡,以防再次触发点击操作*/  
              event.stopPropagation(); 
          }); 
     
    });

//前台勾选数据后的触发按钮

function batchCloseList() {
           var nodes = $( 'tbody tr td input:checked' ); //获取所有复选框选中的项作为一个对象
          var ids = new Array();  //创建一个接收id的数组
          $.each(nodes, function (i){    //遍历所选的对象
              if ($(nodes[i]).val() != 'on' ) { //'on'是表头数据也就是全选的复选框
                   ids.push($(nodes[i]).val());  //将每一个选中对象的值赋给接收id的数组
              }
          });
           if (ids.length !=0) {
               if (confirm( "是否将  " + ids.length + "  条数据关闭推广?" )){
                var param = {selectedItem : ids};
                  $.post( ' <%= path %> /chatRoom/closeExtend.htm ', param, function(data){
                     if (data.code == 0) {
                             window.location.reload();
                        } else {
                             layer.alert(data.msg);
                   }
                  }, 'json' );
              }
          }
    }

//前台传值为数组,后台转为list接收
@ResponseBody
@RequestMapping (value = " /closeExtend " )
public Map<String, Object> closeExtend( @RequestParam(value = "selectedItem[]", required = false ) List<String> selectedItem, HttpServletRequest request, ModelMap model) {
      Map<String, Object> data = Constants. newReturnMap (0);
      String isOpenExtend = "0" ;
      Boolean success = chatRoomService .closeExtend(selectedItem, isOpenExtend);
       if (!success) {
         data.put( "code" , -1);
         data.put( "msg" , "修改失败!" );
      }
       return data;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值