Laravel 5, Form::select - 下拉菜单 select 'other'
Laravel 5, Form::select - Dropdown select 'other'
我正在 Laravel 5 站点上工作,并实现了一个带有下拉菜单的表单。一切正常,但用户应该能够 select 选项 "Other" 并编写自己的文本。
我用谷歌搜索并找到了一些好主意,但我无法实施。
这是我得到的:
<div class="form-group">
{!! Form::label('special_status', 'Erasmus, Nebenhöhrer:') !!}
{!! Form::select('special_status',$status, null, ['id' => 'special_status', 'class' => 'form-control', 'dropdown-menu']) !!}
</div>
与
$status = array (
'Erasmus' => 'Erasmus',
'NebenhörerIn'=> 'NebenhörerIn',
'Sonstiges' => 'Sonstiges',
);
举个例子:
http://jsfiddle.net/CxV9c/4/
这是我在 StOverf 上找到的:
Laravel 4 - Assign OnChange to Form::select
运行 Laravel 5.2.22 - Homestead
包括:
bootstrap.min.css
jquery.min.js
bootstrap.min.js
谢谢,
帕特
实际上,您可以在 blade
视图中放置一个 script
标签,例如:
<script>
$(function(){
$("input[type=text]").hide();
$('#visit').on('change', function () {
var v = this.value == 4 ? 'show' : 'hide';
$.fn[v].call($("input[type=text]"));
});
});
</script>
只需将此代码段放在 blade 视图的底部即可。另外,请确保您已添加 jQuery library vefore this script runs. This is the simplest way but there are other ways to add one or more script
tags in a blade view. A working example here.
我正在 Laravel 5 站点上工作,并实现了一个带有下拉菜单的表单。一切正常,但用户应该能够 select 选项 "Other" 并编写自己的文本。 我用谷歌搜索并找到了一些好主意,但我无法实施。 这是我得到的:
<div class="form-group">
{!! Form::label('special_status', 'Erasmus, Nebenhöhrer:') !!}
{!! Form::select('special_status',$status, null, ['id' => 'special_status', 'class' => 'form-control', 'dropdown-menu']) !!}
</div>
与
$status = array (
'Erasmus' => 'Erasmus',
'NebenhörerIn'=> 'NebenhörerIn',
'Sonstiges' => 'Sonstiges',
);
举个例子: http://jsfiddle.net/CxV9c/4/
这是我在 StOverf 上找到的: Laravel 4 - Assign OnChange to Form::select
运行 Laravel 5.2.22 - Homestead 包括:
bootstrap.min.css
jquery.min.js
bootstrap.min.js
谢谢,
帕特
实际上,您可以在 blade
视图中放置一个 script
标签,例如:
<script>
$(function(){
$("input[type=text]").hide();
$('#visit').on('change', function () {
var v = this.value == 4 ? 'show' : 'hide';
$.fn[v].call($("input[type=text]"));
});
});
</script>
只需将此代码段放在 blade 视图的底部即可。另外,请确保您已添加 jQuery library vefore this script runs. This is the simplest way but there are other ways to add one or more script
tags in a blade view. A working example here.