Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Laravel 5.4,如何有条件地显示表单字段?_Javascript_Php_Laravel 5.4 - Fatal编程技术网

Javascript Laravel 5.4,如何有条件地显示表单字段?

Javascript Laravel 5.4,如何有条件地显示表单字段?,javascript,php,laravel-5.4,Javascript,Php,Laravel 5.4,我的Laravel 5.4应用程序中有一个表单,我想隐藏某些字段,除非从下拉框中选择了特定选项 我有以下JS脚本: $(document).ready(function() { $('#stall_id').change(function(){ if($('#stall-id').val() === '3') { $('#businessname').show(); $('#insurance').show(


我的Laravel 5.4应用程序中有一个表单,我想隐藏某些字段,除非从下拉框中选择了特定选项

我有以下JS脚本:

$(document).ready(function() {
    $('#stall_id').change(function(){
        if($('#stall-id').val() === '3')
        {
            $('#businessname').show();
            $('#insurance').show();
        } else
        {
            $('#businessname').hide();
            $('#insurance').hide();
        }
    });
});
这是我的表单字段:

<div class="form-group">
  {!! Form::label('businessname', 'Business Name:') !!}
  {!! Form::text('businessname', null, ['id' => 'businessname', 'class'=>'form-control'])!!}
</div>

<div class="form-group">
  {!! Form::label('insurance', 'Public Liability Insurance??:') !!}
  {!! Form::label('insurance', 'Yes') !!}
  {!! Form::radio('insurance', 1, ['id' => 'insurance', 'class'=>'form-control'])!!}
  {!! Form::label('insurance', 'No') !!}
  {!! Form::radio('insurance', 0, ['id' => 'insurance', 'class'=>'form-control'])!!}
</div>

{!!Form::label('businessname','businessname:')
{!!Form::text('businessname',null,['id'=>'businessname','class'=>'Form-control'])
{!!表单::标签('保险','公共责任保险??')
{!!Form::label('insurance','Yes')
{!!Form::radio('insurance',1,['id'=>'insurance',class'=>'Form-control'])
{!!Form::label('insurance','No')
{!!Form::radio('insurance',0,['id'=>'insurance',class'=>'Form-control'])
这些是我想要隐藏的表单字段,除非用户从下拉列表中选择选项3。
如何实现这一点?

谢谢

那么,问题是什么?您需要对下拉列表中的
onchange
事件做出响应,检查下拉列表的
selectedIndex
,查看其选项3是否正确。然后将表单组或单个输入元素的css从
display:hidden
修改为
display:inline
。您似乎正在使用引导。尝试添加
隐藏的
类,然后相应地删除。例如:
$('#businessname').addClass('hidden')