首页 > 解决方案 > 如何确保在一个下拉列表中选择的值将更改 Laravel 中另一个下拉列表的值

问题描述

我正在开发 Laravel 项目,我想要实现的是,当用户在下拉列表中选择某个值时,它应该会影响视图中的其他下拉列表,也就是说,如果用户在第一个下拉列表中选择收入,则应该禁用费用下拉列表或类似那个控制器的东西

>  public function create()
>     {
>         $income = Income::pluck('title', 'id');
>         $expense=Expenses::pluck('title', 'id');
>         return view ('IncomeExpense.create', compact('income','expense'));
>     }

看法

<div class="form-group">
>      {{Form::label('IncomeExpense', 'Income&Expense')}}
>      {{Form::select('IncomeExpense', array('E' => 'Expense', 'I' => 'Income'),null,['class'=>'form-control'])}}
>     </div>
>     <div class="form-group">
>             {{Form::label('', 'Income')}}           
>             {{Form::select('IncomeId', $income,null,['class'=>'form-control'])}}
>            </div>
>            <div class="form-group">
>                 {{Form::label('', 'Expense')}}           
>                 {{Form::select('ExpenseId', $expense,null,['class'=>'form-control'])}}
>                </div>

标签: phplaravellaravel-5laravelcollective

解决方案


在放置类的数组中,您还可以像这样分配一个id

{{Form::select('IncomeId', $income, null,['class'=>'form-control', 'id' => 'MyAwesomeId'])}}

然后,您可以像使用普通 html 一样使用 javascript/jquery。


推荐阅读