-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
179 lines (154 loc) · 5 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>模拟★队列</title>
<style>
.num li, #num-sort-wrap li {
display: inline-block;
list-style: none;
background-color: #72b16a;
padding: 0 5px;
margin: 5px;
}
.dis1 {
display: none;
color: red;
}
.dis2 {
display: none;
color: red;
}
</style>
</head>
<body>
<div class="btn">
<h3>请输入10到100之间的数字:</h3>
<input type="text" value="">
<span class="dis1">输入的不是数字,请重输</span>
<span class="dis2">您输入的不是10-100之间的数字,请重输</span>
<button class="lt-in" type="button">→左侧入</button>
<button class="rt-in" type="button">←右侧入</button>
<button class="lt-out" type="button">←左侧出</button>
<button class="rt-out" type="button">右侧出→</button>
<button class="num-sort" type="button">排序</button>
</div>
<div class="num-wrap">
<ul class="num">
</ul>
</div>
<div>
<ul id="num-sort-wrap">
</ul>
</div>
<script>
var ipt = document.getElementsByTagName('input')[0];
var ltIn = document.getElementsByClassName('lt-in')[0];
var rtIn = document.getElementsByClassName('rt-in')[0];
var ltOut = document.getElementsByClassName('lt-out')[0];
var rtOut = document.getElementsByClassName('rt-out')[0];
var dis1 = document.getElementsByClassName('dis1')[0];
var dis2 = document.getElementsByClassName('dis2')[0];
var numSort = document.getElementsByClassName('num-sort')[0];
var numSortWrap = document.getElementById('num-sort-wrap');
var num = document.getElementsByClassName('num')[0];
var lis = num.getElementsByTagName('li');
/*左侧插入*/
function ltInFunc() {
var number = ipt.value;
var liLen = lis.length;
if (isNaN(number)) {
dis1.style.display = 'inline';
ipt.value = "";
} else if (number < 10 || number > 100) {
dis2.style.display = 'inline';
ipt.value = "";
} else if (liLen >= 60) {
alert('您输入的数字个数已超过60,不能再输入');
} else {
var ctLi = document.createElement('li');
ctLi.innerText = number;
ctLi.style.height = number + 'px';
num.insertBefore(ctLi, lis[0]);
ipt.value = "";
}
ipt.onfocus = function () {
dis1.style.display = 'none';
dis2.style.display = 'none';
}
}
/*右侧插入*/
function rtInFunc() {
var number = ipt.value;
var liLen = lis.length;
if (isNaN(number)) {
dis1.style.display = 'inline';
ipt.value = "";
} else if (number < 10 || number > 100) {
dis2.style.display = 'inline';
ipt.value = "";
} else if (liLen >= 60) {
alert('您输入的数字个数已超过60,不能再输入');
} else {
var ctLi = document.createElement('li');
ctLi.innerText = number;
ctLi.style.height = number + 'px';
num.appendChild(ctLi);
ipt.value = "";
}
ipt.onfocus = function () {
dis1.style.display = 'none';
dis2.style.display = 'none';
}
}
/*左侧出*/
function ltOutFunc() {
var delt = lis[0].innerText;
num.removeChild(lis[0]);
alert('您删除的数字是' + delt);
}
/*右侧出*/
function rtOutFunc() {
var len = lis.length;
var dert = lis[len - 1].innerText;
num.removeChild(lis[len - 1]);
alert('您删除的数字是' + dert);
}
/*删除所点击的数字*/
num.onclick = function (e) {
var e = e || window.event;
var target = e.target || e.srcElement;
if (target && target.nodeName == 'LI') {
alert(target.innerText);
num.removeChild(target);
}
};
/*排序函数*/
function sortN() {
numSortWrap.innerHTML = '';
var liLen = lis.length;
var arr = [];
function byNum(a, b) {
return a - b;
}
for (var i = 0; i < liLen; i++) {
arr.push(Number(lis[i].innerText));
}
arr.sort(byNum);
for (var j = 0; j < liLen; j++) {
setInterval(function () {
}, 3000);
var newLi = document.createElement('li');
newLi.innerText = arr[j];
newLi.style.height = arr[j] + 'px';
numSortWrap.appendChild(newLi);
}
}
ltIn.onclick = ltInFunc;
rtIn.onclick = rtInFunc;
ltOut.onclick = ltOutFunc;
rtOut.onclick = rtOutFunc;
numSort.onclick = sortN;
</script>
</body>
</html>