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>

輸出

這將生成以下輸出 −

在單擊“本週有什麼考試?”按鈕之前 −

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

更新日期:2019 年 7 月 30 日

96 次瀏覽

開啟您的職業生涯

透過完成課程獲得認證

立即開始
廣告
© . All rights reserved.