HTML DOM 上标对象
htmlweb developmentfront end technology更新于 2025/7/17 17:16:17
HTML DOM 上标对象表示 HTML 文档的 <sup> 元素。
让我们看看如何创建上标对象 −
语法
以下是语法 −
document.createElement(“SUP”);
示例
让我们看一个上标对象的示例 −
<!DOCTYPE html>
<html>
<head>
<style>
body {
text-align: center;
background-color: #fff;
color: #0197F6;
}
h1 {
color: #23CE6B;
}
.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 superscript Object Demo</h1>
<button onclick="createSup()" class="btn">Create a superscript object</button>
<script>
function createSup() {
var supElement = document.createElement("SUP");
supElement.innerHTML = "This is a superscript element"
document.body.appendChild(supElement);
}
</script>
</body>
</html>
输出
这将产生以下输出 −

点击"创建上标对象"按钮,创建一个上标对象。点击按钮后可见的文本为上标文本,显示在正常行上方半个字符处。−

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

