HTML - DOM Style 物件 textTransform 屬性



HTML DOM Style 物件**textTransform**屬性設定或返回文字的大小寫。它將文字更改為大寫、小寫或首字母大寫。

語法

設定 textTransform 屬性
object.style.textTransform= "none | capitalize | uppercase | lowercase | initial | inherit";
獲取 textTransform 屬性
object.style.textTransform;

屬性值

描述
none 這是預設值,其中不轉換任何字元。
capitalize 它使每個單詞的第一個字元都大寫。
uppercase 它將所有書寫文字轉換為大寫。
lowercase 它將所有書寫文字轉換為小寫。
initial 它用於將此屬性設定為其預設值。
inherit 它用於繼承其父元素的屬性。

返回值

它返回一個字串值,表示元素中文字的轉換。

HTML DOM Style 物件“textTransform”屬性示例

以下示例將書寫文字轉換為小寫、大寫和首字母大寫。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object textTransform Property
    </title>
</head>
<body>
    <p>
        Click to transform text.
    </p>
    <button onclick="fun()">Capitalize</button>
    <button onclick="funTwo()">Lowercase</button>
    <button onclick="funThree()">Uppercase</button>
    <p id="transform">
        Welcome to Tutorials Point.
    </p>
    <script>
        function fun() {
            document.getElementById("transform")
                .style.textTransform = "capitalize";
        }
        function funTwo() {
            document.getElementById("transform")
                .style.textTransform = "lowercase";
        }
        function funThree() {
            document.getElementById("transform")
                .style.textTransform = "uppercase";
        }
    </script>
</body>
</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
textTransform 是 1 是 12 是 1 是 1 是 7
html_dom_style_object_reference.htm
廣告