如果选中top 1 laravel 5.3,则选中所有复选框

Select all checkoxes if selected top one laravel 5.3

本文关键字:复选框 top laravel 如果      更新时间:2023-09-26

在我的user.js文件中,我写了以下方法

js

$('.group-selector-campaign').click(function () {
    if($(this).is(':checked')) {
        $('.group-campaign-').prop('checked', true);
    } else {
        $('.group-campaign-').prop('checked', false);
    }
});
<<p> 视图/strong>
 <label class="mt-checkbox mt-checkbox-single mt-checkbox-outline">
<input type="checkbox" class="checkboxes">
                     </label>
                            </th>
                            <th>Name</th>
                            <th>Email</th>
                            <th>Created at</th>
                            <th>Actions</th>

这是我的标题,我想如果标题复选框选中所有下面的复选框也将自动选择。对于下面所有其他表字段,我在第2行使用this,等等

<label class="mt-checkbox mt-checkbox-single mt-checkbox-outline">
  <input type="checkbox" class="checkboxes" value="1">
                                   </label>

不工作,不知道为什么。如果是,那么如何以及在哪里添加group-selector-campaign类才能正常工作

你可以这样做。

----- jQuery Syntax --------
$('.top-selector').click(function () {
    var this_element = $(this);
    var check = false;
    if(this_element.is(":checked")) {
        check = true;
    }
    // var campaign-checkboxes = 
    this_element.find('select.group-selector-campaign').each(function (i) {
        if(check) {
            $(this).prop("checked", true);
        } else {
            $(this).prop("checked", false);
        }
    })
});
----- HTML Syntax --------
<select type="checkbox" class="top-selector" value="">
<div class="campaign-checkboxes">
    <select type="checkbox" class="group-selector-campaign" value="">
    <select type="checkbox" class="group-selector-campaign" value="">
    <select type="checkbox" class="group-selector-campaign" value="">
    <select type="checkbox" class="group-selector-campaign" value="">
</div>