如何检查jquery datatable中的每个复选框? [英] How to check every checkboxes in a jquery datatable?

查看:943
本文介绍了如何检查jquery datatable中的每个复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,在第一列有复选框。我使用jQuery DataTable插件显示我的表。

I have a table with checkboxes in the first column. I use the jQuery DataTable plugin display my table.

我做了两个链接来选择/取消选择每个复选框。这里是一个选择所有:

I made 2 links to select/unselect every checkboxes. Here's the one to select all :

<a href="" name="CheckAll" onClick="checkAll(document.email_list_form_inviter.getElementsByClassName(\'email_checkbox\'), event)" >Select all</a>

和javascript:

And the javascript :

function checkAll(field, event) {
    event.preventDefault();
    for (i = 0; i < field.length; i++)
        field[i].checked = true ;

    return false;
}

但是datatable启用分页功能,我的函数只选择可见的复选框,的其他页面。如何选择数据表中的每个复选框?

But the datatable enables pagination and my function select only the visible checkboxes, not those of the other pages. How can do to select every checkboxes in my data table?

解决方案:

确定我使用fnGetNodes ,谢谢你amccausl!

Ok I did this with fnGetNodes, thank you amccausl!

$("a[name='CheckAll']").click(function(event) {
        event.preventDefault();
        var nodes = datatable.fnGetNodes( );
        $('.email_checkbox', nodes).attr("checked", "checked");
    });


推荐答案

您可以使用 fnGetNodes 来获取所需的所有节点,而不是getElementsByClassName。

You can use fnGetNodes to grab all the nodes you need, instead of the getElementsByClassName.

也可以使用jquery.click()事件,而不是定义一个onClick自己

You should also be using jquery.click() event instead of defining an onClick yourself

这篇关于如何检查jquery datatable中的每个复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆