javascript 从数组值Laravel Js选中复选框

2ic8powd  于 2023-02-21  发布在  Java
关注(0)|答案(1)|浏览(90)

我使用带有复选框的Jquery Multiselect
我的选择标签

<div class="form-group mb-30">
<label class="font-sm color-text-mutted mb-10">Educational
    Qualification *</label>
<select class="form-control" name="educational_qualification[]" multiple="multiple">
    <optgroup label="Graduation Not Required">
        <option value="Graduation Not Required">Graduation Not Required
        </option>
    </optgroup>
    <optgroup label="Graduate">
        <option value="Any Graduate">Any Graduate</option>
        <option value="B.A">B.A</option>
        ...
        <option value="B.U.M.S">B.U.M.S</option>
        <option value="Other Graduate">Other Graduate</option>
    </optgroup>
    <optgroup label="Postgraduate">
        <option value="Any Postgraduate">Any Postgraduate</option>
        <option value="CA">CA</option>
        ...
        <option value="Post Graduation Not Required">Post Graduation Not
            Required</option>
        <option value="Other Post Graduate">Other Post Graduate</option>
    </optgroup>
    <optgroup label="Doctoral/Ph.D">
        <option value="Any Doctorate">Any Doctorate</option>
        ...
        <option value="Doctorate Not Required">Doctorate Not Required
        </option>
        <option value="Other Doctorate">Other Doctorate</option>
    </optgroup>
</select>

我将此值作为数组$job->education

如果值匹配,则选中复选框

ax6ht2ek

ax6ht2ek1#

在刀片中,在每个选项中循环$job-〉education数据,然后在选项标记中放置一个条件:
示例:

@foreach ($data as $value)
    <option value="Graduation Not Required" @if ($value == "Graduation Not Required") selected @endif>Graduation Not Required</option>
@endforeach

相关问题