แอตทริบิวท์ autofocus ใน HTML
แอตทริบิวท์ autofocus ใน HTML ใช้สำหรับหลายองค์ประกอบ และตั้งค่าโฟกัสที่องค์ประกอบเฉพาะนั้นเมื่อหน้าเว็บโหลด องค์ประกอบที่ประกอบด้วยแอตทริบิวท์ autofocus ได้แก่:
<button>, <input>, <select> และ <textarea>.
ตัวอย่าง
<!DOCTYPE html>
<html>
<body>
<h2>ผลลัพธ์</h2>
<form action="" accept-charset="ISO-8859-1">
<label for="stinfo">นักเรียน:</label> <input type="text" name="stinfo"><br>
<label for="sub">วิชา:</label> <input type="text" name="sub" autofocus><br>
<label for="rank">อันดับ:</label> <input type="number" name="rank"><br>
<label for="marks">คะแนน:</label> <input type="number" name="marks"><br><br>
<input type="submit">
</form>
</body>
</html>
ผลลัพธ์
ผลลัพธ์จะเป็นดังนี้ แสดงโฟกัสบน textbox ที่ 2 เนื่องจากเราตั้งค่า autofocus บน input text เดียวกัน:
