0

我创建了一个测验,我希望每页显示一个问题,下面给出了我对 _ans 的部分视图,因为当我检查单选按钮时,下一个链接是有效的。如果我希望帮助获取单选按钮的值我检查了,如果我没有检查它返回null

 <div id = "main1">
  <% form_for @answer do |f|%>
    <div class = "questions">
      <div id = "passage">
        <%= "Passage"%>:<br>
      <%#= @ans.passage %>
      </div> <br>
      <label>
        <%= @s %> . <%= @ans.ques %>
      </label>  
      <div id = "options">
        <label for "options">
          <div id = "option-1">
            <%= radio_button_tag 'ans', 'ans1'%><%= @ans.ans1 %>
          </div><br>
          <div id = "option-2">
            <%= radio_button_tag 'ans', 'ans2'%><%= @ans.ans2 %>
          </div><br>
          <div id = "option-3">
            <%= radio_button_tag 'ans', 'ans3'%><%= @ans.ans3 %>
          </div><br>
          <div id = "option-4">
            <%= radio_button_tag 'ans', 'ans4'%><%= @ans.ans4  %>
          </div><br>
        </label>
      </div><br>
    </div><br><br>
    <div id = "prev">
      <%= link_to_remote "Previous", 
        :before => "Element.show('loader')",
        :success => "Element.hide('loader')",
        :update => "answers",
        :url=>{:controller=>"answers", :action=>"previous"},
        :with => "'&passed_question=#{@ans.id-1}&'+'&exam_group_id=#{@exam_group.id}&'"
      %> 
    </div>
    <div id = "next">
       <%= link_to_remote "Previous", 
        :before => "Element.show('loader')",
        :success => "Element.hide('loader')",
        :update => "answers",
        :url=>{:controller=>"answers", :action=>"previous"},
        :with => "'answer=$$('[name*=ans]:checked)[0].value+'&passed_question=#{@ans.id-1}&'+'&exam_group_id=#{@exam_group.id}&'"
      %> 
    </div>
    <div id = "sub">
      <%= link_to "Submit", final_exam_group_answers_path(@exam_group)%> 
    </div>
  <% end %> 
</div>
4

1 回答 1

0

尝试:

$(':radio[value=ans1]').prop('checked')
$(':radio[value=ans2]').prop('checked')
$(':radio[value=ans3]').prop('checked')
$(':radio[value=ans4]').prop('checked')

将为每个单选按钮返回 true 或 false。

要在未选择单选时返回 false,在选择任何内容时返回 true:

!!$(':radio:checked')[0]

如果你想返回 null:

!!$(':radio:checked')[0] == false ? null : true;
于 2013-11-06T15:24:12.177 回答