简体   繁体   English

专注于textarea

[英]Focus on textarea

How would I do the following in javascript: 我将如何在javascript中执行以下操作:

<textarea onload="focus">Here is some text</textarea>

Basically, I want the textarea field to be focused on, and I want to do it within the html tag. 基本上,我希望textarea字段集中在html标签内。

Try out the autofocus attribute: 试用自动对焦属性:

 <textarea autofocus>
At w3schools.com you will learn how to make websites.
</textarea> 

w3schools w3schools

You would need to provide some way to select your textarea, like an ID: <textarea id="my-textarea"></textarea> . 您需要提供一些选择文本区域的方法,例如ID: <textarea id="my-textarea"></textarea>

Then you can use the DOM API: document.getElementById('my-textarea').focus() . 然后,您可以使用DOM API: document.getElementById('my-textarea').focus()

Or use jQuery: $('#my-textarea').focus() . 或使用jQuery: $('#my-textarea').focus()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM