简体   繁体   English

如何根据“选择”框中的项目选择提供所选属性?

[英]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.

相关问题 如何将 HTML 多选 select 框滚动到第一个选中的选项? - How do I scroll an HTML multiple-selection select box to the first selected option? 选择选择框中的任何项目时,如何在jQuery中触发事件? - How do I trigger a event in jQuery when any item in a select box is selected? 我怎么知道用户是否在选择框中选择了相同的项目 - How can I know if the user selected the same item in a select box 如何滚动到选择框中的所选项目 - How to scroll to selected item in a select box 如何获取select框中选中的item的position - How to get the position of selected item in the select box 从选择框中选择项目 - Select item from selection box 如何在HTML中显示所选项目 <select>在顶部 - How do I show the selected item in an HTML <select> at the top 如何根据另一个选择框上的内容填充选择框? - How do I populate a select box depending on what was selected on the other select box? 使用Handlebars.js,如何使用全局上下文数据填充选择框,但如何使用当前循环项中的数据设置选择项? - Using Handlebars.js, how do I populate a select box with global context data but set the selected item with data from the current loop item? 根据从选择框中选择的item_ID从MySQL检索数据 - Retrieve data from MySQL according to the item_ID selected from the select box
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM