选择题选项显示和选择

This commit is contained in:
caishi 2017-09-13 17:10:39 +08:00
parent f79a40ca65
commit 7bb99cee44
1 changed files with 55 additions and 18 deletions

View File

@ -14,30 +14,43 @@
<div class="panel-header clearfix" id="top_repository" style="border-bottom:0;padding:15px;">
<% @game_challenge.challenge_chooses.each_with_index do |choose, index| %>
<p class="font-bd font-18 color-grey3"><%= (index + 1).to_s + "." + (choose.category == 1 ? "单选题" : "多选题") %></p>
<div class="font-15 color-grey3 mb10 new_li read_only" unselectable="on" id="choose_subject_<%= index + 1 %>">
<div class="font-15 color-grey3 mb10 new_li read_only" unselectable="on" id="choose_subject_<%= index + 1 %>" style="padding: 10px 0px 10px 10px">
<textarea style="display:none;"><%= choose.subject %></textarea>
</div>
<% choose.challenge_questions.each_with_index do |question, i| %>
<pre class="mb10 back-f6-grey"></pre>
<div class="pl5 pr5 pt10 pb10 bor-grey-e">
<div for="result_<%= question.position %>" class="card -elevation-1 mt10 mb5 <%= (@user_answer.nil? || @user_answer.index(i.to_s).nil?) ? "" : "card-check color_white" %>" onclick="">
<!--单选-->
<% if choose.category == 1 %>
<input type="radio" name="answer[]" value="<%= (question.position + 65).chr %>" id="result_<%= question.position %>" class="ml-3 mr5 magic-radio ml5">
<% else %>
<!--多选-->
<input type="checkbox" name="answer[]" value="<%= (question.position + 65).chr %>" id="result_<%= question.position %>" class="ml-3 mr5 magic-checkbox ml5">
<% end %>
<div class="-layout-h -center break_word">
<span class="mr10"><%= (question.position + 65).chr %>.</span>
<div class="problem_single">
<% choose.challenge_questions.each_with_index do |question, i| %>
<p class="ml10 mb10 ">
<span>
<% if choose.category == 1 %>
<input type="radio" name="answer[]" category="<%= choose.category %>" value="<%= (question.position + 65).chr %>" id="result_<%= index %>_<%= i %>" class="ml-3 mr5 magic-radio ml5">
<% else %>
<!--多选-->
<input type="checkbox" name="answer[]" category="<%= choose.category %>" value="<%= (question.position + 65).chr %>" id="result_<%= index %>_<%= i %>" class="ml-3 mr5 magic-checkbox ml5">
<% end %>
<label for="result_<%= index %>_<%= i %>" style="top: 0px"><span><%= (question.position + 65).chr %></span>.<%= question.option_name %></label>
</span>
</p>
<% end %>
<input type="hidden" name="user_answer">
</div>
<% end %>
<!--<div class="pl5 pr5 pt10 pb10 bor-grey-e">
<div for="result_<%#= question.position %>" class="card -elevation-1 mt10 mb5 <%#= (@user_answer.nil? || @user_answer.index(i.to_s).nil?) ? "" : "card-check color_white" %>" onclick="">
&lt;!&ndash;单选&ndash;&gt;
<%# if choose.category == 1 %>
<input type="radio" name="answer[]" value="<%#= (question.position + 65).chr %>" id="result_<%#= question.position %>" class="ml-3 mr5 magic-radio ml5">
<%# else %>
&lt;!&ndash;多选&ndash;&gt;
<input type="checkbox" name="answer[]" value="<%#= (question.position + 65).chr %>" id="result_<%#= question.position %>" class="ml-3 mr5 magic-checkbox ml5">
<%# end %>
<div class="-layout-h -center break_word" for="result_<%#= question.position %>">
<span class="mr10"><%#= (question.position + 65).chr %>.</span>
<div class="markdown">
<p><code class="font-16"><%= question.option_name %></code></p>
<p><code class="font-16"><%#= question.option_name %></code></p>
</div>
</div>
</div>
</div>
<% end %>
<% end %>
</div>-->
<h3 id="save_status" class="ml15 fl" style="font-weight: normal"></h3>
</div>
</div>
@ -67,6 +80,30 @@
}
});
});
$(function(){
$(".problem_single p input").live("change",function(event){
var $this=$(this).parents(".problem_single").find("input[name='user_answer']");
var value="";
if($(this).attr("category")=="1"){
value="";
//alert($(this).siblings("label").find("span").html());
if($(this).attr("checked")=="checked"){
value=$(this).siblings("label").find("span").html();
}
}else{
var p=$(this).parents(".problem_single").find("p");
value="";
for(var i=0;i< p.length;i++){
if(p.eq(i).find("input").attr("checked")=="checked"){
//alert(p.eq(i).find("input").siblings("label").find("span").html());
value+=p.eq(i).find("input").siblings("label").find("span").html();
}
}
}
$this.val(value);
})
})
</script>