Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript i选中复选框全选并刷新数据表_Javascript_Jquery_Html_Checkbox_Icheck - Fatal编程技术网

Javascript i选中复选框全选并刷新数据表

Javascript i选中复选框全选并刷新数据表,javascript,jquery,html,checkbox,icheck,Javascript,Jquery,Html,Checkbox,Icheck,我在引导中使用了iCheck for checkbox样式,但我遇到了一些问题,我无法选中/取消选中所有、、和dotn工作,无法及时刷新数据表,需要刷新页面,或者页面刷新了它 “高级”或“公共”中的复选框,当我选择它时,它将保持选中状态,并在重新加载页面后 <div class="table-responsive"> <table class="table"> <!-- Start Header --> <thea

我在引导中使用了iCheck for checkbox样式,但我遇到了一些问题,我无法选中/取消选中所有、、和dotn工作,无法及时刷新数据表,需要刷新页面,或者页面刷新了它

“高级”或“公共”中的复选框,当我选择它时,它将保持选中状态,并在重新加载页面后

<div class="table-responsive">
    <table class="table">
        <!-- Start Header -->
        <thead>
            <tr>
                <th>
                    <label class="checkbox checkbox-inline">
                        <input type="checkbox" name="file_id" value="0">
                    </label>
                </th>
                <th>Text Name</th>
                <th>Sixe Date</th>
                <th>Created Date</th>
                <th>Something</th>
                <th>Premium</i>
                </th>
                <th>Public</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <th scope="row">
                    <label class="checkbox checkbox-inline">
                        <input id="check" type="checkbox" name="file_id">
                    </label>
                </th>
                <td>Something</td>
                <td>Size</td>
                <td>Date</td>
                <td>Name</td>
                <td>
                    <label class="checkbox checkbox-inline">
                        <input type="checkbox" name="file_premium_only" </label>
                </td>
                <td>
                    <label class="checkbox checkbox-inline">
                        <input type="checkbox">
                    </label>
                </td>
          </tr> 
          <tr>
                <th scope="row">
                    <label class="checkbox checkbox-inline">
                        <input id="check" type="checkbox" name="file_id">
                    </label>
                </th>
                <td>Something</td>
                <td>Size</td>
                <td>Date</td>
                <td>Name</td>
                <td>
                    <label class="checkbox checkbox-inline">
                        <input type="checkbox" name="file_premium_only" </label>
                </td>
                <td>
                    <label class="checkbox checkbox-inline">
                        <input type="checkbox">
                    </label>
                </td>
          </tr> 
    </table>
</div>
<!-- /.table-responsive -->

文本名
六日
创建日期
某物
保险费
公开的
某物
大小
日期
名称

如果我正确理解了这个问题,您希望为您的页面提供同时选中/取消选中一组iCheck复选框的功能吗

我通过以下jQuery函数实现了类似的功能

function ToggleCheckboxes() {

    var flag = $('#togglebox').is(':checked')

    $("[name='PrintCheck']").each(function () {
        if (flag == true) {
            $(this).iCheck('check');                
        } else {
            $(this).iCheck('uncheck');                
        }
    });
}

此函数已分配给顶部复选框的onchange。然后,这将找到所有名为“PrintCheck”的复选框,并选中或取消选中

<input type="checkbox" id="togglebox" onchange="ToggleCheckboxes();">


希望这有帮助

您可以使用
ifToggled
i检查事件,如果选中/未选中,则使用
check
uncheck
方法在其他行中相应地执行操作

参考:

旁注:我为全选检查设置了一个特定的类
all
,并为每行检查设置了一个特定的类
selector
,避免了多个id值

代码:


演示:

我试过了,但没用,我想先勾选表中的第一个复选框,然后再勾选其他所有复选框,像这样,很抱歉我的英语不好,所以用我的方法,你应该能做的是。。。1) 将顶部复选框的“onclick”功能设置为togglecheckbox(来自我的答案)2)将列表中所有复选框的“name”属性设置为您喜欢的任何值。3) 将“[name='PrintCheck']替换为“[name=YOURNAME']”如果这仍然不起作用,那么您应该检查浏览器控制台是否存在上述任何JS错误,这些错误会阻止它工作抱歉,请更正,将复选框“onchange”而不是“onclick”设置为togglecheckbox…..下面是我编写的一个快速JSFIDLE,希望对您有所帮助!
jQuery(document).ready(function ($) {

    $('input').iCheck({
        checkboxClass: 'icheckbox_flat-pink',
        radioClass: 'iradio_flat-pink'
    });

    $('input.all').on('ifToggled', function (event) {
        var chkToggle;
        $(this).is(':checked') ? chkToggle = "check" : chkToggle = "uncheck";
        $('input.selector:not(.all)').iCheck(chkToggle);
    });

});