HTML DOM HR 对象
htmldomweb developmentfront end technology更新于 2025/12/27 22:36:17
HTML DOM HR 对象表示 HTML 文档的 <hr> 元素。
创建 hr 对象 −
语法
以下是语法 −
document.createElement(“HR”);
让我们看一个 hr 对象的示例 −
示例
<!DOCTYPE html>
<html>
<style>
body {
text-align: center;
background-color: #fff;
color: #0197F6;
}
h1 {
color: #23CE6B;
}
.btn {
background-color: #fff;
border: 2px solid #0197F6;
height: 2rem;
width: 40%;
margin: 2rem auto;
display: block;
color: #0197F6;
outline: none;
cursor: pointer;
border-radius: 20px;
}
hr {
border-color: #db133a;
}
</style>
<body>
<h1>DOM hr Object Demo</h1>
<button onclick="createHr()" class="btn">Create a hr object</button>
<script>
function createHr() {
var insElement = document.createElement("HR");
document.body.appendChild(insElement);
}
</script>
</body>
</html>
输出

点击"创建 hr 对象"按钮来创建 hr 对象。

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

