呈现部分后,Javascript代码无效

时间:2016-01-29 14:06:45

标签: javascript jquery ruby-on-rails

<% if @questions_counter == 2 %>

  <% if @finish == 0 %>
    $("#initial-question-frame").fadeOut('fast');
    $("#next-question-frame").html("<%= escape_javascript(render(:partial => "question", :locals => {:question => @question, :finish_btn => @finish_btn })) %>").fadeIn();
  <% else %>
    $("#next-question-frame").html("<%= escape_javascript(render(:partial => "grade", :locals => {:correct_answers => @correct_answers, :grade => @grade, :total_questions => @total_questions })) %>").fadeIn();
  <% end %>
<% else %>

  <% if @finish == 0 %>
    $("#next-question-frame").html("<%= escape_javascript(render(:partial => "question", :locals => {:question => @question, :finish_btn => @finish_btn })) %>").fadeIn();
  <% else %>
    $("#next-question-frame").html("<%= escape_javascript(render(:partial => "grade", :locals => {:correct_answers => @correct_answers, :grade => @grade, :total_questions => @total_questions })) %>").fadeIn();
  <% end %>
<% end %>

$(document).ready(function(){
    $(":checkbox").on('change',function() {
      var that = this;

      if (!$(this).parent().hasClass("remember-label")){
        $(this).parent().css("background-color", function() {
            return that.checked ? "#C0E9F7" : "";
        });
      }

    });

    $("input[type=radio]").on('change',function() {
      $(this).parents().eq(1).siblings().css("backgroundColor","");
      $(this).parents().eq(1).css("backgroundColor","#C0E9F7");

    });

});

正常情况下javascript代码如果页面正确重新加载就可以了。如果它喜欢这样虽然它不起作用。当我点击包装输入的标签并且它具有正确的属性时,即使复选框/单选按钮被检查也没有任何反应。

<label for="choice_<%= choice.id %>">
            <%= radio_button_tag("choice","#{choice.id}",false,class:"radio big-radio") %>
            <% if choice.image? %>
              <%= image_tag rewrite_url(choice.image_url(:resized)), class:"choice-image" %>
            <% else %>
              <%= choice.description %>
            <% end %>

          </label>

0 个答案:

没有答案
相关问题