如何将复选框选择检查的值发送给控制器?

时间:2019-06-07 11:36:46

标签: jquery css

我想选择一个复选框并将多个值发送到控制器。但是,如果完全选择成功,如何将许多选择的值发送到控制器?

  <table class="table">
    <thead>
        <tr>
            <th scope="col"><input type="checkbox" id="checkall" /></th>
            <th scope="col">@lang('home/mail/receiveTable.sender')</th>
            <th scope="col">@lang('home/mail/receiveTable.content')</th>
            <th scope="col">@lang('home/mail/receiveTable.time')</th>
            <th scope="col">@lang('home/mail/receiveTable.delete')</th>
        </tr>
    </thead>
    <tbody>
        @if($senders != null)
        @foreach($senders as $sender)
        <tr>
            <th scope="row"><input type="checkbox" name="chk" value="{{ $sender->id }}" /></th>
            <td>
                @if($sender->user->country == 'ko')
                <img src="{{ asset("data/ProjectImages/master/korea.png") }}" alt="men">
                @else
                <img src="{{ asset("data/ProjectImages/master/japan.png") }}" alt="women">
                @endif
                <span id="userInfo" data-toggle="modal"
                      data-target="#Modal-large-demo{{ $sender->user->id }}">{{ $sender->user->name }}</span>
            </td>
            <td class="mailsTd">
                @if($sender->is_read == 0)
                <img src="{{ asset("data/ProjectImages/penpal/no_read.png") }}" alt="men">
                @else
                <img src="{{ asset("data/ProjectImages/penpal/ok_read.png") }}" alt="women">
                @endif
                <a href="{{ route('mail.show',['id' => $sender->id,'page' => $page]) }}">{{ $sender->content }}</a>
            </td>
            <td>{{ $sender->created_at }}</td>
            <td>
                <button type="button" class="btn btn-danger"
                    onclick="location.href='{{ route('mail.delete',['id' => $sender->id]) }}'"><i
                        class="fa fa-trash"></i>
                </button>
            </td>
        </tr>
        @endforeach
        @endif
    </tbody>
</table>

jquery

$(document).ready(function () {
    //최상단 체크박스 클릭
    $("#checkall").click(function () {
        //클릭되었으면
        if ($("#checkall").prop("checked")) {
            //input태그의 name이 chk인 태그들을 찾아서 checked옵션을 true로 정의
            $("input[name=chk]").prop("checked", true);
            //클릭이 안되있으면
        } else {
            //input태그의 name이 chk인 태그들을 찾아서 checked옵션을 false로 정의
            $("input[name=chk]").prop("checked", false);
        }
    })

})

我想将所选值发送到使用此按钮注册的URL。

 <button class="btn btn-danger" type="button">selectDelect</button>

1 个答案:

答案 0 :(得分:0)

首先,您要制作<input type="checkbox" name="chk[]">,在这里,chk应该是一个数组,并用动作将其包装在表单中并提交