HTML DOM textTransform 屬性
定義和用法
textTransform 屬性會(huì)改變?cè)刂械淖帜复笮?xiě),而不論源文檔中文本的大小寫(xiě)。
語(yǔ)法:
Object.style.textTransform="none|capitalize|uppercase|lowercase|inherit"
可能的值
| 值 | 描述 |
|---|---|
| none | 默認(rèn)。定義帶有小寫(xiě)字母和大寫(xiě)字母的標(biāo)準(zhǔn)的文本。 |
| capitalize | 文本中的每個(gè)單詞以大寫(xiě)字母開(kāi)頭。 |
| uppercase | 定義僅有大寫(xiě)字母。 |
| lowercase | 定義無(wú)大寫(xiě)字母,僅有小寫(xiě)字母。 |
實(shí)例
本例把每個(gè)單詞的第一個(gè)字母轉(zhuǎn)換為大寫(xiě):
<html>
<head>
<script type="text/javascript">
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()">Convert text</button>
</body>
</html>