开发者

Hide/Show content when checkbox is clicked?

Hey, I have a code segment here:

<div class="label"><%= f.label :course %> <span>(Does this relate to a specific course?)</span></div>
    <%= check_box_tag(:no_course) %>
      <%= label_tag(:no_course, "None") %><br />
    <%= f.collection_select(:course_id, @current_account.courses.find(:all, :order => "name"), :id, :name) %>

How could I make it so that

<%= f.collection_select(:course_id, @current_account.courses.find(:all, :order => "name"), :id, :name) %>

only shows when

<%= check_box_tag(:no_course) %>
开发者_运维问答

Is selected using javascript?

Thanks!


If you are doing it with jQuery, do this in your document.ready:

if(!$('.no_course:checked').length) {
   $('myElementSelectedByClass').hide();
}

I am assuming here that it is originally shown and you are hiding it when the page loads. The basic premise is to get your checkbox DOM Element (in this case I get by class name) and see if the checked attribute is set. If not then hide it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜