บทนำ
แอตทริบิวต์ autocomplete ควบคุมฟีเจอร์เติมอัตโนมัติของเบราว์เซอร์ ใช้ได้ทั้ง <form> และ <input>
ค่าหลัก
| ค่า | คำอธิบาย |
on | เปิด (ค่าเริ่มต้น) - เติมจากประวัติ |
off | ปิด - ไม่เติมอัตโนมัติ |
ค่าเฉพาะเจาะจง (แนะนำกว่า on/off)
| ค่า | ใช้กับ |
name | ชื่อเต็ม |
given-name / family-name | ชื่อ / นามสกุล |
email | อีเมล |
username | ชื่อผู้ใช้ |
current-password | รหัสผ่านปัจจุบัน |
new-password | รหัสผ่านใหม่ (เสนอสร้าง) |
one-time-code | OTP |
address-line1, address-level1 (province), address-level2 (city), postal-code, country | ที่อยู่ |
cc-number, cc-name, cc-exp, cc-csc | บัตรเครดิต |
tel, tel-country-code, tel-national, tel-area-code, tel-local | เบอร์โทร |
ตัวอย่างโค้ด
<!DOCTYPE html>
<html>
<head>
<title>HTML Autocomplete Attribute</title>
</head>
<body>
<form action="" method="get" autocomplete="on">
รายละเอียด:<br><br>
ชื่อนักเรียน<br>
<input type="text" name="sname" autocomplete="name"><br>
อีเมล<br>
<input type="email" name="email" autocomplete="email"><br>
รหัสผ่าน<br>
<input type="password" name="pwd" autocomplete="current-password"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
แนวทางปฏิบัติที่ดี
- ใช้ค่าเฉพาะเจาะจง (name, email, tel) แทน on/off
- Password ใหม่ ใช้
new-password
- OTP ใช้
one-time-code
- Credit Card ใช้
cc-number など