element.focus()没用,没有光标闪动的聚焦效果,那该怎么做?
<input autofocus="autofocus" id="input">
//js
document.getElementById('input').focus();//我执行这句语句的时候光标没有自动聚焦,还是blur状态
element.focus()没用,没有光标闪动的聚焦效果,那该怎么做?
<input autofocus="autofocus" id="input">
//js
document.getElementById('input').focus();//我执行这句语句的时候光标没有自动聚焦,还是blur状态
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 typing in a different control. Only one form element in a document can have the autofocus 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()会没有用。不贴出代码无法解决,随手写了一下测试是有用的
13 回答12.8k 阅读
7 回答1.9k 阅读
3 回答1.1k 阅读✓ 已解决
2 回答1.2k 阅读✓ 已解决
6 回答872 阅读✓ 已解决
6 回答1k 阅读
2 回答1.3k 阅读✓ 已解决
trigger,模拟点击