HTML DOM Footer 对象
htmlweb developmentfront end technology更新于 2024/5/29 6:04:17
HTML DOM Footer 对象与 HTML <footer> 元素关联。<footer> 元素是一种语义标签,在 HTML5 中引入。使用 Footer 对象,我们可以分别使用 createElement() 和 getElementById() 方法创建和获取 <footer> 元素。
语法
以下是语法 −
创建 footer 对象 −
var p = document.createElement("FOOTER");
示例
让我们来看一个 Footer 对象的示例 −
<!DOCTYPE html>
<html>
<head>
<script>
function createFoot() {
var f = document.createElement("FOOTER");
document.body.appendChild(f);
var p = document.createElement("P");
var txt = document.createTextNode("Copyright ©, 2019");
p.appendChild(txt);
f.appendChild(p);
}
</script>
</head>
<body>
<h1>Footer object example</h1>
<p>Create a footer for this webpage by clicking the below button</p>
<button onclick="createFoot()">CREATE</button>
</body>
</html>
输出
这将产生以下输出 −

点击"创建"按钮时 −

在上面的例子中 −
我们首先创建了一个"创建"按钮,当用户点击该按钮时,它将执行 createFoot() 方法。
<button onclick="createFoot()>CREATE</button>
createFoot() 方法使用 document 对象的 createElement() 方法创建一个 footer 元素。然后,我们使用 appendChild() 方法将 footer 元素附加到文档主体,并创建另一个 <p>元素,使用 createElement() 方法。
然后使用 document 对象的 createTextNode() 方法创建一个文本节点。然后使用段落的 appendChild() 方法将该文本节点附加到段落。最后,使用 footer 元素的 appendChild() 方法将段落和文本节点作为 footer 元素的子元素附加 −
function createFoot() {
var f = document.createElement("FOOTER");
document.body.appendChild(f);
var p = document.createElement("P");
var txt = document.createTextNode("Copyright ©, 2019");
p.appendChild(txt);
f.appendChild(p);
}
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

