如果选中父复选框,则选中 laravel 中的子复选框

我有 2 个复选框:


         @foreach ($orders as order)


<span>Map view</span><br><input type="checkbox" class="parent" value="{{ $order->id }}" />


<input type="checkbox" name="checkbox[]" value="{{ $order->customers->location_url }}" data-rowid="{{ $order->id }}" class="child" />

<input type="checkbox"  name="checkbox1[]" value="{{ $order->customers->user->name }}" data-rowid="{{ $order->id }}" class="child" />


        @endforeach

我想如果父项被选中,则应该检查两个数据 rowid 的子项


HUX布斯
浏览 126回答 1
1回答

慕码人8056858

尝试这个$('input.parent').on('change', function(){&nbsp; &nbsp; var id = $(this).val();&nbsp; &nbsp; if($(this).is(':checked')){&nbsp; &nbsp; &nbsp; &nbsp; $('.child[data-rowid |="'+id+'"]').attr('checked', true);&nbsp; &nbsp; }else{&nbsp; &nbsp; &nbsp; &nbsp; $('.child[data-rowid |="'+id+'"]').attr('checked', false);&nbsp; &nbsp; }})
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript