[英]How do I give the selected properties according to the item selection in the Select box?
When I select 12 or 24 or 36 in the Select box, how do I give the selected option a selected property when loaded? 当我在“选择”框中选择12或24或36时,如何在加载时为所选选项指定所选属性?
<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>
And I've chosen one more element, but I have to reload it twice, and the price of the element is applied... why?I set the default value of 12 and change the value of the list variable when the user selects the element 我已经选择了一个元素,但我必须重新加载它两次,并且元素的价格被应用...为什么?我设置默认值12并在用户选择时更改列表变量的值元件
if($request->list){
$list = $request->list;
}else{
$list = 12;
};
I dont really understand what you mean. 我真的不明白你的意思。 However try this code.
但试试这个代码。
<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>
you have to add the HTML selected attribute 您必须添加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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.