jqueryの同じチェックボックスでチェックボックスをチェック/チェックしてください

StackOverflow https://stackoverflow.com/questions/20354069

質問

以下のような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 セクションチェックボックス化されたすべてのチェックボックス化されたチェックなし

では、上記のコードにこれを実装する方法は?

役に立ちましたか?

解決

試す

$(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