1

私は JQuery を必要とするフォームを実行しています。コンボボックスが 1 値を選択すると、状況に応じてラベルとテキストボックスが表示または非表示になります。debug で googlechrome を試すと、正しく動作します。しかし、自分の localhost で試してみると、うまくいきません。

これは私のJQueryです

<script type="text/javascript">
   $(document).ready(function(){
        $("#combine_category_id").change(function(){
        if ($(this).val() == 1){
        $("#type").hide();
        $("#block").show();
        $("#road").show();
        $("#level").show();
        $("#facing").show();
        $("#size").show();
        $("#value").hide();
        $("#asking").show();
        $("#project").show();
        $("#unit").hide();
        $("#match").show();
    }
        else if ($(this).val() == 2){
        $("#type").hide();
        $("#block").hide();
        $("#road").show();
        $("#level").hide();
        $("#facing").show();
        $("#size").show();
        $("#value").hide();
        $("#asking").show();
        $("#project").hide();
        $("#unit").show();
        $("#match").show();
    }
        else if ($(this).val() == 3){
        $("#type").show();
        $("#block").show();
        $("#road").show();
        $("#level").show();
        $("#facing").show();
        $("#size").show();
        $("#value").show();
        $("#asking").show();
        $("#project").hide();
        $("#unit").hide();
        $("#match").hide();
    }
   });
    });
  </script>

これは Ruby on Rails の _form.html.rb です

<div class="field" id="combine_category_id">
    <%= f.label :category_id %><br />
   <%= f.collection_select(:category_id ,  @get_master, :id , :category) %>
   </div>

   <div class="field" id="type">
    <%= f.label :type %><br />
    <%= f.number_field :type %>
    </div>

   <div class="field" id="project">
    <%= f.label :project_name %><br />
    <%= f.text_field :project_name %>
    </div>

    <div class="field" id="no">
    <%= f.label :unit_no %><br />
    <%= f.number_field :unit_no %>
    </div>

   <div class="field" id="block">
    <%= f.label :block_no %><br />
    <%= f.text_field :block_no %>
    </div>

   <div class="field" id="road">
    <%= f.label :road_name %><br />
    <%= f.text_field :road_name %>
    </div>

   <div class="field" id="level">
    <%= f.label :level %><br />
    <%= f.number_field :level %>
    </div>

   <div class="field" id="facing">
    <%= f.label :facing %><br />
    <%= f.text_field :facing %>
    </div>

   <div class="field" id="size">
    <%= f.label :size %><br />
    <%= f.number_field :size %>
    </div>

   <div class="field" id="value">
    <%= f.label :value %><br />
    <%= f.number_field :value %>
    </div>

   <div class="field" id="match">
    <%= f.label :match_bank %><br />
    <%= f.number_field :match_bank %>
    </div>

   <div class="field" id="asking">
    <%= f.label :asking %><br />
    <%= f.number_field :asking %>
    </div>

  <div class="actions">
    <%= f.submit %>
  </div>

これを解決する解決策はありますか?
私を助けてくれてありがとう。

4

1 に答える 1

1

入力ではなくdivを選択しています。

$("#combine_category_id select").change(...

于 2012-12-07T01:46:27.883 に答える