autofocus 属性是一个布尔属性,autofocus 属性指定文本区域应该在页面加载时自动获得焦点。
在线示例
一个自动获得焦点的文本区域:
<textarea rows="4" cols="50" autofocus> At div.cn will learn how to make a website. We offer free tutorials in all web development technologies. </textarea>测试看看 ‹/›
浏览器兼容性
IEFirefoxOperaChromeSafari
Internet Explorer 10、Firefox、Opera、Chrome 和 Safari 支持 autofocus 属性。
注意:Internet Explorer 9 及更早版本支持 <textarea> 标签的 autofocus 属性。
定义和用法
autofocus 属性是一个布尔属性。
autofocus 属性指定文本区域应该在页面加载时自动获得焦点。
HTML 4.01 与 HTML5之间的差异
autofocus 属性是 HTML5 中 <textarea> 标签的新属性。
HTML 与 XHTML 之间的差异
在 XHTML 中,禁止属性简写,autofocus 属性必须定义为 <textarea autofocus="autofocus">。
语法
<textarea autofocus>HTML <textarea> 标签