-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.html
55 lines (45 loc) · 1.09 KB
/
list.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
<html>
<head>
<meta charset="UTF-8">
<STYLE type="text/css">
.selected {
color: red;
border: 1px solid black;
}
</STYLE>
</head>
<body>
<ul id="UL">
{{items_list}}
</ul>
<script>
var current = -1;
var li = document.getElementById('UL').getElementsByTagName("li");
var max = li.length;
// console.log(li[0].firstElementChild.getAttribute('href'));
document.addEventListener('keydown', function(e) {
if (e.keyCode === 40) {
current += 1;
}
if (e.keyCode === 38) {
current -= 1;
}
if (e.keyCode === 13) {
document.location = li[current].firstElementChild.getAttribute('href')
}
if (current < 0) {
current = max;
}
if (current >= max) {
current = 0;
}
for (var i = 0; i < max; i++) {
if (li[i].classList.contains('selected')) {
li[i].className = "";
}
}
li[current].classList.add('selected');
});
</script>
</body>
</html>