HTML中的autofocus屬性用於指定元素在頁麵加載時應該獲得焦點。這是一個布爾屬性。
注意:它僅支持以下元素:<按鈕>,<輸入>,<選擇>和<文本區域>
用法:
<elementName autofocus>
範例1:
<!DOCTYPE html>
<html>
<head>
<title>HTML autofocus Attribute</title>
</head>
<body style = "text-align:center;">
<h1 style = "color:green;">GeeksforGeeks</h1>
<h2>HTML autofocus Attribute</h2>
<form>
<label>First Name:
<input type="text" autofocus
placeholder = "Enter Name">
</label>
</form>
</body>
</html>
輸出:
範例2:
<!DOCTYPE html>
<html>
<head>
<title>HTML autofocus Attribute</title>
</head>
<body style = "text-align:center;">
<h1 style = "color:green;">GeeksforGeeks</h1>
<h2>HTML autofocus Attribute</h2>
<textarea rows="3" cols="30" autofocus>
A computer science portal for geeks.
</textarea>
</body>
</html>
輸出:
支持的瀏覽器:下麵列出了autofocus屬性支持的瀏覽器:
- 穀歌瀏覽器5.0
- Internet Explorer 10.0
- Firefox 4.0
- Opera 9.6
- 蘋果Safari 5.0
相關用法
- HTML <button> autofocus屬性用法及代碼示例
- HTML <input> autofocus屬性用法及代碼示例
- HTML <select> autofocus屬性用法及代碼示例
- HTML <textarea> autofocus屬性用法及代碼示例
- HTML Textarea autofocus用法及代碼示例
- HTML Input Time autofocus用法及代碼示例
- HTML Button autofocus用法及代碼示例
- HTML Input Date autofocus用法及代碼示例
- HTML Input Datetime autofocus用法及代碼示例
- HTML Input Checkbox autofocus用法及代碼示例
- HTML Input Email autofocus用法及代碼示例
- HTML Input Password autofocus用法及代碼示例
- HTML Input Text autofocus用法及代碼示例
- HTML Input Number autofocus用法及代碼示例
- HTML Input Reset autofocus用法及代碼示例
- HTML Input Search autofocus用法及代碼示例
- HTML Input Range autofocus用法及代碼示例
- HTML Input Week autofocus用法及代碼示例
- HTML Input Month autofocus用法及代碼示例
- HTML Input URL autofocus用法及代碼示例
- HTML Input Radio autofocus用法及代碼示例
- HTML Input Button autofocus用法及代碼示例
- HTML Input FileUpload autofocus用法及代碼示例
- HTML Input Color autofocus用法及代碼示例
注:本文由純淨天空篩選整理自Vishal Chaudhary 2大神的英文原創作品 HTML | autofocus Attribute。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。