HTML DOM 页脚对象


HTML DOM 页脚对象与 HTML <footer> 元素相关联。<footer> 元素是一个语义标记类型,在 HTML5 中引入。使用 Footer 对象,我们可以分别使用 createElement() 和 getElementById() 方法创建和获取 <footer> 元素。

语法

以下是语法 −

创建一个页脚对象 −

var p = document.createElement("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>

Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.

输出

这将生成以下输出 −

单击 CREATE 按钮 −

在上面的示例中 −

我们首先创建了一个按钮 CREATE,用户单击后将执行 createFoot() 方法。

<button onclick="createFoot()">CREATE</button>

createFoot() 方法使用 document 对象的 createElement() 方法创建页脚元素。然后使用 appendChild() 方法将页脚元素附加到文档正文,并使用 createElement() 方法创建另一个 <p> 元素。

然后使用 document 对象的 createTextNode() 方法创建文本节点。然后使用段落上的 appendChild() 方法将文本节点附加到段落。最后将段落及其文本节点作为页脚元素的子元素附加,使用页脚元素上的 appendChild() 方法 −

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);
}

更新日期: 19-Feb-2021

559 次浏览

开启你的 职业生涯

完成课程并获得认证

开始学习
广告