-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
383 lines (339 loc) · 13.8 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Thinksite</title>
<link rel="stylesheet" href="css/newstart.css">
<link rel="stylesheet" href="css/public.css">
<link rel="stylesheet" href="font/iconfont.css">
</head>
<body>
<div class="left">
<div class="left-content">
<div class="logo"></div>
<table class="information">
<tr>
<td>教师风采</td>
</tr>
<tr>
<td>开设课程</td>
</tr>
<tr>
<td>问题咨询</td>
</tr>
<tr>
<td>封闭训练营</td>
</tr>
</table>
</div>
</div>
<div class="right">
<div class="header">
<div class="list">
<span>首页</span>
<span>/</span>
<span>我的课程</span>
<span>/</span>
<span>课程列表</span>
</div>
</div>
<div class="typeIn-outline">
<div class="typeIn">
<span>分类</span><input type="text" class="category">
<span>标题</span><input type="text" class="title">
<span>班级</span><input type="text" class="class">
<span>状态</span><input type="text" class="status">
<br>
<span>创建时间</span><input type="text" class="time">
<span>创建者</span><input type="text" class="creator">
<span>分校地区</span><input type="text" class="branch">
<input type="button" value="录入" class="type"> <span class="warning" style="color:red;display:none">请勿留空!</span>
</div>
</div>
<table class="worktab">
<thead>
<tr>
<td><input type="checkbox" class="headcheck"> ID <span class="up"></span><span class="down"></span></td>
<td>分类</td>
<td>标题</td>
<td>班级</td>
<td>状态</td>
<td>创建时间</td>
<td>创建者</td>
<td>分校地区</td>
<td>编辑|删除</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div class="delete">
<input type="text" class="selected-id" placeholder="请选择要删除的ID或全选">
<input type="button" class="selected-delete" value="选中删除">
</div>
</div>
</body>
</html>
<script src="js/jquery.min.js"></script>
<script src="js/database.js"></script>
<script src="js/sorting_bigger.js"></script>
<script src="js/sorting_smaller.js"></script>
<script>
$(function(){
var container1=null;
var typeInId=0;
var blank_num=0;
var tr_ind=0;
var tr_id=0;
var CheckboxId=[];
var check_id=0;
var headcheck_id=0;
var emp=null;
var ind=0;
var num=0;
var btn_ind=0;
var output=[];
var check_count=0;
var num=0;
var typeIn_check=[];
var key_status=false;
var enter_click=false;
//表格内容渲染
//tbody filling
function tbodyfiller(json){
var InformationInputer=
'<tr title="'+json.ID+'">'+
'<td>'+'<input type="checkbox" class="check" title="'+json.ID+'">'+' '+json.ID+'</td>'+
'<td>'+'<input type="text" class="text-list" value="'+json.category+'" disabled>'+'</td>'+
'<td>'+'<input type="text" class="text-list" value="'+json.title+'" disabled>'+'</td>'+
'<td>'+'<input type="text" class="text-list" value="'+json.class+'" disabled>'+'</td>'+
'<td>'+'<input type="text" class="text-list" value="'+json.status+'" disabled>'+'</td>'+
'<td>'+'<input type="text" class="text-list" value="'+json.time+'" disabled>'+'</td>'+
'<td>'+'<input type="text" class="text-list" value="'+json.creator+'" disabled>'+'</td>'+
'<td>'+'<input type="text" class="text-list" value="'+json.branch+'" disabled>'+'</td>'+
'<td>'+'<input type="button" class="btn1" value="编辑" title="'+json.ID+'+">'+'<span>|</span>'+'<input type="button" value="删除" class="btn2" title="'+json.ID+'+">'+ '</td>'+
'</tr>'
return InformationInputer
}
function tbodyInitializer(Students){
$(".worktab tbody").html("");
$.each(Students,function(key,val){
$(".worktab tbody").append(tbodyfiller(val))
})
}
tbodyInitializer(Students);
//ID排序
$(".worktab thead span.up").on("click",function(){
sorting_bigger(Students);
tbodyInitializer(Students);
})
$(".worktab thead span.down").on("click",function(){
sorting_smaller(Students);
tbodyInitializer(Students);
})
//录入信息
//adding new rows
$.each(Students,function(key,val){
if(val.ID>typeInId){
typeInId=val.ID
}
})
function TypeInRefresher(Students,students_){
Students.unshift({
ID:students_.ID,
category:$(students_.category).val(),
title:$(students_.title).val(),
class:$(students_.class).val(),
status:$(students_.status).val(),
time:$(students_.time).val(),
creator:$(students_.creator).val(),
branch:$(students_.branch).val()
})
$(".typeIn input[type='text']").val("");
tbodyInitializer(Students);
}
//点击“录入”信息按钮前,检查是否输入信息输入框是否存空
//check if inputing contents
$(".typeIn").on("click",".type",function(){
for(var i=0;i<$(".typeIn input[type='text']").length;i++){
if($(".typeIn input[type='text']").eq(i).val()!==""){
typeIn_check=0
}else{
typeIn_check++;
}
}
if(typeIn_check==0){
key_status=false;//reset status of key(将键盘恢复默认状态)
typeInId++;
TypeInRefresher(Students, {ID:typeInId,category:".category",title:".title",class:".class",status:".status",time:".time",creator:".creator",branch:".branch"});
$(".warning").hide();
}else if(typeIn_check > 0 && key_status==false){//check if key was pressed down(检查键盘是否按下,排除键盘影响)
$(".warning").show();
typeIn_check=0;
}
})
//点击删除一行信息
//click deleting row
function DeleteRow(){
for(var i=0;i<Students.length;i++){
if(Students[i].ID==tr_id){
Students.splice(i,1);
$(".worktab tbody tr").eq(tr_ind).remove();
}
}
}
$(".worktab").on("click",".btn2",function(){
tr_ind=$(this).parent("td").parent("tr").index();
tr_id=$(this).parent("td").parent("tr").attr("title");
DeleteRow();
$.each(CheckboxId,function(key,val){
if(val==tr_id){
CheckboxId.splice(key,1);
output=CheckboxId.join();
// $(".selected-id").val('选中ID '+output);
}
if(CheckboxId.length==$(".check").length){
$(".headcheck").attr("checked",true);
$(".selected-id").val("全选");
}else{
$(".headcheck").attr("checked",false);
$(".selected-id").val('选中ID '+output);
}
})
})
//点击删除所有信息
//click deleting tbody
$(".worktab").on("click",".check",function(){
check_id=$(this).attr("title");
if($(this).attr("checked")){
CheckboxId.unshift(check_id);
output=CheckboxId.join();
if(CheckboxId.length==$(".check").length){
$(".headcheck").attr("checked",true);
$(".selected-id").val("全选");
}else{
$(".headcheck").attr("checked",false);
$(".selected-id").val('选中ID '+output);
}
}else{
$(".headcheck").attr("checked",false);
CheckboxId=[];
$(".selected-id").val("");
for(var i=0;i<$(".check").length;i++){
check_id=$(".check").eq(i).attr("title");
if($(".check").eq(i).attr("checked")){
CheckboxId.unshift(check_id);
output=CheckboxId.join();
$(".selected-id").val('选中ID '+output);
}
}
}
})
$(".headcheck").on("click",function(){
headcheck_id=$(this).attr("title");
if($(".headcheck").attr("checked")){
$(".selected-id").val("全选");
for(var i=0;i<$(".check").length;i++){
$(".check").eq(i).attr("checked",true);
check_id=$(".check").eq(i).attr("title");
CheckboxId.push(check_id)
}
}else{
$(".selected-id").val("");
CheckboxId=[];
for(var i=0;i<$(".check").length;i++){
$(".check").eq(i).attr("checked",false);
}
}
})
$(".selected-delete").on("click",function(){
for(var i=0;i<CheckboxId.length;i++){
for(var j=0;j<Students.length;j++){
if(CheckboxId[i]==Students[j].ID){
Students.splice(j,1);
$(".worktab tbody tr").eq(j).remove();
}
}
}
$(".selected-id").val("");
CheckboxId=[];
$(".headcheck").attr("checked",false)
})
//键盘下按删除
//keydown deleting
RowShifting();
$(window).keydown(function(e){
key_status=true;
var key=e.keyCode;
tr_ind=$(".worktab tbody tr.b").index();
tr_id=$(".worktab tbody tr.b").attr("title");
switch(key){
case 40:
if(num<$(".worktab tbody tr").length){
num++;
RowShifting();
}else{
num=-1
};
if($(".worktab tbody tr.b").children("td").eq(0).children(".check").attr("checked")){
enter_click=true
}else{
enter_click=false
}
break;
case 38:
if(num>=0){
num--;
RowShifting()
}else{
num=$(".worktab tbody tr").length-1
};
if($(".worktab tbody tr.b").children("td").eq(0).children(".check").attr("checked")){
enter_click=true
}else{
enter_click=false
}
break;
case 13:
if(enter_click==false){
$(".worktab tbody tr.b").children("td").eq(0).children(".check").attr("checked",true);
enter_click=true;
}
else{
$(".worktab tbody tr.b").children("td").eq(0).children(".check").attr("checked",false);
enter_click=false
}
break;
case 46:
// tr_ind=$(".worktab tbody tr.b").index();
// tr_id=$(".worktab tbody tr.b").attr("title");
if($(".check").eq(tr_ind).attr("checked")){DeleteRow(); };
break;
default:
break
}
typeIn_check=0;
})
function RowShifting(){
$(".worktab tbody tr").eq(num).addClass("b").siblings("tr").removeClass("b");
for(var i=0;i<$(".worktab tbody tr").eq(num).children("td").length;i++){
$(".worktab tbody tr").eq(num).children("td").eq(i).children(".text-list").addClass("b").parent("td").parent("tr").siblings("tr").children("td").children(".text-list").removeClass("b");
};
}
//点击编辑某行信息(表格每一单元格内容由输入框填充,可编辑状态下,输入框disabled为false,反之为true)
//click editing row
$("body").on("dblclick","td",function(){
$(this).children(".text-list").removeAttr("disabled")
})
$("body").on("blur","td",function(){
$(this).children(".text-list").attr("disabled",true);
})
$(".worktab").on("click",".btn1",function(){
btn_ind=$(this).parent("td").parent("tr").index();
for(var i=0;i<$(".worktab tbody tr").eq(btn_ind).children("td").children("input[type='text']").length;i++){
$(".worktab tbody tr").eq(btn_ind).children("td").children(".text-list").eq(i).removeAttr("disabled");
$(".worktab tbody tr").eq(btn_ind).siblings("tr").children("td").children(".text-list").eq(i).attr("disabled",true);
}
})
})
</script>