autofocus HTML5 This Boolean attribute lets you specify that a form control should have input focus when the page loads, unless the user overrides it, for example by ty ty introinent control. attribute, which is a Boolean. It cannot be applied if the type attribute is set to hidden (that is, you cannot automatically set focus to a hidden control).
給輸入框加上這個屬性就行了
mdn連結
另外不懂為什麼 element.focus()會沒用。不貼出程式碼無法解決,隨手寫了一下測試是有用的
trigger,模擬點擊