javascript - js怎麼讓輸入框自動取得焦點?
我想大声告诉你
我想大声告诉你 2017-06-12 09:31:40
0
2
739

element.focus()沒用,沒有遊標閃爍的聚焦效果,那該怎麼做?

<input autofocus="autofocus" id="input">
//js
document.getElementById('input').focus();//我执行这句语句的时候光标没有自动聚焦,还是blur状态
我想大声告诉你
我想大声告诉你

全部回覆(2)
Ty80

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 introi​​nent 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()會沒用。不貼出程式碼無法解決,隨手寫了一下測試是有用的

Ty80

trigger,模擬點擊

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!