محاولة
$(document).ready(function () {
$('.select_unselect_all').change(function () {
$('.se_unse').prop('checked', this.checked);
});
});
this.checked
يروي ما إذا كان مربع الاختيار قد تم فحصه أم لا. إرجاع القيمة المنطقية.
سؤال
لدي 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
يجب أن يتم فحص جميع مربع الاختيار المحدد
إذن كيف أقوم بتنفيذ هذا في الكود أعلاه؟
المحلول
محاولة
$(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'));
});
});