From cb45acb2e249c42b196b2ceb7f98cb009cb0a997 Mon Sep 17 00:00:00 2001 From: yolo <1084677348@qq.com> Date: Tue, 5 Jan 2021 16:01:17 +0800 Subject: [PATCH] fix(verify-account-ui): Cannot read property 'focus' of undefined --- verify-account-ui/script.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/verify-account-ui/script.js b/verify-account-ui/script.js index 6df6bf0..4b7bfd4 100644 --- a/verify-account-ui/script.js +++ b/verify-account-ui/script.js @@ -1,4 +1,5 @@ const codes = document.querySelectorAll('.code') +const length = codes.length codes[0].focus() @@ -6,8 +7,14 @@ codes.forEach((code, idx) => { code.addEventListener('keydown', (e) => { if(e.key >= 0 && e.key <=9) { codes[idx].value = '' + if (length - 1 == idx) { + return + } setTimeout(() => codes[idx + 1].focus(), 10) } else if(e.key === 'Backspace') { + if (idx == 0) { + return + } setTimeout(() => codes[idx - 1].focus(), 10) } })