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

แอตทริบิวท์ autofocus ของ <textarea> ใน HTML


แอตทริบิวท์ autofocus ของ <textarea> ใน HTML

แอตทริบิวท์ autofocus ขององค์ประกอบ <textarea> ใช้สำหรับตั้งค่า autofocus ให้กับ textarea เองเมื่อหน้าเว็บโหลด แอตทริบิวท์ autofocus สำหรับ <textarea> ถูกนำมาใช้ใน HTML5

รูปแบบการใช้งานมีดังนี้:

<textarea autofocus>

ตัวอย่าง

<!DOCTYPE html>
<html>
<body>
  <h2>คำถามสัมภาษณ์</h2>
  <p>ทำไมคุณจึงต้องการไปทำงานโปรไฟล์ Technical Writer? (100 คำ)</p>
  <textarea rows="6" cols="70" autofocus> เขียนคำตอบใน 100 คำเท่านั้น... </textarea>
  <p>จุดแข็งของคุณคืออะไร? (50 คำ)</p>
  <textarea rows="4" cols="70" autofocus> เขียนคำตอบใน 50 คำเท่านั้น... </textarea>
</body>
</html>

ผลลัพธ์

แอตทริบิวท์ autofocus ของ <textarea> ใน HTML

ในตัวอย่างข้างต้น เราได้ตั้งค่า textarea สองอัน:

<textarea rows="6" cols="70" autofocus> เขียนคำตอบใน 100 คำเท่านั้น... </textarea> <p>จุดแข็งของคุณคืออะไร? (50 คำ)</p> <textarea rows="4" cols="70" autofocus> เขียนคำตอบใน 50 คำเท่านั้น... </textarea>

หนึ่งใน textarea เราตั้งค่าด้วย autofocus ตอนนี้เมื่อใดก็ตามที่หน้าเว็บโหลด โฟกัสและเคอร์เซอร์จะมองเห็นได้อัตโนมัติใน textarea แรก:

<textarea rows="6" cols="70" autofocus>