我有下面的html

    <script>
          $(document).ready(function(){
            $('.select_unselect_all').click(function(){
                   console.log('hurray>>>');
                    $('.se_unse').prop('checked', true);

            }); 
          });  
    </script>


<table cellpadding="0" cellspacing="0" border="0" class="stdtable">
   <thead>
      <tr>
         <th><input id="" class="select_unselect_all" type="checkbox"/></th>
         <th>product name</th>
      </tr>
   </thead>
   <tbody>
    {% for val in values %}
      <tr>
         <td><input id="" class="se_unse" type="checkbox" /></td>
         <td>{{val.name}}</td>
      </tr>
    {% endfor %}
   </tbody>
</table>

因此,从上面的HTML和jQuery代码中,当我们单击“使用类”的复选框时 select_unselect_all, ,所有剩余的复选框 tbody 与课程的街区 se_unse 应选择(其使用上述jQuery代码的IND)。

因此,当我们再次单击同一复选框时 select_unselect_allthead 部分所有检查的复选框应取消选中

那么如何在我的上述代码中实现这一点?

有帮助吗?

解决方案

尝试

$(document).ready(function () {
    $('.select_unselect_all').change(function () {
        $('.se_unse').prop('checked', this.checked);
    });
});

this.checked 告诉复选框是否已检查。返回布尔值。

。改变()

其他提示

尝试这个:

$(function(){
  $('.select_unselect_all').click(function(){
      $('.se_unse').prop('checked', $(this).prop('checked'));
  });
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top