【问题标题】:Select all checkoxes if selected top one laravel 5.3如果选择了前一个 laravel 5.3,则选择所有复选框
【发布时间】:2016-11-08 16:05:31
【问题描述】:

在我的 user.js 文件中,我将以下方法编写为

js

$('.group-selector-campaign').click(function () {
    if($(this).is(':checked')) {
        $('.group-campaign-').prop('checked', true);
    } else {
        $('.group-campaign-').prop('checked', false);
    }
});

查看

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

它是我的标题,我希望如果标题复选框选中了所有下面的复选框也将自动选择。 下面对于所有其他表格字段,我将其用于第二行,依此类推

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

它不工作不知道为什么。 最重要的是我的功能是正确的,如果是,那么如何以及在何处添加 group-selector-campaign 类以正常工作

【问题讨论】:

  • 首先你应该检查你使用的所有选择器,因为我在你的html中没有看到.group-selector-campaigngroup-campaign-
  • 你能检查一下 $('.group-campaign-').attr('checked', true); $('.group-campaign-').attr('checked', false);
  • 为什么这个标签是 laravel?

标签: javascript php jquery laravel checkbox


【解决方案1】:

你可以这样做。

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

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2018-06-26
    • 1970-01-01
    • 1970-01-01
    • 2013-02-02
    • 2012-05-08
    • 1970-01-01
    • 2016-09-28
    • 1970-01-01
    • 2016-07-10
    相关资源
    最近更新 更多