HTML DOM Section 对象
htmlweb developmentfront end technology更新于 2025/8/10 9:48:17
HTML DOM Section 对象表示 HTML 文档的 <section> 元素。
创建 section 对象
语法
以下是语法 −
document.createElement(“SECTION”);
示例
看一个 HTML DOM section 对象的示例 −
<!DOCTYPE html>
<html>
<head>
<style>
body{
text-align:center;
background-color:#fff;
color:#0197F6;
}
h1{
color:#23CE6B;
}
.drop-down{
width:35%;
border:2px solid #fff;
font-weight:bold;
padding:8px;
}
.btn{
background-color:#fff;
border:1.5px dashed #0197F6;
height:2rem;
border-radius:2px;
width:60%;
margin:2rem auto;
display:block;
color:#0197F6;
outline:none;
cursor:pointer;
}
</style>
</head>
<body>
<h1>DOM Section Object Demo</h1>
<button onclick="createSection()" class="btn">Create a section object</button>
<script>
function createSection() {
var sectionElement = document.createElement("SECTION");
sectionElement.innerHTML=" Hi! I'm a <section> element in HTML";
document.body.appendChild(sectionElement);
}
</script>
</body>
</html>
输出
这将产生以下输出 −


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

