Commit 10146a46026ec6652fe81a9ebf9fb5cdce1a52fc

Authored by 孙向锦
1 parent a0ec879e

创建试卷

Showing 1 changed file with 26 additions and 17 deletions
WebRoot/static/js/control-604.js
1 1 $(function(){
2 2 /*快速创建答案列表*/
3 3 var score=0;
  4 + var total_score = 0;
  5 + var questionNUm = 0 ;
4 6 function creat(str_ans,a_num,fraction){
5   - $(".section").remove();
  7 +// $(".section").remove();
  8 + answer_index_b=$(".section").length+1;
6 9 /*$(".content").append('<div class="section section-1 single" data-fraction="'+fraction+'" data-score=""> <div class="title"> <h3><span class="que_num">一、</span><span class="que_name">单选</span></h3> <input type="button" class="btn btn-danger pull-right remove" name="remove" value="删除" /> </div> <div class="question_list"></div></div>')*/
7   - $(".content").append('<div class="section section-1 single" data-fraction="'+fraction+'" data-score=""><div class="title"><h3><span>请在试题选项上点击,亮色为该试题的正确答案&nbsp; </span></h3> </div><div class="question_list"></div></div>');
8 10 var str=str_ans.split('');
9 11 console.log(str);
10 12 for(i=0;i<str.length;i++){
... ... @@ -14,28 +16,32 @@
14 16 }
15 17 }
16 18 q_num=str.length;
  19 + $(".content").append('<div class="section section-' + answer_index_b +' single" data-fraction="'+fraction+'" data-score=""><div class="title"><h3>第' +answer_index_b +'大题总分: ' + (q_num * fraction)+'分<!--<span>请在试题选项上点击,亮色为该试题的正确答案&nbsp; </span> --></h3> </div><div class="question_list"></div></div>');
17 20 for(var i=0;i<q_num;i++){
18 21 str_temp=str[i];
19 22 str_temp=str_temp.toUpperCase()
20 23 code = str_temp.charCodeAt();
21 24 on_index=code-65;
  25 + questionNUm++;
22 26 if(code<(65+a_num)){
23 27 console.log(str_temp);
24   - $(".question_list").append('<div class="question question'+(i+1)+'"><span>'+(i+1)+'、</span><ul></ul></div>');
  28 + $(".section-" +answer_index_b +" .question_list").append('<div class="question question'+(questionNUm)+'"><span>'+(questionNUm)+'、</span><ul></ul></div>');
25 29 for(var j=0;j<a_num;j++){
26 30 option=String.fromCharCode(0x41+j);
27 31 if(on_index==j){
28 32 console.log(on_index+"---"+j);
29   - $(".question"+(i+1)+' ul').append('<li class="btn btn-default on">'+option+'</li>');
  33 + $(".question"+(questionNUm)+' ul').append('<li class="btn btn-default on">'+option+'</li>');
30 34 }else
31   - $(".question"+(i+1)+' ul').append('<li class="btn btn-default">'+option+'</li>');
  35 + $(".question"+(questionNUm)+' ul').append('<li class="btn btn-default">'+option+'</li>');
32 36 }
33 37 }else{
34 38 alert("题目"+(i+1)+":"+String.fromCharCode(code)+"答案错误,超出选项数");
35 39 //return;
36 40 }
37 41 }
38   - $(".section-1").attr("data-score",$(".section-1").find(".question").length*fraction);
  42 + $(".section-" +answer_index_b).attr("data-score",$(".section-1").find(".question").length*fraction);
  43 + total_score += q_num * fraction;
  44 + $("#score_all").text(total_score);
39 45 }
40 46  
41 47 /***********
... ... @@ -105,15 +111,18 @@
105 111 }
106 112 }*/
107 113 case 5: //多选题
108   - $(".content").html("");
109   - $(".content").append('<div class="section section0'+' check" data-fraction="'+fraction2+'" data-score=""> <div class="title"><h3><span>请在试题选项上点击,亮色为该试题的正确答案&nbsp; </span></h3> </div> <div class="question_list"></div></div>');
  114 +// $(".content").html("");
  115 + $(".content").append('<div class="section section-'+ answer_index_b +' check" data-fraction="'+fraction2+'" data-score=""> <div class="title"><h3>第' +answer_index_b +'大题总分: ' + ((index_e_2- index_s_2 + 1 )* fraction2)+'分<!--<span>请在试题选项上点击,亮色为该试题的正确答案&nbsp; </span>--></h3> </div> <div class="question_list"></div></div>');
110 116 for(var i=index_s_2;i<=index_e_2;i++){
111   - $(".section0" +" .question_list").append('<div class="question question'+i+'"><span>'+i+'、</span><ul></ul></div>');
  117 + questionNUm++;
  118 + $(".section-" + answer_index_b +" .question_list").append('<div class="question question'+questionNUm+'"><span>'+questionNUm+'、</span><ul></ul></div>');
112 119 for(var j=0;j<a_num;j++){
113 120 option=String.fromCharCode(0x41+j);
114   - $(".section0"+" .question"+i+' ul').append('<li class="btn btn-default">'+option+'</li>');
  121 + $(".section-" + answer_index_b +" .question"+questionNUm+' ul').append('<li class="btn btn-default">'+option+'</li>');
115 122 }
116 123 }
  124 + total_score +=((index_e_2- index_s_2 + 1 )* fraction2);
  125 + $("#score_all").text(total_score);
117 126 break;
118 127 }
119 128 // $(".section-"+answer_index_b).attr("data-score",$(".section-"+answer_index_b).find(".question").length*fraction2);
... ... @@ -125,7 +134,7 @@
125 134 })
126 135  
127 136 $("#fast_submit").click(function(){ //点击确定,创建答案列表
128   - $("#addQuestion").attr("disabled","disabled");
  137 +// $("#addQuestion").attr("disabled","disabled");
129 138 var answer=$("#answer").val();
130 139 var num_ans=$("#num_ans").val();
131 140 var fraction=$("#fraction").val();
... ... @@ -136,7 +145,7 @@
136 145 alert("请输入题目分数");
137 146 return;
138 147 }
139   - var frac = parseInt(fraction);
  148 + var frac = parseFloat(fraction);
140 149 if(frac > 0){
141 150 $('.fast').modal('hide');
142 151 //score += parseInt(fraction)*answer.split(",").length;
... ... @@ -149,13 +158,13 @@
149 158  
150 159 /*添加试题的确定按钮*/
151 160 $("#addQuestion_submit").click(function(){
152   - $("#fast").attr("disabled","disabled");
  161 +// $("#fast").attr("disabled","disabled");
153 162 var type_2=5;//parseInt($("#type").val())
154 163 var index_s_2=1;//parseInt($("#index_s_2").val())
155 164 var index_e_2=parseInt($("#index_s_2").val());
156 165 //var answer_2=$("#answer_2").val();
157 166 var num_ans_2=$("#num_ans_2").val();
158   - var fraction2=parseInt($("#fraction2").val());
  167 + var fraction2=parseFloat($("#fraction2").val());
159 168 if(isNaN(index_s_2)){
160 169 alert("请输入题目开始序号");
161 170 return;
... ... @@ -213,7 +222,7 @@
213 222 $("#save").click(function(){
214 223 var url=URL;
215 224 for(i=0;i<$(".section").length;i++){
216   - score+=parseInt($(".section").eq(i).attr("data-score"));
  225 + score+=parseFloat($(".section").eq(i).attr("data-score"));
217 226 }
218 227 var data={
219 228 title: $(".header_box h1").text(),
... ... @@ -260,7 +269,7 @@
260 269 alert("还有试题未编辑答案。");
261 270 return;
262 271 }
263   - data.questions[j]={
  272 + data.questions[rank-1]={
264 273 chapter_id: "0",
265 274 problem_type_id: "0",
266 275 knowledge_id: "0",
... ... @@ -275,7 +284,7 @@
275 284 part_score: "0",
276 285 remark: "",
277 286 rank: rank,
278   - no_name: (j+1),
  287 + no_name: rank,
279 288 }
280 289 }
281 290 }
... ...