HTML DOM Legend 对象

htmlweb developmentfront end technology更新于 2025/7/11 18:52:17

HTML DOM Legend 对象在 HTML 中表示 <lagend> 元素。

语法

以下是语法 −

创建 <legend> 元素

var legendObject = document.createElement(“LEGEND”)

属性

此处,“LegendObject” 可以具有以下属性 −

属性描述
表单返回包含图例元素的封闭表单的引用

示例

让我们看一个图例表单属性的示例 −

<!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>

输出

这将产生以下输出 −

点击"本周有哪些考试?"按钮前 −

查看"本周有哪些考试?"按钮后 −


相关文章


有用资源