HTML DOM 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>本教程(w3big.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>本教程(w3big.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>
嘗試一下»
Style對象