element.focus()沒用,沒有遊標閃爍的聚焦效果,那該怎麼做?
<input autofocus="autofocus" id="input">
//js
document.getElementById('input').focus();//我执行这句语句的时候光标没有自动聚焦,还是blur状态
PHP中文网2017-06-12 09:33:40
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()會沒用。不貼出程式碼無法解決,隨手寫了一下測試是有用的