gpt4 book ai didi

javascript - jQuery:选中一个文本输入框

转载 作者:太空宇宙 更新时间:2023-11-03 19:48:40 24 4
gpt4 key购买 nike

您知道如何在打开新标签页时无需选择搜索栏就可以开始输入吗?我有一个 HTML 文本输入框,我希望能够打开我的网页并立即输入该文本输入框,因为没有更好的术语。假设我的输入框是这样的:

 <input type="text" class="myInput" value="add an item"></input>

我现在正在使用 HTML、CSS 和 JavaScript/jQuery。我可以添加什么代码来确保文本输入框可以立即输入?

最佳答案

使用自动对焦:

<input type="text" class="myInput" value="add an item" autofocus/>

来自 the input documentation on MDN :

This Boolean attribute lets you specify that a form control should have input focus when the page loads, unless the user overrides it (e.g. 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). Note that the focusing of the control may occur before the firing of the DOMContentLoaded event.

关于javascript - jQuery:选中一个文本输入框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46498545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com