Javascript 从下拉列表中选择内容时如何显示和隐藏文本字段。

Javascript 从下拉列表中选择内容时如何显示和隐藏文本字段。,javascript,jquery,jquery-ui,ruby-on-rails-4,simple-form,Javascript,Jquery,Jquery Ui,Ruby On Rails 4,Simple Form,我的问题是,如果我在我的下拉列表中选择了像ABS这样的东西,当选择了ABS时,我怎么能显示一个文本框来输入额外的信息呢。我现在所拥有的一切都不起作用了…非常感谢您的帮助 这是我的app.js $(document).ready(function(){ $('#indirect_id').change(function() { var indirect_id = $(this).val(); if(indirect_id == 'ABS'){ $('#sick_com

我的问题是,如果我在我的下拉列表中选择了像ABS这样的东西,当选择了ABS时,我怎么能显示一个文本框来输入额外的信息呢。我现在所拥有的一切都不起作用了…非常感谢您的帮助

这是我的app.js

$(document).ready(function(){

$('#indirect_id').change(function() {
    var indirect_id = $(this).val();
    if(indirect_id == 'ABS'){
      $('#sick_comment').show();
    }
    else{
      $('#sick_comment').hide();
    }
  });
这是我的看法

.row-fluid
  =simple_form_for @entry, :url => url_for(:controller => 'entry', :action => 'create'), :method => :post do |f|

%table.table.table-bordered.table-striped{:style => 'table-layout:fixed; width:100% !important;'}
  %th.lt Indirect Code:
  %td.lt= f.input_field :indirect_id, :as => :select, :label => false, :collection => ['PD', 'VAC', 'ABS'], :id => 'indirect_id', :input_html => {:value => ''}


  %th.lt Optional Comment
  %td.lt= f.text_field :sick_day,  :label => false, :id => 'sick_comment', :input_html => {:value => ''}

%table.table.table-bordered.table-striped{:style => 'table-layout:fixed; width:100% !important;'}
= f.button :submit, "Submit", :class => 'btn btn-primary', :style => 'margin-left:50px;'

如果这是app.js的全文,则缺少一个结束括号和圆括号:

 $(document).ready(function(){
    $('#indirect_id').change(function() {
        var indirect_id = $(this).val();
        if(indirect_id == 'ABS'){
          $('#sick_comment').show();
        }
        else{
          $('#sick_comment').hide();
        }
      });
    });

我忘了那些。但还是没办法让它工作@BenJaspersIs文本框从未显示过?我怀疑这个
:input\u html=>{:value=>''}
可能正在将所有选项的值设置为空字符串。您是否打算发布您如何修复它??