HTML DOM 锚点 rel 属性
htmlweb developmentfront end technology更新于 2024/6/11 17:48:17
HTML DOM 锚点 rel 属性返回链接的 rel 属性。rel 属性描述了当前正在运行的文档与链接文档之间的关联。
语法
以下是 − 的语法
a) 返回 rel 属性 −
anchorObject.rel
b) 设置 rel 属性
anchorObject.rel = "value"
示例
让我们看一个 HTML DOM 锚点 rel 属性的示例 −
<!DOCTYPE html>
<html>
<body>
<h1>Example</h1>
<p><a id="anchorExample" rel="Rel Property" href="https://www.examplesite.com/">
Anchor Rel Property</a></p>
<p>Click on the button</p>
<button onclick="display()">Click me!</button>
<p id="show"></p>
<script>
function display() {
var docs = document.getElementById("anchorExample").rel;
document.getElementById("show").innerHTML = docs;
}
</script>
</body>
</html>
输出
这将产生以下输出 −

点击"点击我!"按钮即可获取 HTML DOM 锚点的 rel 属性 −

在上面的例子中 −
我们采用了一个带有 rel 属性的锚标签,用于指定与链接文档的关系类型,在上面的代码中,链接文档为 https://www.examplesite.com/
<p> <a id="anchorExample" rel="Rel Property" href="https://www.examplesite.com/">Anchor Rel Property</a> </p>
然后,我们创建了一个名为"Click Me"的按钮来执行 display 函数 −
<button onclick="display()>>Click me!</button>
display 函数获取 id 为"Anchor example"的元素的 rel 属性 −
function display() {
var docs = document.getElementById("anchorExample").rel;
document.getElementById("show").innerHTML = docs;
}
然后我们创建了一个名为"Click Me"的按钮来执行显示功能 −
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

