HTML DOM 圖例 form 屬性


HTML DOM 圖例 form 屬性返回 legend 標籤關聯表單的引用。

語法

以下是語法 −

返回對form 物件的引用

legendObject.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>

輸出

將產生以下輸出 −

點選‘本週有哪些考試?’按鈕之前 −

選中‘本週有哪些考試?’按鈕之後 −

更新於: 30-Jul-2019

97 次瀏覽

開始你的職業生涯

透過完成課程獲取認證

開始
廣告
© . All rights reserved.