Spaces:
Running
Running
Commit
·
3af41a1
1
Parent(s):
76ada96
add
Browse files- index.html +89 -40
index.html
CHANGED
@@ -251,55 +251,104 @@ tr:hover a {
|
|
251 |
}
|
252 |
|
253 |
function sortTable(tableId, n) {
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
258 |
while (switching) {
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
}
|
276 |
-
}
|
277 |
-
} else if (dir == "desc") {
|
278 |
-
if (isNaN(x.innerHTML)) {
|
279 |
-
if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
|
280 |
-
shouldSwitch = true;
|
281 |
-
break;
|
282 |
-
}
|
283 |
-
} else {
|
284 |
-
if (Number(x.innerHTML) < Number(y.innerHTML)) {
|
285 |
-
shouldSwitch = true;
|
286 |
-
break;
|
287 |
-
}
|
288 |
-
}
|
289 |
-
}
|
290 |
}
|
|
|
291 |
if (shouldSwitch) {
|
292 |
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
|
293 |
switching = true;
|
294 |
switchcount++;
|
295 |
-
} else {
|
296 |
-
if (switchcount == 0 && dir == "asc") {
|
297 |
-
dir = "desc";
|
298 |
-
switching = true;
|
299 |
-
}
|
300 |
}
|
301 |
}
|
|
|
|
|
|
|
|
|
|
|
302 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
|
304 |
Object.keys(urls).forEach(key => {
|
305 |
fetch(urls[key])
|
|
|
251 |
}
|
252 |
|
253 |
function sortTable(tableId, n) {
|
254 |
+
const table = document.getElementById(tableId);
|
255 |
+
let switching = true;
|
256 |
+
let dir = table.dataset.sortDir === "asc" ? "desc" : "asc";
|
257 |
+
let switchcount = 0;
|
258 |
+
|
259 |
+
const headers = table.querySelectorAll("th");
|
260 |
+
headers.forEach((header, index) => {
|
261 |
+
if (index !== n) {
|
262 |
+
header.querySelector(".sort-arrow").textContent = "";
|
263 |
+
}
|
264 |
+
});
|
265 |
+
|
266 |
+
const currentHeader = headers[n];
|
267 |
+
const arrowSpan = currentHeader.querySelector(".sort-arrow");
|
268 |
+
arrowSpan.textContent = dir === "asc" ? " ▲" : " ▼";
|
269 |
+
|
270 |
while (switching) {
|
271 |
+
switching = false;
|
272 |
+
const rows = table.rows;
|
273 |
+
for (let i = 1; i < rows.length - 1; i++) {
|
274 |
+
let shouldSwitch = false;
|
275 |
+
let x = rows[i].cells[n].innerHTML;
|
276 |
+
let y = rows[i + 1].cells[n].innerHTML;
|
277 |
+
|
278 |
+
// 判断是否为数字
|
279 |
+
let xVal = isNaN(parseFloat(x)) ? x : parseFloat(x);
|
280 |
+
let yVal = isNaN(parseFloat(y)) ? y : parseFloat(y);
|
281 |
+
|
282 |
+
// 比较逻辑
|
283 |
+
if (dir === "asc" && xVal > yVal) {
|
284 |
+
shouldSwitch = true;
|
285 |
+
} else if (dir === "desc" && xVal < yVal) {
|
286 |
+
shouldSwitch = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
}
|
288 |
+
|
289 |
if (shouldSwitch) {
|
290 |
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
|
291 |
switching = true;
|
292 |
switchcount++;
|
|
|
|
|
|
|
|
|
|
|
293 |
}
|
294 |
}
|
295 |
+
|
296 |
+
// 当一次都没有切换时,反转排序方向
|
297 |
+
if (switchcount === 0) {
|
298 |
+
dir = dir === "asc" ? "desc" : "asc";
|
299 |
+
}
|
300 |
}
|
301 |
+
|
302 |
+
|
303 |
+
// var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
|
304 |
+
// table = document.getElementById(tableId);
|
305 |
+
// switching = true;
|
306 |
+
// dir = "asc";
|
307 |
+
// while (switching) {
|
308 |
+
// switching = false;
|
309 |
+
// rows = table.rows;
|
310 |
+
// for (i = 1; i < (rows.length - 1); i++) {
|
311 |
+
// shouldSwitch = false;
|
312 |
+
// x = rows[i].getElementsByTagName("TD")[n];
|
313 |
+
// y = rows[i + 1].getElementsByTagName("TD")[n];
|
314 |
+
// if (dir == "asc") {
|
315 |
+
// if (isNaN(x.innerHTML)) {
|
316 |
+
// if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
|
317 |
+
// shouldSwitch = true;
|
318 |
+
// break;
|
319 |
+
// }
|
320 |
+
// } else {
|
321 |
+
// if (Number(x.innerHTML) > Number(y.innerHTML)) {
|
322 |
+
// shouldSwitch = true;
|
323 |
+
// break;
|
324 |
+
// }
|
325 |
+
// }
|
326 |
+
// } else if (dir == "desc") {
|
327 |
+
// if (isNaN(x.innerHTML)) {
|
328 |
+
// if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
|
329 |
+
// shouldSwitch = true;
|
330 |
+
// break;
|
331 |
+
// }
|
332 |
+
// } else {
|
333 |
+
// if (Number(x.innerHTML) < Number(y.innerHTML)) {
|
334 |
+
// shouldSwitch = true;
|
335 |
+
// break;
|
336 |
+
// }
|
337 |
+
// }
|
338 |
+
// }
|
339 |
+
// }
|
340 |
+
// if (shouldSwitch) {
|
341 |
+
// rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
|
342 |
+
// switching = true;
|
343 |
+
// switchcount++;
|
344 |
+
// } else {
|
345 |
+
// if (switchcount == 0 && dir == "asc") {
|
346 |
+
// dir = "desc";
|
347 |
+
// switching = true;
|
348 |
+
// }
|
349 |
+
// }
|
350 |
+
// }
|
351 |
+
// }
|
352 |
|
353 |
Object.keys(urls).forEach(key => {
|
354 |
fetch(urls[key])
|