Style textTransform 屬性

定義和用法
textTransform 屬性設置或返回文本的大小寫。
語法
設置 textTransform 屬性:
Object.style.textTransform="none|capitalize|uppercase|lowercase|inherit"
返回 textTransform 屬性:
Object.style.textTransform
值 | 描述 |
---|---|
none | 默認。沒有被轉換的字元。 |
capitalize | 每個單詞的首字元轉換為大寫。 |
uppercase | 所有字元都轉換為大寫。 |
lowercase | 所有字元都轉換為小寫。 |
inherit | textTransform 屬性的值從父元素繼承。 |
流覽器支持
所有主要流覽器都支持 textTransform 屬性。
注意:IE7 及更早的版本不支持 "inherit" 值。IE8 只有規定了 !DOCTYPE 才支持 "inherit"。IE9 支持 "inherit"。
實例
實例
把每個單詞的首字母轉換為大寫:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.textTransform="capitalize";
}
</script>
</head>
<body>
<p id="p1">This is some text.</p>
<br>
<button type="button" onclick="displayResult()">轉換文本首字元為大寫</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.textTransform="capitalize";
}
</script>
</head>
<body>
<p id="p1">This is some text.</p>
<br>
<button type="button" onclick="displayResult()">轉換文本首字元為大寫</button>
</body>
</html>
