HTML textarea autofocus 属性
htmlweb developmentfront end technology更新于 2025/3/20 7:40:17
<textarea> 元素的 autofocus 属性用于在页面加载时将自动对焦设置为文本区域本身。HTML5 中引入了 <textarea> 元素的 autofocus 属性。
以下是语法 −
<textarea autofocus>
现在让我们看一个实现 <textarea> 元素 autofocus 属性的示例 −
示例
<!DOCTYPE html> <html> <body> <h2>Interview Questions</h2> <p>Why do you want go for the Technical Writer Job Profile? (100 words)</p> <textarea rows="6" cols="70" autofocus> Write the answer in 100 words only... </textarea> <p>What are your strengths? (50 words)</p> <textarea rows="4" cols="70" autofocus> Write the answer in 50 words only... </textarea> </body> </html>
输出

在上面的例子中,我们设置了两个textarea −
<textarea rows="6" cols="70" autofocus> Write the answer in 100 words only... </textarea> <p>What are your strengths? (50 words)</p> <textarea rows="4" cols="70" autofocus> Write the answer in 50 words only... </textarea>
我们已将其中一个文本区域设置为自动对焦。现在,无论何时页面加载,焦点和光标都会自动显示在第一个文本区域中 −
<textarea rows="6" cols="70" autofocus>
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

