-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
74 lines (74 loc) · 2.3 KB
/
index.html
File metadata and controls
74 lines (74 loc) · 2.3 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>投票</title>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
teams=[];
ups=[];
pre=[];
back=[];
var head=0;
function mswap(d1,d2){
var d11=$('<hr/>');
var d22=$('<hr/>');
$(d1).before(d11);
$(d2).before(d22);
$(d22).after(d1);
$(d11).after(d2);
$(d11).remove();
$(d22).remove();
}
function add(id){
ups[id]++;
document.getElementById(id.toString()).innerText=(id+1).toString()+'班';
var str='';
for(var i=1;i<=ups[id];i++) str+='|';
document.getElementById(id.toString()).innerText+=str+ups[id].toString()+'票';
while(pre[id]!=-1){
var nid=pre[id];
if(ups[nid]>=ups[id]) break;
pre[id]=pre[nid];
pre[nid]=id;
pre[back[id]]=nid;
back[pre[id]]=id;
back[nid]=back[id];
back[id]=nid;
mswap(document.getElementById(id.toString()),document.getElementById(nid.toString()));
}
if(pre[id]==-1) head=id;
}
function showRes(){
var str='';
var pos=head;
while(pos!=20){
str+=(pos+1).toString()+'班'+ups[pos].toString()+'票 ';
pos=back[pos];
}
alert(str);
}
</script>
</head>
<body>
<h1>投票</h1>
<button onclick="showRes()">显示结果</button>
<div id="bts"></div>
<div id="tmsort"></div>
<script>
for(var i=1;i<=20;i++){
teams.push(i.toString()+'班');
ups.push(0);
pre.push(i-2);
back.push(i);
}
var bts=document.getElementById('bts');
var tmsort=document.getElementById('tmsort');
for(var i=0;i<teams.length;i++){
bts.innerHTML+='<button onclick=add('+i.toString()+')>'+teams[i]+'</button>';
tmsort.innerHTML+='<div id='+i.toString()+'>'+teams[i]+'0票</div>';
}
</script>
</body>
</html>