-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
122 lines (106 loc) · 3.3 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p>
<label for="inChar">symbol:</label>
<input type="text" name="inChar" id="inChar" maxlength="1">
</p>
<p id="showNum"></p>
<p>
<label for="inNum">number(radix 10):</label>
<input type="number" id="inNum" min="0">
</p>
<p id="showChar"></p>
<p id="range-input">
<input type="number" id="from" min="0">
<span>~</span>
<input type="number" id="to" min="0">
</p>
<button id="btnShowRange">generate</button>
<p id="showRange"></p>
<style>
p {
width: 95vw;
display: flex;
}
input,
p {
font-size: 2rem;
}
span {
font-size: 5rem;
}
button {
width: 100px;
height: 50px;
}
#range-input {
display: flex;
width: 100%;
}
</style>
<script>
document.querySelector('button#btnShowRange').onclick = emitBtn
document.querySelector('input#from').onkeyup = e => e.keyCode === 13 && emitBtn()
document.querySelector('input#to').onkeyup = e => e.keyCode === 13 && emitBtn()
function emitBtn() {
console.log('123')
const from = document.querySelector('input#from')
const to = document.querySelector('input#to')
try {
const a = Number.parseInt(from.value)
const b = Number.parseInt(to.value)
if (Number.isNaN(a) || Number.isNaN(b)) return
document.querySelector('p#showRange').textContent = generateRangeChar(a, b).join(' ')
} catch (error) {
console.error(error.message)
}
}
const showNum = document.querySelector('p#showNum')
const showChar = document.querySelector('p#showChar')
document.querySelector('input#inChar').oninput = (e => {
if (e.target.value !== '') {
const num = e.target.value.charCodeAt() || 0
showNum.innerText =
`10 radix: &#${num};
16 radix: U+${num.toString(16)}
`
} else {
showNum.innerText = ''
}
})
document.querySelector('input#inNum').oninput = (e => {
if (e.target.value !== '') {
showChar.textContent = toChar(e.target) // innerHTML = `P`
} else {
showChar.textContent = ''
}
})
function generateRangeChar(a, b) {
if (a > b) {
return generateRangeChar(b, a)
}
const result = []
for (let i = a; i <= b; i++) {
result.push(toChar(i))
}
return result
}
function toChar(input) {
if (input instanceof HTMLInputElement) {
input = input.value
}
input = Number.parseInt(input)
if (Number.isNaN(input)) {
return ''
}
return String.fromCodePoint(input)
}
</script>
</body>
</html>