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