2012-05-12 3 views
-1

/行く隠す...そのjsのフィドルでの作業だけでなく、私のアプリで...私の資産には、私の見解/ user_stepsでJailはレール3.2のアプリケーションで動作していませんか?シンプルなショーを取得しよう

/interests.html.erb

<label class="checkbox"> 
<input id="user_holiday_ids_" name="user[holiday_ids][]" type="checkbox" value="2" /> 
Valentine Day 
</label> 
<div style="display:none;"> 
    Whatever you have to capture here<input type="text" id="foo" /> 
</div> 
</br> 
<label class="checkbox"> 
<input id="user_holiday_ids_" name="user[holiday_ids][]" type="checkbox" value="3" /> 
Easter 
</label> 
<div style="display:none;"> 
    Whatever you have to capture here<input type="text" id="foo1" /> 
</div> 
</br> 
<label class="checkbox"> 
<input id="user_holiday_ids_" name="user[holiday_ids][]" type="checkbox" value="4" /> 
Mother Day 
</label> 
<div style="display:none;"> 
    Whatever you have to capture here<input type="text" id="foo2" /> 
</div> 
</br> 
<label class="checkbox"> 
    <input id="user_holiday_ids_" name="user[holiday_ids][]" type="checkbox" value="5" /> 
    Father's Day 
</label> 
<div style="display:none;"> 
    Whatever you have to capture here<input type="text" id="foo3" /> 
</div> 
</br> 
<label class="checkbox"> 
<input id="user_holiday_ids_" name="user[holiday_ids][]" type="checkbox" value="6" /> 
Halloween 
</label> 
<div style="display:none;"> 
    Whatever you have to capture here<input type="text" id="foo4" /> 
</div> 
</br> 
<label class="checkbox"> 
<input id="user_holiday_ids_" name="user[holiday_ids][]" type="checkbox" value="7" /> 
Thanksgiving 
</label> 
</br> 
<label class="checkbox"> 
    <input id="user_holiday_ids_" name="user[holiday_ids][]" type="checkbox" value="8" /> 
    Christmas 
</label> 

/javascripts/user_steps.js:

$(".checkbox").click(function(){ 
    $(this).next("div").toggle(); 
}); 
+2

エラーコンソールにエラーはありますか? – icktoofay

+1

多くの重複IDが問題です。 – Marc

+1

hiya、申し訳ありませんが、<2 mins back>はこれと同じ質問ではありません:http://stackoverflow.com/questions/10561210/how-to-show-hide-in-rails-form-with-jquery/? –

答えて

1

DOM要素のIDを重複しないでください。 IDはページ上で一意でなければなりません。もしそうでなければ、javascriptセレクターは信頼できなくなる可能性があります。

+0

同じ問題があっても、ビュー内のすべてのチェックボックスが削除されますが、1 ... – js111

関連する問題