แท็ก <output> ใน HTML5 แสดงผลลัพธ์ของการคำนวณหรือการกระทำของผู้ใช้
แอตทริบิวต์
| แอตทริบิวต์ | ค่า | คำอธิบาย |
|---|---|---|
| for | element IDs | รายการ ID ขององค์ประกอบที่ให้ค่าอินพุต |
| form | form ID | เชื่อมโยงกับฟอร์ม (วางนอกฟอร์มได้) |
| name | name | ชื่อขององค์ประกอบ |
ตัวอย่าง: คำนวณผลรวมแบบเรียลไทม์
<!DOCTYPE html> <html> <head> <title>HTML Output Tag</title> </head> <body> <form oninput="sumresult.value = parseInt(z1.value)+parseInt(z2.value)+parseInt(z3.value)"> <input type="range" name="z1" value="0" /> + <input type="number" name="z2" value="30" /> + <input type="number" name="z3" value="60" /><br /> ผลลัพธ์: <output name="sumresult"></output> </form> </body> </html>
ใช้ oninput บน form คำนวณทุกครั้งที่ค่าเปลี่ยน <output> มี semantic meaning ช่วย accessibility