83b5ddeb
孙向锦
模板添加
|
1
|
var questionNUm = 0;
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
2
|
/* 数字转汉字数字 */
|
83b5ddeb
孙向锦
模板添加
|
3
4
5
6
7
8
9
10
|
var chnNumChar = [ "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" ];
var chnUnitSection = [ "", "万", "亿", "万亿", "亿亿" ];
var chnUnitChar = [ "", "十", "百", "千" ];
/* 快速创建答案列表 */
var score = 0;
var total_score = 0;
var answerLen = 0;
|
83b5ddeb
孙向锦
模板添加
|
11
|
$(function() {
|
83b5ddeb
孙向锦
模板添加
|
12
13
14
15
16
17
18
19
20
21
22
23
|
function creat(str_ans, a_num, fraction) {
// $(".section").remove();
answer_index_b = $(".section").length + 1;
/*
* $(".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>')
*/
var str = str_ans.split('');
|
5d2c2033
孙向锦
自定义出题
|
24
|
console.log(str);
|
83b5ddeb
孙向锦
模板添加
|
25
26
27
28
|
for (i = 0; i < str.length; i++) {
if (str[i] == " ") {
str.splice(i, 1);
i = i - 1;
|
5d2c2033
孙向锦
自定义出题
|
29
30
|
}
}
|
83b5ddeb
孙向锦
模板添加
|
31
|
q_num = str.length;
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
$(".content")
.append(
'<div class="section section-'
+ answer_index_b
+ ' single" data-fraction="'
+ fraction
+ '" data-score="'
+ (q_num * fraction)
+ '" style="margin-top:80px;"><div class="title"><h3>第'
+ answer_index_b
+ '大题(单选)总分: '
+ q_num
+ ' X '
+ fraction
+ ' = '
+ (q_num * fraction)
|
83b5ddeb
孙向锦
模板添加
|
48
49
50
51
52
53
|
+ ' 分<!--<span>请在试题选项上点击,亮色为该试题的正确答案 </span> --></h3> </div><div class="question_list"></div></div>');
for (var i = 0; i < q_num; i++) {
str_temp = str[i];
str_temp = str_temp.toUpperCase()
code = str_temp.charCodeAt();
on_index = code - 65;
|
10146a46
孙向锦
创建试卷
|
54
|
questionNUm++;
|
83b5ddeb
孙向锦
模板添加
|
55
|
if (code < (65 + a_num)) {
|
5d2c2033
孙向锦
自定义出题
|
56
|
console.log(str_temp);
|
83b5ddeb
孙向锦
模板添加
|
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
$(".section-" + answer_index_b + " .question_list").append(
'<div class="question question' + (questionNUm)
+ '"><span>' + (questionNUm)
+ '、</span><ul></ul></div>');
for (var j = 0; j < a_num; j++) {
option = String.fromCharCode(0x41 + j);
if (on_index == j) {
console.log(on_index + "---" + j);
$(".question" + (questionNUm) + ' ul').append(
'<li class="btn btn-default on">' + option
+ '</li>');
} else
$(".question" + (questionNUm) + ' ul').append(
'<li class="btn btn-default">' + option
+ '</li>');
}
} else {
alert("题目" + (i + 1) + ":" + String.fromCharCode(code)
+ "答案错误,超出选项数");
// return;
|
5d2c2033
孙向锦
自定义出题
|
77
78
|
}
}
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
79
|
$(".section-" + answer_index_b).attr("data-score", q_num * fraction);
|
10146a46
孙向锦
创建试卷
|
80
81
|
total_score += q_num * fraction;
$("#score_all").text(total_score);
|
5d2c2033
孙向锦
自定义出题
|
82
83
|
}
|
83b5ddeb
孙向锦
模板添加
|
84
|
/***************************************************************************
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
85
|
* 1、单选题 2、完形填空 3、阅读理解 4、判断题 5、多选题 6、数字题
|
83b5ddeb
孙向锦
模板添加
|
86
|
**************************************************************************/
|
5d2c2033
孙向锦
自定义出题
|
87
|
|
83b5ddeb
孙向锦
模板添加
|
88
|
function addQuestion(type, a_num, index_s_2, index_e_2, fraction2) {
|
5d2c2033
孙向锦
自定义出题
|
89
|
console.log(type);
|
83b5ddeb
孙向锦
模板添加
|
90
91
92
93
94
95
96
97
98
|
answer_index_b = $(".section").length + 1;
var question_num = SectionToChinese($(".section").length + 1);
switch (type) {
case 1: // 单选题
// alert(typeof(index_s_2));
$(".content")
.append(
'<div class="section section-'
+ answer_index_b
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
99
|
+ ' single" data-type="1" data-fraction="'
|
83b5ddeb
孙向锦
模板添加
|
100
|
+ fraction2
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
101
102
103
|
+ '" data-score="'
+ ((index_e_2 - index_s_2 + 1) * fraction2)
+ '"> <div class="title"> <h3><span class="que_num">'
|
83b5ddeb
孙向锦
模板添加
|
104
105
106
107
108
109
110
111
112
113
114
115
116
|
+ question_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>');
for (i = index_s_2; i <= index_e_2; i++) {
$(".section-" + answer_index_b + " .question_list").append(
'<div class="question question' + i + '"><span>' + i
+ '、</span><ul></ul></div>');
for (var j = 0; j < a_num; j++) {
option = String.fromCharCode(0x41 + j);
$(".section-" + answer_index_b + " .question" + i + ' ul')
.append(
'<li class="btn btn-default">' + option
+ '</li>');
|
5d2c2033
孙向锦
自定义出题
|
117
|
}
|
83b5ddeb
孙向锦
模板添加
|
118
|
}
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
119
120
|
total_score += ((index_e_2 - index_s_2 + 1) * fraction2);
$("#score_all").text(total_score);
|
5d2c2033
孙向锦
自定义出题
|
121
|
break;
|
83b5ddeb
孙向锦
模板添加
|
122
123
124
125
126
|
case 2: // 完形填空
$(".content")
.append(
'<div class="section section-'
+ answer_index_b
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
127
|
+ ' single" data-type="2" data-fraction="'
|
83b5ddeb
孙向锦
模板添加
|
128
|
+ fraction2
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
129
130
131
|
+ '" data-score="'
+ ((index_e_2 - index_s_2 + 1) * fraction2)
+ '"> <div class="title"> <h3><span class="que_num">'
|
83b5ddeb
孙向锦
模板添加
|
132
133
134
135
136
137
138
139
140
141
142
143
|
+ question_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>');
for (var i = index_s_2; i <= index_e_2; i++) {
$(".section-" + answer_index_b + " .question_list").append(
'<div class="question question' + i + '"><span>' + i
+ '、</span><ul></ul></div>');
for (var j = 0; j < a_num; j++) {
option = String.fromCharCode(0x41 + j);
$(".section-" + answer_index_b + " .question" + i + ' ul')
.append(
'<li class="btn btn-default">' + option
+ '</li>');
|
5d2c2033
孙向锦
自定义出题
|
144
|
}
|
83b5ddeb
孙向锦
模板添加
|
145
|
}
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
146
147
|
total_score += ((index_e_2 - index_s_2 + 1) * fraction2);
$("#score_all").text(total_score);
|
5d2c2033
孙向锦
自定义出题
|
148
|
break;
|
83b5ddeb
孙向锦
模板添加
|
149
150
151
152
153
|
case 3: // 阅读理解
$(".content")
.append(
'<div class="section section-'
+ answer_index_b
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
154
|
+ ' single" data-type="3" data-fraction="'
|
83b5ddeb
孙向锦
模板添加
|
155
|
+ fraction2
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
156
157
158
|
+ '" data-score="'
+ ((index_e_2 - index_s_2 + 1) * fraction2)
+ '"> <div class="title"> <h3><span class="que_num">'
|
83b5ddeb
孙向锦
模板添加
|
159
160
161
162
163
164
165
166
167
168
169
170
|
+ question_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>');
for (var i = index_s_2; i <= index_e_2; i++) {
$(".section-" + answer_index_b + " .question_list").append(
'<div class="question question' + i + '"><span>' + i
+ '、</span><ul></ul></div>');
for (var j = 0; j < a_num; j++) {
option = String.fromCharCode(0x41 + j);
$(".section-" + answer_index_b + " .question" + i + ' ul')
.append(
'<li class="btn btn-default">' + option
+ '</li>');
|
5d2c2033
孙向锦
自定义出题
|
171
|
}
|
83b5ddeb
孙向锦
模板添加
|
172
|
}
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
173
174
|
total_score += ((index_e_2 - index_s_2 + 1) * fraction2);
$("#score_all").text(total_score);
|
5d2c2033
孙向锦
自定义出题
|
175
|
break;
|
83b5ddeb
孙向锦
模板添加
|
176
177
178
179
180
|
case 4: // 判断题
$(".content")
.append(
'<div class="section section-'
+ answer_index_b
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
181
|
+ ' single" data-type="4" data-fraction="'
|
83b5ddeb
孙向锦
模板添加
|
182
|
+ fraction2
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
183
184
185
|
+ '" data-score="'
+ ((index_e_2 - index_s_2 + 1) * fraction2)
+ '"> <div class="title"> <h3><span class="que_num">'
|
83b5ddeb
孙向锦
模板添加
|
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
+ question_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>');
for (var i = index_s_2; i <= index_e_2; i++) {
$(".section-" + answer_index_b + " .question_list").append(
'<div class="question question' + i + '"><span>' + i
+ '、</span><ul></ul></div>');
for (var j = 0; j < a_num; j++) {
if (j % 2 == 0)
option = "√";
else
option = "×";
$(".section-" + answer_index_b + " .question" + i + ' ul')
.append(
'<li class="btn btn-default">' + option
+ '</li>');
|
5d2c2033
孙向锦
自定义出题
|
201
|
}
|
83b5ddeb
孙向锦
模板添加
|
202
|
}
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
203
204
|
total_score += ((index_e_2 - index_s_2 + 1) * fraction2);
$("#score_all").text(total_score);
|
5d2c2033
孙向锦
自定义出题
|
205
|
break;
|
83b5ddeb
孙向锦
模板添加
|
206
207
208
209
210
211
212
213
214
215
216
217
218
|
/*
* case 5: //多选题 $(".content").append('<div class="section
* section-'+answer_index_b+' check" data-fraction="'+fraction2+'"
* data-score=""> <div class="title"> <h3><span
* class="que_num">'+question_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>');
* for(var i=index_s_2;i<=index_e_2;i++){
* $(".section-"+answer_index_b+" .question_list").append('<div
* class="question question'+i+'"><span>'+i+'、</span><ul></ul></div>');
* for(var j=0;j<a_num;j++){ option=String.fromCharCode(0x41+j);
* $(".section-"+answer_index_b+" .question"+i+' ul').append('<li class="btn btn-default">'+option+'</li>'); } }
*/
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
case 5:
$(".content")
// 多选题
.append(
'<div class="section section-'
+ answer_index_b
+ ' check" data-type="5" data-fraction="'
+ fraction2
+ '" data-score="'
+ ((index_e_2 - index_s_2 + 1) * fraction2)
+ '"> <div class="title"><h3><span class="que_num">'
+ question_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>');
for (var i = index_s_2; i <= index_e_2; i++) {
questionNUm++;
$(".section-" + answer_index_b + " .question_list").append(
'<div class="question question' + i
+ '"><span>' + i
+ '、</span><ul></ul></div>');
for (var j = 0; j < a_num; j++) {
option = String.fromCharCode(0x41 + j);
$(
".section-" + answer_index_b + " .question"
+ questionNUm + ' ul').append(
'<li class="btn btn-default">' + option + '</li>');
}
}
total_score += ((index_e_2 - index_s_2 + 1) * fraction2);
$("#score_all").text(total_score);
break;
case 6: // 数字题
// $(".content").html("");
$(".content")
.append(
'<div class="section section-'
+ answer_index_b
+ ' number" data-type="6" data-fraction="'
+ fraction2
+ '" data-score="'
+ ((index_e_2 - index_s_2 + 1) * fraction2)
+ '"> <div class="title"><h3><span class="que_num">'
+ question_num
+ '、</span><span class="que_name">数字题</span><!--<span>请在试题选项上点击,亮色为该试题的正确答案 </span>--></h3><input type="button" class="btn btn-danger pull-right remove" name="remove" value="删除" /> </div> <div class="question_list"></div></div>');
for (var i = index_s_2; i <= index_e_2; i++) {
questionNUm++;
$(".section-" + answer_index_b + " .question_list")
.append(
'<div class="question question'
+ i
+ '"><span>'
+ i
|
5f403333
jack
1,完善数字题
|
271
|
+ '、</span><ul><li class="btn btn-default on" contenteditable="true" onkeyup="NumberCheck(this.innerText,this)">请输入答案</li></ul></div>');
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
272
273
274
275
276
277
278
279
280
281
282
|
// for (var j = 0; j < a_num; j++) {
// option = String.fromCharCode(0x41 + j);
// $(
// ".section-" + answer_index_b + " .question"
// + questionNUm + ' ul').append(
// '<li class="btn btn-default">' + option + '</li>');
// }
}
total_score += ((index_e_2 - index_s_2 + 1) * fraction2);
$("#score_all").text(total_score);
break;
|
5d2c2033
孙向锦
自定义出题
|
283
|
}
|
83b5ddeb
孙向锦
模板添加
|
284
285
286
|
// $(".section-"+answer_index_b).attr("data-score",$(".section-"+answer_index_b).find(".question").length*fraction2);
$(".section0").attr("data-score",
$(".section0").find(".question").length * fraction2);
|
5d2c2033
孙向锦
自定义出题
|
287
288
|
}
|
83b5ddeb
孙向锦
模板添加
|
289
|
$(document).on('click', '.remove', function() { // 删除按钮
|
5d2c2033
孙向锦
自定义出题
|
290
|
$(this).parent().parent(".section").remove();
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
291
292
293
294
295
296
297
|
for(i=0;i<$(".section").length;i++){
$(".section").eq(i).find(".que_num").text(SectionToChinese(i+1)+'、');
var className = $(".section").attr("class").replace(/\d+/g,i);
console.log(className)
$(".section").attr("class",className);
}
|
5d2c2033
孙向锦
自定义出题
|
298
|
})
|
83b5ddeb
孙向锦
模板添加
|
299
300
|
$("#fast_submit").click(function() { // 点击确定,创建答案列表
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
301
|
// $("#addQuestion").attr("disabled","disabled");
|
83b5ddeb
孙向锦
模板添加
|
302
303
304
305
|
var answer = $("#answer").val();
var num_ans = $("#num_ans").val();
var fraction = $("#fraction").val();
if (answer == '') {
|
ee61a3f0
孙向锦
增强判断
|
306
|
alert("请输入题目答案");
|
5d2c2033
孙向锦
自定义出题
|
307
|
return;
|
83b5ddeb
孙向锦
模板添加
|
308
|
} else if (fraction == '') {
|
5d2c2033
孙向锦
自定义出题
|
309
310
311
|
alert("请输入题目分数");
return;
}
|
10146a46
孙向锦
创建试卷
|
312
|
var frac = parseFloat(fraction);
|
83b5ddeb
孙向锦
模板添加
|
313
314
315
|
if (frac > 0) {
// score += parseInt(fraction)*answer.split(",").length;
creat(answer, num_ans, fraction);
|
67dfaf5c
孙向锦
提交代码
|
316
|
$('.fast').modal('hide');
|
83b5ddeb
孙向锦
模板添加
|
317
|
} else {
|
67dfaf5c
孙向锦
提交代码
|
318
319
320
|
alert("请输入正确分数");
return;
}
|
83b5ddeb
孙向锦
模板添加
|
321
|
})
|
5d2c2033
孙向锦
自定义出题
|
322
|
|
83b5ddeb
孙向锦
模板添加
|
323
324
|
/* 添加试题的确定按钮 */
$("#addQuestion_submit").click(function() {
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
325
326
|
$("#fast").attr("disabled", "disabled");
var type_2 = parseInt($("#type").val());
|
83b5ddeb
孙向锦
模板添加
|
327
328
329
330
331
332
|
var index_s_2 = 1;// parseInt($("#index_s_2").val())
var index_e_2 = parseInt($("#index_s_2").val());
// var answer_2=$("#answer_2").val();
var num_ans_2 = $("#num_ans_2").val();
var fraction2 = parseFloat($("#fraction2").val());
if (isNaN(index_s_2)) {
|
5d2c2033
孙向锦
自定义出题
|
333
334
|
alert("请输入题目开始序号");
return;
|
83b5ddeb
孙向锦
模板添加
|
335
336
|
} else if (isNaN(index_e_2)) {
alert("请输入题目个数");// alert("请输入题目结束序号");
|
5d2c2033
孙向锦
自定义出题
|
337
|
return;
|
83b5ddeb
孙向锦
模板添加
|
338
|
} else if (isNaN(fraction2)) {
|
ee61a3f0
孙向锦
增强判断
|
339
340
|
alert("请输入题目分数");
return;
|
5d2c2033
孙向锦
自定义出题
|
341
|
}
|
67dfaf5c
孙向锦
提交代码
|
342
|
var iindex_e_2 = parseInt(index_e_2);
|
83b5ddeb
孙向锦
模板添加
|
343
|
if (iindex_e_2 < 1 || iindex_e_2 > 100) {
|
67dfaf5c
孙向锦
提交代码
|
344
345
346
|
alert("题目个数不合法");
return;
}
|
83b5ddeb
孙向锦
模板添加
|
347
348
|
// console.log(typeof(type_2));
addQuestion(type_2, num_ans_2, index_s_2, index_e_2, fraction2);
|
5d2c2033
孙向锦
自定义出题
|
349
350
|
$('.addQuestion').modal('hide');
})
|
83b5ddeb
孙向锦
模板添加
|
351
352
|
$("#type").change(function() {
if ($("#type").val() == 4) {
|
5d2c2033
孙向锦
自定义出题
|
353
|
$("#num_ans_2").val(2);
|
83b5ddeb
孙向锦
模板添加
|
354
|
$("#num_ans_2").attr("disabled", "disabled");
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
355
356
357
|
}else if($("#type").val() == 6){
$("#num_ans_2").closest(".form-group").css("display","none");
}else {
|
5d2c2033
孙向锦
自定义出题
|
358
359
|
$("#num_ans_2").removeAttr("disabled");
$("#num_ans_2").val(4);
|
83b5ddeb
孙向锦
模板添加
|
360
|
|
5d2c2033
孙向锦
自定义出题
|
361
362
|
}
})
|
83b5ddeb
孙向锦
模板添加
|
363
364
365
366
|
/* 更改考试时长 */
$("#time_submit").click(function() {
var test_time = $("#enter_time").val();
if (test_time == '') {
|
5d2c2033
孙向锦
自定义出题
|
367
368
369
370
371
372
|
alert("请输入考试时间");
return;
}
$("#time").html(test_time);
$('.test_time').modal('hide');
})
|
83b5ddeb
孙向锦
模板添加
|
373
374
|
/* 更改单选答案 */
$(document).on('click', '.single li', function() {
|
5d2c2033
孙向锦
自定义出题
|
375
376
377
|
$(this).siblings().removeClass("on");
$(this).addClass("on");
})
|
83b5ddeb
孙向锦
模板添加
|
378
379
380
381
|
/* 更改多选答案 */
$(document).on('click', '.check li', function() {
// $(this).siblings().removeClass("on");
if ($(this).hasClass('on')) {
|
67dfaf5c
孙向锦
提交代码
|
382
|
$(this).removeClass("on");
|
83b5ddeb
孙向锦
模板添加
|
383
|
} else {
|
67dfaf5c
孙向锦
提交代码
|
384
385
|
$(this).addClass("on");
}
|
5d2c2033
孙向锦
自定义出题
|
386
|
})
|
83b5ddeb
孙向锦
模板添加
|
387
|
/* 提交保存数据 */
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
388
389
390
|
$("#save")
.click(
function() {
|
83b5ddeb
孙向锦
模板添加
|
391
|
var url = URL;
|
5d2c2033
孙向锦
自定义出题
|
392
|
|
83b5ddeb
孙向锦
模板添加
|
393
394
395
396
397
398
399
400
401
402
403
|
var data = {
title : $(".header_box h1").text(),
exam_time : parseInt($("#time").text()),
paper_type : testData.paper_type,
subject_id : testData.subject_id,
grade_id : testData.grade_id,
user_id : testData.user_id,
school_id : testData.school_id,
score : total_score,
questions : []
}
|
5d2c2033
孙向锦
自定义出题
|
404
|
|
83b5ddeb
孙向锦
模板添加
|
405
406
407
408
409
410
|
if ($(".section").length > 0) {
var rank = 0
for (i = 0; i < $(".section").length; i++) {
// rank++;
data.questions[i] = {
chapter_id : "0",
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
411
|
problem_type_id : $(".section").eq(i).attr("data-type"),
|
83b5ddeb
孙向锦
模板添加
|
412
413
414
415
416
417
418
419
420
421
422
423
424
425
|
knowledge_id : "0",
// content:
// $(".section").eq(i).find(".que_name").text(),
option_num : "",
option_content : "",
answer : "",
difficulty : "",
analysis : "",
question_from : "",
score : parseFloat($(".section").eq(i)
.attr("data-score")),
part_score : "",
remark : "",
rank : rank,
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
426
|
no_name : "",//$(".section").eq(i).find(".que_num").text(),
|
83b5ddeb
孙向锦
模板添加
|
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
questions : []
}
for (j = 0; j < $(".section").eq(i).find(
".question_list").children(".question").length; j++) {
rank++;
var on_num = $(".section").eq(i).find(
".question").eq(j).find(".on").length;
var answer = "";
for (k = 0; k < on_num; k++) {
answer += $(".section").eq(i).find(
".question").eq(j).find(".on")
.eq(k).text();
// console.log(answer);
}
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
441
442
|
if (answer == ''
|| answer.indexOf("请输入答案") >= 0) {
|
83b5ddeb
孙向锦
模板添加
|
443
444
445
446
447
|
alert("还有试题未编辑答案。");
return;
}
data.questions[i].questions[j] = {
chapter_id : "0",
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
448
|
problem_type_id : $(".section").eq(i).attr("data-type"),//"0",//data-type="1"
|
83b5ddeb
孙向锦
模板添加
|
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
|
knowledge_id : "0",
content : "",
option_num : $(".section").eq(i).find(
".question").eq(j).find("li").length,
option_content : "",
answer : answer,
difficulty : "0",
analysis : "",
question_from : "1",
score : parseFloat($(".section").eq(i)
.attr("data-fraction")),
part_score : "0",
remark : "",
rank : rank,
no_name : rank,
}
}
}
}
if (data.questions.length > 0) {
data = JSON.stringify(data);
dataJson = {
"json" : data
};
console.log(data);
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
475
|
ajax_submit(url, dataJson);
|
83b5ddeb
孙向锦
模板添加
|
476
477
478
|
} else
alert("请添加试题");
});
|
5d2c2033
孙向锦
自定义出题
|
479
|
|
83b5ddeb
孙向锦
模板添加
|
480
481
482
483
484
485
486
487
488
489
490
491
|
/* ajax封装函数 */
function ajax_submit(url, data) {
$(".loading").css("display", "block");
console.log(data);
$.ajax({
url : url,
type : "POST",
data : data,
dataType : "json",
contentType : "application/x-www-form-urlencoded; charset=utf-8",
success : function(data) {
$(".loading").css("display", "none");
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
492
493
494
495
496
497
498
|
if (testData.paper_type == '1') {
window.location.href = JUMP_URL
+ "?a=1&defaulturl=../paper/list2.do";
} else {
window.location.href = JUMP_URL
+ "?a=1&defaulturl=../paper/list5.do?school_id="
+ testData.school_id;
|
4b347a15
孙向锦
修改编辑试题后,添加的返回路径
|
499
|
}
|
83b5ddeb
孙向锦
模板添加
|
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
|
}
})
}
function fastSort(array, head, tail) {
// 考虑到给每个分区操作的时候都是在原有的数组中进行操作的,所以这里head,tail来确定分片的位置
/* 生成随机项 */
var randomnum = parseInt((head + tail) / 2);
var random = array[randomnum];
/* 将小于random的项放置在其左边 策略就是通过一个临时的数组来储存分好区的结果,再到原数组中替换 */
var arrayTemp = [];
var unshiftHead = 0;
for (var i = head; i <= tail; i++) {
if (parseInt(array[i].rank) < parseInt(random.rank)) {
arrayTemp.unshift(array[i]);
unshiftHead++;
} else if (parseInt(array[i].rank) > parseInt(random.rank)) {
arrayTemp.push(array[i]);
}
/* 当它等于的时候放哪,这里我想选择放到队列的前面,也就是从unshift后的第一个位置放置 */
if (parseInt(array[i].rank) === parseInt(random.rank)) {
arrayTemp.splice(unshiftHead, 0, array[i]);
}
|
5d2c2033
孙向锦
自定义出题
|
522
|
}
|
83b5ddeb
孙向锦
模板添加
|
523
524
525
526
527
528
|
/* 将对应项覆盖原来的记录 */
for (var j = head, u = 0; j <= tail; j++, u++) {
array.splice(j, 1, arrayTemp[u]);
}
/* 寻找中间项所在的index */
var nowIndex = array.indexOf(random);
|
5d2c2033
孙向锦
自定义出题
|
529
|
|
83b5ddeb
孙向锦
模板添加
|
530
531
532
|
/* 设置出口,当要放进去的片段只有2项的时候就可以收工了 */
if (arrayTemp.length <= 2) {
return;
|
5d2c2033
孙向锦
自定义出题
|
533
|
}
|
83b5ddeb
孙向锦
模板添加
|
534
535
536
|
/* 递归,同时应用其左右两个区域 */
fastSort(array, head, nowIndex);
fastSort(array, nowIndex + 1, tail);
|
5d2c2033
孙向锦
自定义出题
|
537
|
}
|
83b5ddeb
孙向锦
模板添加
|
538
|
function creatHtml(data) {
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
539
540
541
542
543
544
545
546
547
548
549
|
data.questions.sort(function(a, b) {
// if (a.rank < b.rank) {
// return -1;
// } else if (a.rank == b.rank) {
// return 0;
// } else {
// return 1;
// }
var rankA = isNaN(parseInt(a.rank)) ? 0 : parseInt(a.rank);
var rankB = isNaN(parseInt(b.rank)) ? 0 : parseInt(b.rank);
return rankA - rankB;
|
96cc2079
jack
1.轻松考-增加题目根据rank字...
|
550
|
})
|
5d2c2033
孙向锦
自定义出题
|
551
|
console.log(data);
|
83b5ddeb
孙向锦
模板添加
|
552
|
$(".header_box h1").html(data.title);
|
5d2c2033
孙向锦
自定义出题
|
553
|
$("#time").html(data.exam_time);
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
554
|
if (data.score != null && data.score > 0 && data.score != '') {
|
83b5ddeb
孙向锦
模板添加
|
555
556
557
558
|
$("#score_all").html(data.score);
}
if (data.questions.length > 0) {
|
0b46638a
孙向锦
标准答案
|
559
560
561
562
|
$(".time").removeAttr("data-target");
$(".remove").remove();
$(".btn_box").remove();
}
|
83b5ddeb
孙向锦
模板添加
|
563
564
565
|
for (var i = 0; i < data.questions.length; i++) {
if (data.questions[i].questions) {
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
566
567
568
569
570
571
572
573
574
575
576
|
var sortTemp = data.questions[i].questions.sort(function(a, b) {
// if (parseInt(a.rank) < parseInt(b.rank)) {
// return -1;
// } else if (a.rank == b.rank) {
// return 0;
// } else {
// return 1;
// }
var rankA = isNaN(parseInt(a.rank)) ? 0 : parseInt(a.rank);
var rankB = isNaN(parseInt(b.rank)) ? 0 : parseInt(b.rank);
return rankA - rankB;
|
96cc2079
jack
1.轻松考-增加题目根据rank字...
|
577
578
|
})
console.log(sortTemp)
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
579
580
581
582
583
584
585
|
var tixing = "";
switch(data.questions[i].problem_type_id){
case '1':tixing="单选题";break;
case '5':tixing="多选题";break;
case '4':tixing="判断题";break;
case '6':tixing="数字题";break;
}
|
83b5ddeb
孙向锦
模板添加
|
586
587
588
589
|
$(".content")
.append(
'<div class="section section-'
+ i
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
590
|
+ '" data-type="'+data.questions[i].problem_type_id+'" data-fraction="'
|
83b5ddeb
孙向锦
模板添加
|
591
|
+ data.questions[i].score
|
ffa525ff
孙向锦
修改出卷页面
|
592
|
+ '" style="margin-top:80px;"> <h3><span class="que_num">'
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
593
594
595
|
+SectionToChinese(i+1)+'、'
+ tixing
+ '(总分:'
|
83b5ddeb
孙向锦
模板添加
|
596
597
598
599
600
|
+ data.questions[i].questions.length
+ " X "
+ (parseFloat(data.questions[i].sug_score) / data.questions[i].questions.length)
+ " = "
+ data.questions[i].sug_score
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
601
|
+ '分)</span>'
|
83b5ddeb
孙向锦
模板添加
|
602
603
604
605
606
607
608
|
+ '<span class="que_name">'
+ data.questions[i].content
+ '</span></h3><!-- <input type="button" class="btn btn-danger pull-right remove" name="remove" value="删除" /> --> <div class="question_list"></div></div>');
} else {
if (i == 0) {
$(".content")
.append(
|
ffa525ff
孙向锦
修改出卷页面
|
609
|
'<div class="section section0"> <div class="question_list" style="margin-top:80px"></div></div>');
|
0b46638a
孙向锦
标准答案
|
610
|
}
|
83b5ddeb
孙向锦
模板添加
|
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
|
$(".section0").find(".question_list").append(
'<div class="question question' + (i + 1) + '"><span>'
+ (++questionNUm) + '、</span><ul></ul></div>');
for (var k = 0; k < parseInt(data.questions[i].option_num); k++) {
str_temp = data.questions[i].answer;
$(".section0").find(".question" + (i + 1) + ' ul').append(
'<li class="btn btn-default">'
+ String.fromCharCode(0x41 + k) + '</li>');
for (var l = 0; l < str_temp.length; l++) {
str_temp_arry = str_temp.split('');
code = str_temp_arry[l].charCodeAt();
on_index = code - 65;
if (on_index == k) {
$(".section0").find(
".question" + (i + 1) + ' ul li').eq(
on_index).attr("class",
"btn btn-default on");
}
|
0b46638a
孙向锦
标准答案
|
629
630
|
}
}
|
5d2c2033
孙向锦
自定义出题
|
631
|
}
|
83b5ddeb
孙向锦
模板添加
|
632
633
634
635
636
637
638
|
if (data.questions[i].questions) {
for (var j = 0; j < data.questions[i].questions.length; j++) {
$(".section-" + i).find(".question_list").append(
'<div class="question question' + (j + 1)
+ '"><span>' + (++questionNUm)
+ '、</span><ul></ul></div>');
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
639
|
if ($(".section-" + i).attr("data-type") == "4") {
|
83b5ddeb
孙向锦
模板添加
|
640
641
642
643
644
645
646
647
648
649
|
for (var k = 0; k < parseInt(data.questions[i].questions[j].option_num); k++) {
str_temp = data.questions[i].questions[j].answer;
if (k % 2 == 0) {
$(".section-" + i).find(
".question" + (j + 1) + ' ul').append(
'<li class="btn btn-default">√</li>');
} else if (k % 2 == 1) {
$(".section-" + i).find(
".question" + (j + 1) + ' ul').append(
'<li class="btn btn-default">×</li>');
|
0b46638a
孙向锦
标准答案
|
650
|
}
|
83b5ddeb
孙向锦
模板添加
|
651
652
653
654
655
|
if (str_temp == "√")
$(".section-" + i).find(
".question" + (j + 1) + ' ul li').eq(0)
.attr("class", "btn btn-default on");
|
0b46638a
孙向锦
标准答案
|
656
|
else
|
83b5ddeb
孙向锦
模板添加
|
657
658
659
|
$(".section-" + i).find(
".question" + (j + 1) + ' ul li').eq(1)
.attr("class", "btn btn-default on");
|
5d2c2033
孙向锦
自定义出题
|
660
|
}
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
661
662
663
664
665
666
667
|
}else if($(".section-" + i).attr("data-type") == "6"){
str_temp = data.questions[i].questions[j].answer;
$(".section-" + i).find(
".question" + (j + 1) + ' ul').append(
'<li class="btn btn-default on">'+str_temp+'</li>');
if(!$(".section-" + i).hasClass("number"))
$(".section-" + i).addClass("number");
|
83b5ddeb
孙向锦
模板添加
|
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
|
} else {
for (var k = 0; k < parseInt(data.questions[i].questions[j].option_num); k++) {
str_temp = data.questions[i].questions[j].answer;
$(".section-" + i).find(
".question" + (j + 1) + ' ul').append(
'<li class="btn btn-default">'
+ String.fromCharCode(0x41 + k)
+ '</li>');
for (var l = 0; l < str_temp.length; l++) {
str_temp_arry = str_temp.split('');
code = str_temp_arry[l].charCodeAt();
on_index = code - 65;
if (on_index == k) {
$(".section-" + i).find(
".question" + (j + 1) + ' ul li')
.eq(on_index).attr("class",
"btn btn-default on");
}
|
0b46638a
孙向锦
标准答案
|
686
|
}
|
5d2c2033
孙向锦
自定义出题
|
687
688
689
690
691
692
|
}
}
}
}
}
}
|
7242423d
孙向锦
添加固件管理
|
693
|
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
694
|
/* 快速建题中,每输入五个答案就加一个空格 */
|
83b5ddeb
孙向锦
模板添加
|
695
696
697
698
699
700
701
702
703
704
705
|
$("#answer").on("input propertychange", function(event) {
var answerStr = "";
answerStr = $("#answer").val();
var result = "";
if (answerStr.length > 5) {
answerStr = answerStr.replace(new RegExp(" ", "gm"), "");
for (var i = 0; i < answerStr.length; i++) {
result += answerStr[i];
if (i % 5 == 4 && i != answerStr.length - 1) {
result += " ";
}
|
0b46638a
孙向锦
标准答案
|
706
|
}
|
83b5ddeb
孙向锦
模板添加
|
707
708
|
} else {
result = answerStr;
|
7242423d
孙向锦
添加固件管理
|
709
|
}
|
83b5ddeb
孙向锦
模板添加
|
710
711
712
713
714
715
716
|
$("#answer").val(result);
if (answerStr.length > 0) {
$(".tips").text("共" + answerStr.length + "题");
} else {
$(".tips").text("");
}
})
|
5d2c2033
孙向锦
自定义出题
|
717
|
|
83b5ddeb
孙向锦
模板添加
|
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
|
function SectionToChinese(section) {
var strIns = '', chnStr = '';
var unitPos = 0;
var zero = true;
while (section > 0) {
var v = section % 10;
if (v === 0) {
if (!zero) {
zero = true;
chnStr = chnNumChar[v] + chnStr;
}
} else {
zero = false;
strIns = chnNumChar[v];
strIns += chnUnitChar[unitPos];
chnStr = strIns + chnStr;
}
unitPos++;
section = Math.floor(section / 10);
}
return chnStr;
}
|
5d2c2033
孙向锦
自定义出题
|
740
|
|
83b5ddeb
孙向锦
模板添加
|
741
|
if (template != null && template.length > 0) {
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
742
743
744
745
746
747
748
749
|
$("#addQuestion").attr("disabled", "disabled");
$("#fast").attr("disabled", "disabled");
for (var i = 0; i < template.length; i++) {
if (template[i].type == 1) {
var answer = "";
for (var j = 0; j < template[i].questionNum; j++) {
answer += "1";
|
83b5ddeb
孙向锦
模板添加
|
750
|
}
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
751
|
creat(answer, template[i].optionNum, template[i].score);
|
83b5ddeb
孙向锦
模板添加
|
752
|
}
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
753
754
755
|
if (template[i].type == 2) {
addQuestion(5, template[i].optionNum, 1,
template[i].questionNum, template[i].score);
|
eef2f078
孙向锦
修改域名问题
|
756
|
}
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
757
758
759
760
761
762
763
764
765
766
767
|
}
if (testData != null) {
$(".header_box h1").html(testData.title);
$("#time").html(testData.exam_time);
if (testData.score != null && testData.score > 0
&& testData.score != '') {
$("#score_all").html(testData.score);
}
}
} else if (testData != null && testData.questions != null
|
83b5ddeb
孙向锦
模板添加
|
768
769
770
|
&& testData.questions.length > 0) {
fastSort(testData.questions, 0, testData.questions.length - 1);
for (var i = 0; i < testData.questions.length; i++) {
|
5d2c2033
孙向锦
自定义出题
|
771
|
|
83b5ddeb
孙向锦
模板添加
|
772
773
774
775
776
777
778
|
if (testData.questions[0].questions
&& testData.questions[0].questions.length > 1) {
fastSort(testData.questions[i].questions, 0,
testData.questions[i].questions.length - 1);
}
}
creatHtml(testData);
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
779
780
|
} else {
if (testData != null) {
|
ffa525ff
孙向锦
修改出卷页面
|
781
782
|
$(".header_box h1").html(testData.title);
$("#time").html(testData.exam_time);
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
783
784
|
if (testData.score != null && testData.score > 0
&& testData.score != '') {
|
ffa525ff
孙向锦
修改出卷页面
|
785
786
787
|
$("#score_all").html(testData.score);
}
}
|
83b5ddeb
孙向锦
模板添加
|
788
|
}
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
789
790
791
|
$(".content").on("focus", ".number .on", function() {
if ($(this).text() == "请输入答案")
|
803a7d44
jack
1.增加数字题
|
792
|
$(this).text("");
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
793
|
|
803a7d44
jack
1.增加数字题
|
794
|
})
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
795
796
|
$(".content").on("blur", ".number .on", function() {
if ($(this).text() == "") {
|
803a7d44
jack
1.增加数字题
|
797
798
|
$(this).text("请输入答案");
}
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
799
|
|
803a7d44
jack
1.增加数字题
|
800
|
})
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
801
|
|
83b5ddeb
孙向锦
模板添加
|
802
|
})
|
803a7d44
jack
1.增加数字题
|
803
804
805
|
/**
* 数字校验
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
806
|
*
|
803a7d44
jack
1.增加数字题
|
807
808
|
* @param e
*/
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
|
function keydown2(e) {
var reg = /^[0-9]*$/;
console.log(reg.test(e.text()));
console.log(e.text())
if (!reg.test(e.text())) {
e.text("");
}
}
function NumberCheck(num, obj) {
var str = num;
// callback(str,obj)
console.log("num:" + num)
var len1 = str.substr(0, 1);
var len2 = str.substr(1, 1);
// 如果第一位是0,第二位不是点,就用数字把点替换掉
if (str.length > 1 && len1 == 0 && len2 != ".") {
str = str.substr(1, 1);
}
// 第一位不能是.
if (len1 == ".") {
str = "";
}
// 限制只能输入一个小数点
if (str.indexOf(".") != -1) {
var str_ = str.substr(str.indexOf(".") + 1);
if (str_.indexOf(".") != -1) {
str = str.substr(0, str.indexOf(".") + str_.indexOf(".") + 1);
|
803a7d44
jack
1.增加数字题
|
837
838
|
}
}
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
839
840
841
842
|
// 正则替换,保留数字和小数点
str = str.replace(/[^\-?\d.]/g, '')
obj.innerText = str
|
803a7d44
jack
1.增加数字题
|
843
|
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
844
|
callback(str, obj)
|
5f403333
jack
1,完善数字题
|
845
|
}
|
32d27bdc
jack
1.增加判断题和数字题,调试更改上传数据
|
846
847
|
function callback(tp, obj) {
var _div = obj// document.querySelector('.number .on');
|
5f403333
jack
1,完善数字题
|
848
849
850
851
852
853
854
855
|
var range = document.createRange();
range.selectNodeContents(_div);
range.collapse(false);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
|
803a7d44
jack
1.增加数字题
|
856
|
}
|