HTML DOM Style textTransform 属性
htmlweb developmentfront end technology更新于 2025/6/11 5:00:17
DOM Style textTransform 属性返回 HTML 文档中元素文本的转换结果。
语法
以下是语法 −
返回 textTransform
object.style.textTransform
修改 textTransform
object.style.textTransform = “value”
值
此处,值可以为 -
| 值 | 说明 |
|---|---|
| inherit | 从其父元素继承此属性值。 |
| initial | 将此属性值设置为其默认值。 |
| none | 不对文本进行任何转换。 |
| uppercase | 将所有字符转换为大写。 |
| lowercase | 将所有字符转换为小写。 |
| capitalize | 将所有单词的第一个字符转换为大写。 |
示例
让我们看看样式 textTransform 属性的示例 −
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
background: lightblue;
height: 100vh;
}
p {
margin: 1.5rem auto;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
}
</style>
</head>
<body>
<h1>DOM Style textTransform Property Example</h1>
<p>Hi! I'm a paragraph element with some dummy text.</p>
<button onclick="add()" class="btn">Change textTransform</button>
<script>
function add() {
document.querySelector('p').style.textTransform = "uppercase";
}
</script>
</body>
</html>
输出
这将产生以下输出 −

点击"更改文本转换"按钮对段落文本应用转换 −

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

