doujumiao5024 2013-06-07 09:16
浏览 197
已采纳

如何在分页的jquery数据表中选择多个复选框?

I am using jquery datatables. There I am using check box for each row inside the table. Now I want when a user click select all link which is outside of table, will select all records in the table. For that I am using this function.

function checkAll(formname, checktoggle)
{  
 var checkboxes = new Array(); 
 checkboxes = document[formname].getElementsByTagName('input');
 for (var i=0; i<checkboxes.length; i++)  {
  if (checkboxes[i].type == 'checkbox')   {
    checkboxes[i].checked = checktoggle;
   }
 }

}

Here select all link is

 <a onclick="javascript:checkAll('frm_charges', true);" href="javascript:void(0);">Select All</a>

"frm_charges" is the name and id of the form.

This is the code for check box, which I am using inside the table.

  <input type="checkbox" value="742" name="charges[]" class="charges"  style="opacity: 0; position: absolute; z-index: -1; visibility: hidden;">

Now my problem is I have pagination it is selecting rows from first page but not all page.Screenshot

  • 写回答

3条回答 默认 最新

  • donglang1894 2013-06-11 14:32
    关注

    Try This:

    $(function () {
        var oTable = $('#datatable').dataTable();
        $('#selectall').click(function () {
    
           var checkall =$('.main_table').find(':checkbox').attr('checked','checked');
           $.uniform.update(checkall);
        });
    });
    
    $(function () {
        var oTable = $('#datatable').dataTable();
        $('#deselectall').click(function () {
          //alert('hi');
           var checkall =$('.main_table').find(':checkbox').attr('checked',false);
           $.uniform.update(checkall);
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿