HTML DOM blockquote 对象
htmlweb developmentfront end technology更新于 2024/6/11 11:24:17
HTML DOM blockquote 基本上代表 HTML 元素 <blockquote>。与 <q> 标签不同,<blockquote> 元素不添加任何引号。我们可以借助 blockquote 对象创建和访问 <blockquote> 属性。
语法
以下是语法 −
创建 blockquote 对象 −
var x = document.createElement("BLOCKQUOTE");
示例
让我们看一个 blockquote 对象的示例 −
<!DOCTYPE html>
<html>
<body>
<p>Click on the below button to create a blockquote object</p>
<button onclick="createBloc()">CREATE</button>
<script>
function createBloc() {
var x = document.createElement("BLOCKQUOTE");
var t = document.createTextNode("This is a random block quote.This is some sample text.");
x.setAttribute("cite", "http://www.examplesite.com");
x.setAttribute("id", "myQuote");
x.appendChild(t);
document.body.appendChild(x);
}
</script>
</body>
</html>
输出
这将产生以下输出 −

点击"创建" −

在上面的例子中 −
首先,我们创建了一个按钮 CREATE 来调用 createBloc() 函数。
<button onclick="createBloc()">CREATE</button>
函数 createBloc() 使用 document 对象的 createElement() 方法创建一个 <blockquote> 元素。然后,我们使用 document 对象的 createTextNode() 方法创建了一个包含文本的文本节点。我们使用 setAttribute() 方法为上面创建的 <blockquote> 元素添加了一些属性,例如 cite 和 id。最后,我们使用 appendChild() 方法将该元素作为子元素附加到文档主体中。
function createBloc() {
var x = document.createElement("BLOCKQUOTE");
var t = document.createTextNode("This is a random block quote.This is some sample text.");
x.setAttribute("cite", "http://www.examplesite.com");
x.setAttribute("id", "myQuote");
x.appendChild(t);
document.body.appendChild(x);
}
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

