อ็อบเจกต์ Legend แทนอีลีเมนต์ <legend> (หัวข้อของ fieldset) ใน HTML DOM
ไวยากรณ์ (Syntax)
var legendObject = document.createElement("LEGEND")
คุณสมบัติ
| คุณสมบัติ | คำอธิบาย |
|---|---|
| form | คืนค่าการอ้างอิงถึงฟอร์ม (<form>) ที่ครอบคลุม legend element นี้ |
ตัวอย่างการใช้งาน (คุณสมบัติ form)
ตัวอย่างด้านล่างดึง ID ของฟอร์มที่ครอบคลุม legend:
<!DOCTYPE html>
<html>
<head>
<title>Legend form</title>
<style>
form { width: 70%; margin: 0 auto; text-align: center; }
* { padding: 2px; margin: 5px; }
input[type="button"] { border-radius: 10px; }
</style>
</head>
<body>
<form id="Mid-Term">
<fieldset>
<legend id="legendForm">Legend-form</legend>
<label for="WeekSelect">Examination Week: <input type="week" value="2019-W36"> </label>
<input type="button" onclick="showExamination()" value="What exams are in this week?">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var legendForm = document.getElementById("legendForm");
function showExamination() {
divDisplay.textContent = 'Examinations: ' + legendForm.form.id;
}
</script>
</body>
</html>
ผลลัพธ์
ก่อนคลิกปุ่ม: แสดงฟอร์มพร้อม legend
หลังคลิกปุ่ม "What exams are in this week?": แสดง "Examinations: Mid-Term" (ID ของฟอร์มที่ครอบคลุม)
หมายเหตุ: รูปภาพตัวอย่างจากต้นฉบับไม่ได้รวมอยู่ในเนื้อหานี้