【问题标题】:iCheck checkbox select all , and refresh data tableiCheck checkbox 全选,并刷新数据表
【发布时间】:2016-01-04 19:40:24
【问题描述】:

我在 bootstrap 中使用 iCheck 作为复选框样式,但我遇到了一些问题,我无法检查/取消选中所有,并且 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 -->

在这里你可以看到 codepen 的例子:

http://codepen.io/anon/pen/QjvomM

【问题讨论】:

    标签: javascript jquery html checkbox icheck


    【解决方案1】:

    您可以使用ifToggled iCheck 事件,如果选中/未选中,则使用checkuncheck 方法在其他行中进行相应的操作。

    参考:

    https://github.com/fronteed/iCheck#callbacks

    https://github.com/fronteed/iCheck#methods

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

    代码:

    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);
        });
    
    });
    

    演示:http://jsfiddle.net/IrvinDominin/estL6xrv/

    【讨论】:

      【解决方案2】:

      如果我正确理解了这个问题,您希望为您的页面提供同时选中/取消选中一组 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();">
      

      希望这会有所帮助!

      【讨论】:

      • 我尝试过,但它不起作用,我希望在检查表中的第一个复选框后可以检查所有其他复选框,例如 issues.wenzhixin.net.cn/bootstrap-table,抱歉我的英语不好
      • 所以使用我的方法你应该能够做的是...... 1)将顶部复选框的“onclick”功能设置为 ToggleCheckboxes(来自我的回答) 2)设置“名称”属性列表中的所有复选框到您喜欢的任何内容。 3) 将 "[name='PrintCheck'] 替换为 "[name=YOURNAME']" 如果这仍然不起作用,那么您应该检查浏览器控制台是否有上述任何 JS 错误会阻止它工作
      • 抱歉更正,将复选框“onchange”而不是“onclick”设置为 ToggleCheckboxes
      • jsfiddle.net/jymy5qox/3 .....这是我写的一个快速的 JSFiddle,希望对您有所帮助!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-05
      • 2015-06-12
      • 2016-11-11
      • 1970-01-01
      • 2012-02-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多