-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
74 lines (60 loc) · 1.9 KB
/
main.js
File metadata and controls
74 lines (60 loc) · 1.9 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
var order = 0;
var status = "start";
var randomSortLoop;
var itemsSheetHtml = "";
var itemsSheet = document.getElementById("itemsSheet");
//随机选项修改处
var items = ["Allen","Bob","Cindy","David",
"Erric","Fox","Goslin","Henry","Issac","Jerry","Kate","Luis","Melody"];
window.onload = function() {
itemsSheetHtml += "<table class=\"table table-showed\"><tr><th style=\"border: 1px solid black;\">序号</th><th style=\"border: 1px solid black;\">名称</th></tr>";
for(let index in items){
order = parseInt(index) + 1;
itemsSheetHtml += "<tr><td>"+order+"</td><td>"+items[index]+"</td></tr>";
}
itemsSheetHtml += "</table>";
itemsSheet.innerHTML =itemsSheetHtml;
};
function randomSort(a, b) {
return Math.random() > 0.5 ? -1 : 1;
}
function refresh(){
itemsSheet.innerHTML =itemsSheetHtml;
}
// 输入名称数组 输出随机排序
function randomSortitems(){
itemsSheetHtml = "";
items.sort(randomSort);
itemsSheetHtml += "<table class=\"table table-showed\"><tr><th style=\"border: 1px solid black;\">序号</th><th style=\"border: 1px solid black;\">名称</th></tr>";
for(let index in items){
order = parseInt(index) + 1;
itemsSheetHtml += "<tr><td>"+order+"</td><td>"+items[index]+"</td></tr>";
}
itemsSheetHtml += "</table>";
refresh();
}
function test(){
randomSortitems();
}
//点击开始 ,滚动(每0.3秒刷新一次名单),开始按钮变成停止
function start(){
startorstop.innerText = "停止";
startorstop.className = "btn btn-default";
status = "stop";
randomSortLoop = setInterval(test, 200);
}
//点击停止, 停止滚动, 停止按钮变成开始
function stop(){
startorstop.innerText = "开始";
startorstop.className = "btn btn-primary";
status = "start";
window.clearInterval(randomSortLoop);
}
function startOrStop(){
var startorstop = document.getElementById("startorstop");
if(status == "start"){
start();
}else{
stop();
}
}