【问题标题】:How to pass looping value attribute from the <options> tag to onchange attribute in the <select> tag [duplicate]如何将 <options> 标记中的循环值属性传递给 <select> 标记中的 onchange 属性 [重复]
【发布时间】:2018-02-23 09:50:29
【问题描述】:

我正在使用 laravel 框架。我用我的数据库中的数据填充了我的下拉列表。

<select class="form-control" id="username" name="username" onchange="somerandonfunction(blah)">     
            <option value="" selected>Select User</option>
            @foreach($getUsers as $list)
            <option value="{{$list->id}}" >{{$list->name}}</option>
            @endforeach

        </select>

我希望能够将单击的选项的值传递给 select> 标记中 onchange 属性中的函数。有没有办法做到这一点?

【问题讨论】:

  • 又是这个.....

标签: php laravel laravel-5


【解决方案1】:

你可以在函数中传递 this.value

<select class="form-control" id="username" name="username" onchange="somerandonfunction(this.value)">     
        <option value="" selected>Select User</option>
        @foreach($getUsers as $list)
        <option value="{{$list->id}}" >{{$list->name}}</option>
        @endforeach

    </select>

【讨论】:

    猜你喜欢
    • 2018-08-03
    • 2017-10-14
    • 2015-06-29
    • 2017-09-14
    • 2021-10-17
    • 1970-01-01
    • 2021-08-24
    • 2011-12-14
    • 1970-01-01
    相关资源
    最近更新 更多