如何在多选表单 laravel 中选择所有选项?

Posted

技术标签:

【中文标题】如何在多选表单 laravel 中选择所有选项?【英文标题】:How can I select all the options in a multi select form laravel? 【发布时间】:2021-07-25 14:49:37 【问题描述】:

数据正在从数据库中获取,我想默认选择来自数据库的所有位置

 @php
          $default_location = null;
          if(count($business_locations) == 1)
            $default_location = array_key_first($business_locations->toArray());
          
        @endphp
        <div class="col-sm-4">
          <div class="form-group">
            !! Form::label('product_locations', __('business.business_locations') . ':') !! @show_tooltip(__('lang_v1.product_location_help'))
              !! Form::select('product_locations[]', $business_locations, $default_location, ['class' => 'form-control select2', 'multiple', 'id' => 'product_locations']); !!
          </div>
        </div>

【问题讨论】:

!! Form::select('product_locations[]', $business_locations, $default_location, ['class' =&gt; 'form-control select2', 'multiple', 'id' =&gt; 'product_locations'], 'selected' =&gt; 'true'); !! 我认为它可以满足您的需求。 【参考方案1】:

您可以使用 jquery 选择所有。

$(document).ready(function()
// all selected
$("#product_locations").prop('checked', true);
);

【讨论】:

欲了解更多信息,请查看此链接***.com/questions/16538399/…

以上是关于如何在多选表单 laravel 中选择所有选项?的主要内容,如果未能解决你的问题,请参考以下文章