簡體   English   中英

如何自動選中和取消選中復選框

[英]How to check and uncheck checkbox automatically

我正在做一個頁面,我可以在其中顯示帶有復選框的數據列表。 然后我將自動檢查數據庫,如果有數據,則將選中該復選框。 我現在想做的是,假設該復選框已自動選中,當我自己取消選中並保存時,它將更新數據庫中的數據。

我的編碼示例:

<form action="{{URL::to('/granted/'.$d->id)}}" method="get">
    <input name="_token" type="hidden" value="{{ csrf_token() }}"/>
    @foreach($var as $v)
    <table style="margin-left:20px;">
         <caption>{{$v->module_groupname}}</caption>
         @foreach($name as $n)
         <?php if($n->module_groupname == $v->module_groupname){?>
         <tr><td width="80"><input type="checkbox" name="module_code[]" value="{{ $n->module_code }}"
         <?php foreach($priv as $p){
         if($p->user_id == $d->id){
             if($p->module_code == $n->module_code){
                 echo 'checked="checked"';
             }
         }
     }?>></td>
     <td width="150">{{$n->module_groupname}}</td>
     <td width="200">{{ $n->module_desc}}</td>
    </tr> <?php } ?>
 @endforeach
</table>
<hr>
@endforeach
<input type="submit" value="select" class="btn btn-s btn-success">
</form>

建議我查找PLUS語句oracle,但我找不到如何

對於自動檢查,您需要設置選中該復選框的屬性

https://www.w3schools.com/tags/att_input_checked.asp

為了通過js做到這一點,請遵循以下網址! 說setAttribute屬性

https://www.w3schools.com/jsref/met_element_setattribute.asp

希望這個能對您有所幫助

<input type="checkbox" @if(compare) checked @endif />

我建議您看一下這段代碼,然后嘗試重新格式化自己的代碼。 您正在使用刀片,因此請隨處使用。

<form action="{{URL::to('/granted/'.$d->id)}}" method="get">
{{ csrf_field() }}
@foreach($var as $v)
    <table style="margin-left:20px;">
        <caption>{{$v->module_groupname}}</caption>
        @foreach($name as $n)
            @if($n->module_groupname == $v->module_groupname)
                <tr>
                    <td width="80"><input type="checkbox" name="module_code[]" value="{{ $n->module_code }}" {{ $priv->contains('user_id', $d->id) && $priv->contains('module_code', $n->module_code) ? 'checked' : '' }}></td>
                    <td width="150">{{$n->module_groupname}}</td>
                    <td width="200">{{ $n->module_desc}}</td>
                </tr>
            @endif
        @endforeach
    </table>
    <hr>
@endforeach
<input type="submit" value="select" class="btn btn-s btn-success">

我認為如果$ prev變量是模型,則可以使用contains函數。

我沒有測試此代碼,因此請嘗試是否有效

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM