-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.html
613 lines (551 loc) · 17.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
body,h2 { margin:0;}
body,input,select { font-size:14px;font-family:"宋体",tahoma,arial;}
h2 { width:750px;height:50px;margin:0 0;color:red;border:1px solid gray;}
h2 span { width:374px;height:50px;line-height:50px;text-align:center;float:left;}
ul li.colmode { float:left; width:200px; font-size:14px; margin:0 0; padding: 0; height: 20px; list-style-type: none;}
ul li { float:left; width:150px; font-size:14px; margin:0 0; padding: 0; height: 20px; list-style-type: none;}
#tab .tab { color:yellow;background-color:#999;}
#ct div { width:750px;height:120px;margin:0 0;border:1px solid blue;display:none;}
#ct .ct { display:block; float:center;}
#act div { width:750px;height:30px;margin:0 0;border:1px solid blue;display:none;}
#act .act { display:block; float:center;}
table { table-layout:fixed; empty-cells:show; margin:auto auto; page-break-after:always;}
td { height:80px; width:150px;text-align:"left";align:"left";font-size:24px;font-family:"宋体", arial;}
@media print {
@page print_section {
size: 210mm 297mm;
margin: 10mm 10mm 5mm 5mm;
}
div.print_section {
page:print_section;
}
}
</style>
</head>
<body>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jQuery.print.js"></script>
<script type="text/javascript" src="js/jquery.base64.js"></script>
<script type="text/javascript" src="js/libs/FileSaver/FileSaver.min.js"></script>
<!---
<script type="text/javascript" src="js/libs/jsPDF/jspdf.min.js"></script>
<script type="text/javascript" src="js/libs/jsPDF-AutoTable/jspdf.plugin.autotable.js"></script>
<script type="text/javascript" src="js/pdfmake/pdfmake.js"></script>
<script type="text/javascript" src="js/pdfmake/vfs_fonts.js"></script>
---!>
<script type="text/javascript" src="js/tableExport.js"></script>
<script type="text/javascript">
/* Generate integer that in [m,n], if m > n return 0 */
function rand(m,n)
{
if (m > n)
return 0;
else
return Math.round(Math.random() * (n - m) + m);
}
var modes = [
["add_1_1", "一位数加一位数"],
["addc_2_2", "两位数进位加法"],
["add_2_2", "两位数不进位加"],
["subc_2_2", "两位数退位减法"],
["sub_2_2", "两位数不退位减"],
["add_1_2", "一位数加两位数"],
["add_2_1", "两位数加一位数"],
["sub_2_1", "两位数减一位数"],
["mul_1_1", "一位数乘一位数"],
["addmul_2_1_1", "两位数加一位数乘"],
["muladd_1_1_2", "一位数乘加两位数"],
["mulsub_1_1_2", "一位数乘减两位数"],
["submul_2_1_1", "两位数减一位数乘"],
["sub9", "减数个位为9"],
["sub012", "减数个位为012"],
["add012", "加数个位为012"],
["addn_2_2", "特殊非进位加"],
["wrong", "历史错题"],
];
var wrong_issues = [
[1,46,'-',31,15],
[1,43,'+',40,83],
[1,27,'+',30,57],
[1,49,'+',30,79],
[1,56,'-',21,35],
[1,97,'-',59,38],
[2,6,'x',5,'-',29,1],
[1,76,'-',59,17],
[2,8,'x',6,'-',12,36],
[2,45,'+',2,'x',6,57],
[2,42,'+',2,'x',3,48],
[1,63,'+',10,73],
[1,62,'+',16,78]
];
var current_wrong = 0;
/* randomly generate one issue of give type */
function generate_issue(type)
{
var i, j;
var issue = new Object();
// default 1 operator
issue.op_n = 1;
issue.op = new Array();
issue.opr = new Array();
switch (type) {
case 'add_1_1':
i = rand(1,9);
j = rand(1,9);
issue.opr[0] = i;
issue.op[0] = '+';
issue.opr[1] = j;
issue.result = issue.opr[0] + issue.opr[1];
break;
case 'addc_2_2':
i = rand(1,7);
j = rand(1,9);
issue.opr[0] = i * 10 + j;
issue.op[0] = '+';
issue.opr[1] = rand(1,8 - i) * 10 + rand(10 - j, 9);
issue.result = issue.opr[0] + issue.opr[1];
break;
case 'add_2_2':
i = rand(1,8);
j = rand(0,9);
issue.opr[0] = i * 10 + j;
issue.op[0] = '+';
issue.opr[1] = rand(1, 9 - i) * 10 + rand(0, 9-j);
issue.result = issue.opr[0] + issue.opr[1];
break;
case 'subc_2_2':
i = rand(2,9);
j = rand(0,8);
issue.opr[0] = i * 10 + j;
issue.op[0] = '-';
issue.opr[1] = rand(1, i - 1) * 10 + rand(j+1, 9);
issue.result = issue.opr[0] - issue.opr[1];
break;
case 'sub_2_2':
i = rand(1,9);
j = rand(0,9);
issue.opr[0] = i * 10 + j;
issue.op[0] = '-';
issue.opr[1] = rand(1,i) * 10 + rand(0,j);
issue.result = issue.opr[0] - issue.opr[1];
break;
case 'add_2_1':
i = rand(1,9);
j = rand(0,9);
issue.opr[0] = i * 10 + j;
issue.op[0] = '+';
issue.opr[1] = (i < 9) ? rand(0,9) : rand(0, 9 - j);
issue.result = issue.opr[0] + issue.opr[1];
break;
case 'add_1_2':
i = rand(1,9);
j = rand(1,9);
issue.opr[0] = i;
issue.op[0] = '+';
issue.opr[1] = (j == 9) ? j*10 + rand(0,9 - i) : j * 10 + rand(0, 9);
issue.result = issue.opr[0] + issue.opr[1];
break;
case 'sub_2_1':
i = rand(1,9);
j = rand(0,9);
issue.opr[0] = i*10 + j;
issue.op[0] = '-';
issue.opr[1] = rand(0,9);
issue.result = issue.opr[0] - issue.opr[1];
break;
case 'mul_1_1':
i = rand(1,9);
j = rand(1,9);
issue.opr[0] = i;
issue.op[0] = 'x';
issue.opr[1] = j;
issue.result = issue.opr[0] * issue.opr[1];
break;
case 'addmul_2_1_1':
i = rand(1,99);
j = rand(1,9);
k = rand(1,9);
issue.op_n = 2;
issue.opr[0] = i;
issue.op[0] = '+';
issue.opr[1] = j;
issue.op[1] = 'x';
issue.opr[2] = k;
issue.result = issue.opr[0] + issue.opr[1] * issue.opr[2];
break;
case 'submul_2_1_1':
j = rand(1,9);
k = rand(1,9);
i = rand(j*k,100);
issue.op_n = 2;
issue.opr[0] = i;
issue.op[0] = '-';
issue.opr[1] = j;
issue.op[1] = 'x';
issue.opr[2] = k;
issue.result = issue.opr[0] - issue.opr[1] * issue.opr[2];
break;
case 'muladd_1_1_2':
i = rand(1,9);
j = rand(1,9);
k = rand(1,99);
issue.op_n = 2;
issue.opr[0] = i;
issue.op[0] = 'x';
issue.opr[1] = j;
issue.op[1] = '+';
issue.opr[2] = k;
issue.result = issue.opr[0] * issue.opr[1] + issue.opr[2];
break;
case 'mulsub_1_1_2':
i = rand(4,9);
j = rand(4,9);
k = rand(1,i*j);
issue.op_n = 2;
issue.opr[0] = i;
issue.op[0] = 'x';
issue.opr[1] = j;
issue.op[1] = '-';
issue.opr[2] = k;
issue.result = issue.opr[0] * issue.opr[1] - issue.opr[2];
break;
case 'sub9':
j = rand(1,8);
i = rand(j+1,9);
issue.opr[0] = i * 10 + rand(0,9);
issue.op[0] = '-';
issue.opr[1] = j * 10 + 9;
issue.result = issue.opr[0] - issue.opr[1];
break;
case 'sub012':
i = rand(2,9);
j = rand(0,2);
issue.opr[0] = i * 10 + rand(5,9);
issue.op[0] = '-';
issue.opr[1] = rand(0,i-1) * 10 + j;
issue.result = issue.opr[0] - issue.opr[1];
break;
case 'add012':
i = rand(1,8);
j = rand(1,9 - i);
k = rand(0,2);
issue.opr[0] = i * 10 + rand(0,9 - k);
issue.op[0] = '+';
issue.opr[1] = j * 10 + k;
issue.result = issue.opr[0] + issue.opr[1];
break;
case 'mix_2_1':
i = rand(0,4) * 2;
j = (i + 10) / 2;
issue.opr[0] = j * 10 + i;
issue.op[0] = '+';
issue.opr[1] = rand(1,(9-j)) * 10 + j;
issue.result = issue.opr[0] + issue.opr[1];
break;
case 'addn_2_2':
/* add with no carry but at least a[2] + b[1] >= 10
or a[1] + b[2] >= 10 to test whether it will confuse her*/
do {
i = rand(1,8);
j = rand(0,9);
k = rand(0, 9-j);
l = rand(1, 9-i);
} while (i + k < 10 && j + l < 10);
issue.opr[0] = i * 10 + j;
issue.op[0] = '+';
issue.opr[1] = l * 10 + k;
issue.result = issue.opr[0] + issue.opr[1];
break;
case 'wrong':
i = current_wrong;
j = 0;
/* op number */
k = wrong_issues[i][j++];
issue.op_n = k;
issue.opr[0] = wrong_issues[i][j++];
issue.op[0] = wrong_issues[i][j++];
issue.opr[1] = wrong_issues[i][j++];
if (k == 2) {
issue.op[1] = wrong_issues[i][j++];
issue.opr[2] = wrong_issues[i][j++];
}
issue.result = wrong_issues[i][j];
current_wrong ++;
if (current_wrong == wrong_issues.length) {
current_wrong = 0;
}
break;
default:
alert("unknown type=" + type);
}
return issue;
}
/* genrate n issues of given type */
function generate_issues(type, n)
{
var issues = new Array(n);
for (var i = 0; i < n; i ++)
issues[i] = generate_issue(type);
return issues;
}
/* store all generated issues. Maximum pages * cells per page/table */
var MAX_PAGES = 20;
var CELLS_PER_PAGE = 50;
var cells = new Array(MAX_PAGES * CELLS_PER_PAGE);
/* which op mode we are in:
0: specify type for each column
1: specify quantity of each type then mix
*/
var current_mode = 0;
/* how many page generated, user can choose between 1-MAX_PAGES */
var old_total_pages = 0;
var total_pages = 0;
function print_issue(issue, show_answer)
{
var s = '<td> ';
s += issue.opr[0];
s += issue.op[0];
s += issue.opr[1];
if (issue.op_n == 2) {
s += issue.op[1];
s += issue.opr[2];
}
s += '=';
if (show_answer)
s += issue.result;
s += '</td>'
return s;
}
function create_table(p)
{
var tab;
tab = document.createElement("table");
tab.innerHTML = '<table class="table"></table>' ;
tab.setAttribute("id", "mytab" + p);
for (var r=0; r < 11; r++) {
tr = tab.insertRow(r);
if (r == 0) {
tr.innerHTML = '<tr> <td></td> \
<td colspan="1" align="center">姓名:</td> \
<td colspan="1" align="center">班级:</td> \
<td colspan="1" align="center">时间:</td> \
<td></td> </tr>';
} else {
for (var c = 0; c < 5; c++) {
tr.insertCell(c);
}
}
}
var d = document.getElementById("tabdiv");
d.appendChild(tab);
return tab;
}
function show_issues()
{
var p, r, c;
var tab, tr, td;
var show_answer = document.getElementById("show_answer_cb").checked;
for (p = 0; p < total_pages; p++) {
tab = document.getElementById("mytab" + p);
if (!tab) {
tab = create_table(p);
}
for (r = 0; r < 10; r ++) {
tr = tab.rows[r + 1];
for (c = 0; c < 5; c ++) {
td = tr.cells[c];
td.innerHTML = print_issue(cells[p*CELLS_PER_PAGE + c*10 + r], show_answer);
}
}
}
if (old_total_pages > total_pages) {
var d = document.getElementById("tabdiv");
for (p = old_total_pages - 1; p >= total_pages; p --) {
tab = document.getElementById("mytab" + p);
if (tab) {
d.removeChild(tab);
delete tab;
}
}
}
old_total_pages = total_pages;
}
function generate_mode1()
{
var cols = ["col1type", "col2type", "col3type", "col4type", "col5type"];
var mode, issues, i, j;
for (var p = 0; p < total_pages; p++) {
for (i = 0; i < 5; i ++ ) {
mode = document.getElementById(cols[i]).value;
issues = generate_issues(mode, 10);
for (j = 0; j < 10; j++) {
cells[p*CELLS_PER_PAGE + i*10 + j] = issues[j];
}
}
}
show_issues();
}
function generate_mode2()
{
var i, j, k, p;
var mode;
var input;
var issues;
var current_cells = new Array(CELLS_PER_PAGE);
var n = new Array(modes.length);
var total = 0;
for (i = 0; i < modes.length; i++ ) {
input = document.getElementById(modes[i][0]);
if (input)
n[i] = parseInt(input.value);
else
n[i] = 0;
total += n[i];
}
if (total != 50) {
alert("总题数应该是50,现在是" + total);
return;
}
for (p = 0; p < total_pages; p++ ) {
k = 0;
for (i = 0; i < modes.length; i++ ) {
if (n[i] > 0) {
issues = generate_issues(modes[i][0], n[i]);
for (j = 0; j < n[i]; j++) {
current_cells[k] = issues[j];
k++;
}
}
}
// random sort
current_cells = current_cells.sort(function(a,b){
return Math.random()>.5 ? -1 : 1;});
// store in global array
for (i = 0; i < CELLS_PER_PAGE; i++ )
cells[p * CELLS_PER_PAGE + i] = current_cells[i];
}
show_issues();
}
function generate()
{
var pages = document.getElementById("pages").value;
if (isNaN(pages) || pages < 1 || pages > MAX_PAGES) {
alert("无效的份数设置,必须是1-20之间的数字!" + pages);
return;
}
old_total_pages = total_pages;
total_pages = pages;
if (current_mode == 0)
generate_mode1();
else
generate_mode2();
}
function changetab(){
var tabs=document.getElementById("tab").getElementsByTagName("span");
for (i=0;i<tabs.length;i++){
tabs[i].onclick=tab;
}
}
function tab(){
var tabs=document.getElementById("tab").getElementsByTagName("span");
var cts=document.getElementById("ct").getElementsByTagName("div");
for (i=0;i<tabs.length;i++){
tabs[i].className="";
cts[i].className="";
if (tabs[i]==this){
tabs[i].className="tab";
cts[i].className="ct";
current_mode = i;
}
}
}
/* fill in the mode lists */
function create_options()
{
var i, j;
var select, select_html;
var list, li;
for (i = 1; i < 6; i++) {
select = document.getElementById("col" + i + "type");
for (j = 0; j < modes.length; j++ )
select.options.add(new Option(modes[j][1], modes[j][0]));
}
list = document.getElementById("mode_option_list");
for (i = 0; i < modes.length; i++ ) {
li = document.createElement("li");
li.innerHTML = '<li class="mixmode">' + modes[i][1] + '<input id="' +
modes[i][0] +'" type="text" value="0" size="2"/> </li>';
list.appendChild(li);
}
}
window.onload=function (){
changetab();
create_options();
generate();
}
function printme()
{
$("#tabdiv").print();
}
function saveasword()
{
$("table").tableExport({type:'doc',escape:'false', excelstyles:['height','width','text-align','font-size','align']});
}
function saveaspdf()
{
$("table").tableExport({type:'pdf', fileName:'issues', pdfmake:{enabled:true}});
}
</script>
<center> <h2 id="tab">
<span class="tab">按列选模式生成</span>
<span>按模式数量混合生成</span>
</h2></center>
<div id="ct" align="center">
<div class="ct">
<ul>
<li class="colmode">
第1列: <select id="col1type">
</select>
</li>
<li class="colmode">
第2列: <select id="col2type">
</select>
</li>
<li class="colmode">
第3列: <select id="col3type">
</select>
</li>
<li class="colmode">
第4列: <select id="col4type">
</select>
</li>
<li class="colmode">
第5列: <select id="col5type">
</select>
</li>
</ul>
</div>
<div>
<ul id="mode_option_list"> </ul>
</div>
</div>
<div id="act" align="center">
<div class="act" align="center">
<input type="button" value="重新生成" onclick="generate()" />
<input type="text" value="1" id="pages" size="2"/>份
<input type="button" value="打印习题" onclick="printme()" />
<input type="button" value="另存为word" onclick="saveasword()" />
<!---
<input type="button" value="另存为pdf" onclick="saveaspdf()" />
---!>
<input type="checkbox" id="show_answer_cb" value="answer" onclick="show_issues()"/>显示答案
</div>
</div>
<div id="tabdiv" class="print_section" align="center" width="100%">
</div>
</body>
</html>