prevent error caused by index out of bound

pull/151/head
Kaiyang Yao 3 years ago
parent 236f68461b
commit 534a6781a3

@ -6,9 +6,9 @@ codes.forEach((code, idx) => {
code.addEventListener('keydown', (e) => {
if(e.key >= 0 && e.key <=9) {
codes[idx].value = ''
setTimeout(() => codes[idx + 1].focus(), 10)
setTimeout(() => codes[idx < codes.length - 1 ? idx + 1 : idx].focus(), 10)
} else if(e.key === 'Backspace') {
setTimeout(() => codes[idx - 1].focus(), 10)
setTimeout(() => codes[idx > 0 ? idx - 1 : idx].focus(), 10)
}
})
})
Loading…
Cancel
Save