[英]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_all
在thead
節中的所有檢查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.