当我在“选择”框中选择12或24或36时,如何在加载时为选定的选项赋予选定的属性?
doWork
我又选择了一个元素,但是我必须重新加载两次,然后应用元素的价格...为什么?我将默认值设置为12,并在用户选择元素
<form action="{{ route('penpal.index', ['list'=>$list,'page' => $page]) }}" method="post">
@csrf
<select id="inputState" class="form-control" style="height:35px; width:80%" name="list" onchange="this.form.submit()">
<option value="12" selected>@lang('penpal/component/indexMenu.twelve')</option>
<option value="24">@lang('penpal/component/indexMenu.twenty_four')</option>
<option value="36">@lang('penpal/component/indexMenu.thirty_six')</option>
</select>
</form>
答案 0 :(得分:0)
我真的不明白你的意思。但是,请尝试使用此代码。
<form action="{{ route('penpal.index', ['list'=>$list,'page' => $page]) }}" method="post">
@csrf
<select id="inputState" class="form-control" style="height:35px; width:80%" name="list" onchange="this.form.submit()">
<option value="12" {{(old('list') == 12) ? "selected" : ""}} >@lang('penpal/component/indexMenu.twelve')</option>
<option value="24" {{(old('list') == 24) ? "selected" : ""}} >@lang('penpal/component/indexMenu.twenty_four')</option>
<option value="36" {{(old('list') == 36) ? "selected" : ""}} >@lang('penpal/component/indexMenu.thirty_six')</option>
</select>
</form>
答案 1 :(得分:0)
您必须添加HTML selected属性
<select id="inputState" class="form-control" style="height:35px; width:80%" name="list" onchange="this.form.submit()">
<option value="12" selected="selected">@lang('penpal/component/indexMenu.twelve')</option>
<option value="24">@lang('penpal/component/indexMenu.twenty_four')</option>
<option value="36">@lang('penpal/component/indexMenu.thirty_six')</option>
</select>