Commit 5f403333f85c6de95ebaa0c82d8ca5912e0a9af0
1 parent
803a7d44
1,完善数字题
Showing
2 changed files
with
92 additions
and
78 deletions
WebRoot/WEB-INF/jsp/sunvote/teacher/creat_question.jsp
... | ... | @@ -41,41 +41,7 @@ |
41 | 41 | </div> |
42 | 42 | |
43 | 43 | <div class="content container"> |
44 | - <div class="section section-1 number" data-fraction="1" data-score=""> | |
45 | - <div class="title"> | |
46 | - <h3> | |
47 | - <span class="que_num">一、</span><span class="que_name">单选</span> | |
48 | - </h3> | |
49 | - <input type="button" class="btn btn-danger pull-right remove" | |
50 | - name="remove" value="删除"> | |
51 | - </div> | |
52 | - <div class="question_list"> | |
53 | - <div class="question question1"> | |
54 | - <span>1、</span> | |
55 | - <ul> | |
56 | - <li class="btn btn-default on" contenteditable="true" onkeydown="$(this).text(NumberCheck($(this).text()))">请输入答案</li> | |
57 | - </ul> | |
58 | - </div> | |
59 | - <div class="question question2"> | |
60 | - <span>2、</span> | |
61 | - <ul> | |
62 | - <li class="btn btn-default on" contenteditable="true">请输入答案</li> | |
63 | - </ul> | |
64 | - </div> | |
65 | - <div class="question question3"> | |
66 | - <span>3、</span> | |
67 | - <ul> | |
68 | - <li class="btn btn-default on" contenteditable="true">请输入答案</li> | |
69 | - </ul> | |
70 | - </div> | |
71 | - <div class="question question4"> | |
72 | - <span>4、</span> | |
73 | - <ul> | |
74 | - <li class="btn btn-default on" contenteditable="true">请输入答案</li> | |
75 | - </ul> | |
76 | - </div> | |
77 | - </div> | |
78 | - </div> | |
44 | + | |
79 | 45 | </div> |
80 | 46 | |
81 | 47 | <!-- 快速出题 --> | ... | ... |
WebRoot/static/js/control-604.js
... | ... | @@ -190,43 +190,77 @@ $(function() { |
190 | 190 | * for(var j=0;j<a_num;j++){ option=String.fromCharCode(0x41+j); |
191 | 191 | * $(".section-"+answer_index_b+" .question"+i+' ul').append('<li class="btn btn-default">'+option+'</li>'); } } |
192 | 192 | */ |
193 | - case 5: // 多选题 | |
194 | - // $(".content").html(""); | |
195 | - $(".content") | |
196 | - .append( | |
197 | - '<div class="section section-' | |
198 | - + answer_index_b | |
199 | - + ' check" data-fraction="' | |
200 | - + fraction2 | |
201 | - + '" data-score="' | |
202 | - + ((index_e_2 - index_s_2 + 1) * fraction2) | |
203 | - + '"> <div class="title"><h3>第' | |
204 | - + answer_index_b | |
205 | - + '大题(多选)总分: ' | |
206 | - + (index_e_2 - index_s_2 + 1) | |
207 | - + ' X ' | |
208 | - + fraction2 | |
209 | - + ' = ' | |
210 | - + ((index_e_2 - index_s_2 + 1) * fraction2) | |
211 | - + ' 分<!--<span>请在试题选项上点击,亮色为该试题的正确答案 </span>--></h3> </div> <div class="question_list"></div></div>'); | |
212 | - for (var i = index_s_2; i <= index_e_2; i++) { | |
213 | - questionNUm++; | |
214 | - $(".section-" + answer_index_b + " .question_list").append( | |
215 | - '<div class="question question' + questionNUm | |
216 | - + '"><span>' + questionNUm | |
217 | - + '、</span><ul></ul></div>'); | |
218 | - for (var j = 0; j < a_num; j++) { | |
219 | - option = String.fromCharCode(0x41 + j); | |
220 | - $( | |
221 | - ".section-" + answer_index_b + " .question" | |
222 | - + questionNUm + ' ul').append( | |
223 | - '<li class="btn btn-default">' + option + '</li>'); | |
224 | - } | |
225 | - } | |
226 | - total_score += ((index_e_2 - index_s_2 + 1) * fraction2); | |
227 | - $("#score_all").text(total_score); | |
228 | - break; | |
229 | - case 6: break; | |
193 | + | |
194 | + case 5: $(".content") //多选题 | |
195 | + .append( | |
196 | + '<div class="section section-' | |
197 | + + answer_index_b | |
198 | + + ' check" data-fraction="' | |
199 | + + fraction2 | |
200 | + + '" data-score="' | |
201 | + + ((index_e_2 - index_s_2 + 1) * fraction2) | |
202 | + + '"> <div class="title"><h3>第' | |
203 | + + answer_index_b | |
204 | + + '大题(多选)总分: ' | |
205 | + + (index_e_2 - index_s_2 + 1) | |
206 | + + ' X ' | |
207 | + + fraction2 | |
208 | + + ' = ' | |
209 | + + ((index_e_2 - index_s_2 + 1) * fraction2) | |
210 | + + ' 分<!--<span>请在试题选项上点击,亮色为该试题的正确答案 </span>--></h3> </div> <div class="question_list"></div></div>'); | |
211 | + for (var i = index_s_2; i <= index_e_2; i++) { | |
212 | + questionNUm++; | |
213 | + $(".section-" + answer_index_b + " .question_list").append( | |
214 | + '<div class="question question' + questionNUm | |
215 | + + '"><span>' + questionNUm | |
216 | + + '、</span><ul></ul></div>'); | |
217 | + for (var j = 0; j < a_num; j++) { | |
218 | + option = String.fromCharCode(0x41 + j); | |
219 | + $( | |
220 | + ".section-" + answer_index_b + " .question" | |
221 | + + questionNUm + ' ul').append( | |
222 | + '<li class="btn btn-default">' + option + '</li>'); | |
223 | + } | |
224 | + } | |
225 | + total_score += ((index_e_2 - index_s_2 + 1) * fraction2); | |
226 | + $("#score_all").text(total_score); | |
227 | + break; | |
228 | + case 6: // 数字题 | |
229 | + // $(".content").html(""); | |
230 | + $(".content") | |
231 | + .append( | |
232 | + '<div class="section section-' | |
233 | + + answer_index_b | |
234 | + + ' number" data-fraction="' | |
235 | + + fraction2 | |
236 | + + '" data-score="' | |
237 | + + ((index_e_2 - index_s_2 + 1) * fraction2) | |
238 | + + '"> <div class="title"><h3>第' | |
239 | + + answer_index_b | |
240 | + + '大题(数字题)总分: ' | |
241 | + + (index_e_2 - index_s_2 + 1) | |
242 | + + ' X ' | |
243 | + + fraction2 | |
244 | + + ' = ' | |
245 | + + ((index_e_2 - index_s_2 + 1) * fraction2) | |
246 | + + ' 分<!--<span>请在试题选项上点击,亮色为该试题的正确答案 </span>--></h3> </div> <div class="question_list"></div></div>'); | |
247 | + for (var i = index_s_2; i <= index_e_2; i++) { | |
248 | + questionNUm++; | |
249 | + $(".section-" + answer_index_b + " .question_list").append( | |
250 | + '<div class="question question' + questionNUm | |
251 | + + '"><span>' + questionNUm | |
252 | + + '、</span><ul><li class="btn btn-default on" contenteditable="true" onkeyup="NumberCheck(this.innerText,this)">请输入答案</li></ul></div>'); | |
253 | +// for (var j = 0; j < a_num; j++) { | |
254 | +// option = String.fromCharCode(0x41 + j); | |
255 | +// $( | |
256 | +// ".section-" + answer_index_b + " .question" | |
257 | +// + questionNUm + ' ul').append( | |
258 | +// '<li class="btn btn-default">' + option + '</li>'); | |
259 | +// } | |
260 | + } | |
261 | + total_score += ((index_e_2 - index_s_2 + 1) * fraction2); | |
262 | + $("#score_all").text(total_score); | |
263 | + break; | |
230 | 264 | } |
231 | 265 | // $(".section-"+answer_index_b).attr("data-score",$(".section-"+answer_index_b).find(".question").length*fraction2); |
232 | 266 | $(".section0").attr("data-score", |
... | ... | @@ -375,7 +409,7 @@ $(function() { |
375 | 409 | .eq(k).text(); |
376 | 410 | // console.log(answer); |
377 | 411 | } |
378 | - if (answer == '') { | |
412 | + if (answer == ''||answer.indexOf("请输入答案")>=0) { | |
379 | 413 | alert("还有试题未编辑答案。"); |
380 | 414 | return; |
381 | 415 | } |
... | ... | @@ -736,8 +770,10 @@ function keydown2(e){ |
736 | 770 | } |
737 | 771 | } |
738 | 772 | |
739 | -function NumberCheck(num) { | |
773 | +function NumberCheck(num,obj) { | |
740 | 774 | var str = num; |
775 | + //callback(str,obj) | |
776 | + console.log("num:"+num) | |
741 | 777 | var len1 = str.substr(0, 1); |
742 | 778 | var len2 = str.substr(1, 1); |
743 | 779 | //如果第一位是0,第二位不是点,就用数字把点替换掉 |
... | ... | @@ -756,8 +792,20 @@ function NumberCheck(num) { |
756 | 792 | } |
757 | 793 | } |
758 | 794 | //正则替换,保留数字和小数点 |
759 | - str = str.replace(/[^\d^\.]+/g,'') | |
760 | - //如果需要保留小数点后两位,则用下面公式 | |
761 | - //str = str.replace(/\.\d\d$/,'') | |
762 | - return str; | |
795 | + str = str.replace(/[^\-?\d.]/g,'') | |
796 | + | |
797 | + obj.innerText=str | |
798 | + | |
799 | + callback(str,obj) | |
800 | +} | |
801 | +function callback(tp,obj) { | |
802 | + var _div = obj//document.querySelector('.number .on'); | |
803 | + var range = document.createRange(); | |
804 | + | |
805 | + range.selectNodeContents(_div); | |
806 | + range.collapse(false); | |
807 | + | |
808 | + var sel = window.getSelection(); | |
809 | + sel.removeAllRanges(); | |
810 | + sel.addRange(range); | |
763 | 811 | } | ... | ... |