繁体   English   中英

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

[英]How to show hide a text field when something is selected from a drop down.

我的问题是,如果在选择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();
        }
      });
    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM