Javascript 关注文本区域

Javascript 关注文本区域,javascript,Javascript,我将如何在javascript中执行以下操作: <textarea onload="focus">Here is some text</textarea> 这里有一些文本 基本上,我希望关注textarea字段,并且我希望在html标记中这样做。尝试自动聚焦属性: <textarea autofocus> At w3schools.com you will learn how to make websites. </textarea>

我将如何在javascript中执行以下操作:

<textarea onload="focus">Here is some text</textarea>
这里有一些文本

基本上,我希望关注textarea字段,并且我希望在html标记中这样做。

尝试自动聚焦属性:

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

在w3schools.com,您将学习如何制作网站。

您需要提供一些方法来选择文本区域,比如ID:

然后可以使用DOM API:
document.getElementById('my-textarea').focus()

或者使用jQuery:
$(“#我的文本区域”).focus()