HTML DOM 圖例物件
HTML DOM 圖例物件在 HTML 中表示<lagend> 元素。
語法
以下為語法 −
建立 <legend> 元素
var legendObject = document.createElement(“LEGEND”)
屬性
在此處,“圖例物件”具有的屬性如下 −
| 屬性 | 說明 |
|---|---|
| form | 它返回包含 legend 元素的封閉 form 的引用 |
示例
讓我們瞭解圖例 form 屬性的示例 −
<!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>輸出
這將生成以下輸出 −
在單擊“本週有什麼考試?”按鈕之前 −

選中“本週有什麼考試?”按鈕後 −

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP