Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> HTML

วิธาใช้แอตทริบิวต์ Autocomplete ใน HTML


บทนำ

แอตทริบิวต์ autocomplete ควบคุมฟีเจอร์เติมอัตโนมัติของเบราว์เซอร์ ใช้ได้ทั้ง <form> และ <input>

ค่าหลัก

ค่าคำอธิบาย
onเปิด (ค่าเริ่มต้น) - เติมจากประวัติ
offปิด - ไม่เติมอัตโนมัติ

ค่าเฉพาะเจาะจง (แนะนำกว่า on/off)

ค่าใช้กับ
nameชื่อเต็ม
given-name / family-nameชื่อ / นามสกุล
emailอีเมล
usernameชื่อผู้ใช้
current-passwordรหัสผ่านปัจจุบัน
new-passwordรหัสผ่านใหม่ (เสนอสร้าง)
one-time-codeOTP
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 など