簡體   English   中英

選中/取消選中jQuery中具有相同復選框的復選框

[英]Check/Uncheck the checkbox with same checkbox in jquery

我有下面的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代碼一起使用)。

因此,當我們用類相同的復選框,再次單擊select_unselect_allthead節中的所有檢查checkboxed應該是選中

那么如何在我上面的代碼中實現呢?

嘗試

$(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 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM