HTML <input> autofocus 属性
标签" href="tag-main.html"><main>
<map>
<mark>
<menu>
<meta>
<meter>
<nav>
<noframes>
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<pre>
<html>
<picture>
<progress>
<q>
<rp>
<rt>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<small>
<source>
<span>
<strike>
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<textarea>
< template>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<track>
<tt>
<u>
<ul>
<var>
<video>
<wbr>
HTML <input> autofocus 属性
实例
设置 "First name" 输入字段在页面加载时自动获得焦点:
<form action="demo_form.html">
First name: <input type="text" name="fname" autofocus><br>
Last name: <input type="text" name="lname"><br>
<input type="submit">
</form>
First name: <input type="text" name="fname" autofocus><br>
Last name: <input type="text" name="lname"><br>
<input type="submit">
</form>
浏览器支持
Internet Explorer 10、Firefox、Opera、Chrome 和 Safari 支持 autofocus 属性。
注意:Internet Explorer 9 及之前的版本不支持 <input> 标签的 autofocus 属性。
定义和用法
autofocus 属性是一个布尔属性。
autofocus 属性规定当页面加载时 <input> 元素应该自动获得焦点。
HTML 4.01 与 HTML5之间的差异
autofocus 属性是 HTML5 中的新属性。
HTML 与 XHTML 之间的差异
在 XHTML 中,禁止属性最小化,autofocus 属性必须定义为 <input autofocus="autofocus" />。
语法
<input autofocus>
HTML <input> 标签