HTML DOM 小对象
htmlweb developmentfront end technology更新于 2025/9/27 17:48:17
HTML DOM 小对象与 HTML <small> 元素关联。我们可以分别使用 createElement() 和 getElementById() 方法创建和访问小元素。
语法
以下是语法 −
创建小对象 −
var s= document.createElement("SMALL");
示例
让我们看一个关于小对象的示例 −
<!DOCTYPE html>
<html>
<body>
<h1>Small object example</h1>
<p>Create a small element containing some text by clicking the below button</p>
<button onclick="CreateSmall()">CREATE</button>
<p>This is normal text</p>
<script>
function CreateSmall() {
var s = document.createElement("SMALL");
var txt = document.createTextNode("This is small text");
s.appendChild(txt);
document.body.appendChild(s);
}
</script>
</body>
</html>
输出
这将产生以下输出 −

点击"创建"按钮 −

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

