input 获取焦点
时间: 2023-11-07 09:18:14 浏览: 81
input的focus方法使用
input可以通过两种方式获取焦点。一种是使用HTML属性autofocus,在input标签中增加属性autofocus即可自动获取焦点。例如:
<input id='test' type="text" autofocus="autofocus" />
另一种是使用JavaScript方法focus(),通过获取元素的id并调用focus()方法来实现。例如:
document.getElementById('test').focus();<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [【杂记】(input获取焦点失去焦点、获取input中输入的值、 键盘事件、js事件、Math 属性、手机自适应meta...](https://blog.csdn.net/Khun_HWJ/article/details/102839075)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [input获取焦点](https://blog.csdn.net/gotowest123/article/details/125541315)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文