HTML - DOM樣式物件textDecoration屬性



HTML DOM樣式物件textDecoration屬性是用於設定textDecorationLine、textDecorationStyle和textDecorationColor屬性的簡寫屬性。

語法

設定textDecoration屬性
object.style.textDecoration= "text-decoration-color text-decoration-line text-decoration-style | initial | inherit"
獲取textDecoration屬性
object.style.textDecoration;

屬性值

描述
color 設定文字裝飾顏色。
line 設定要使用的文字裝飾線的型別。
style 設定文字裝飾樣式。
initial 用於將此屬性設定為其預設值。
inherit 用於繼承其父元素的屬性。

返回值

它返回一個字串值,表示元素的textDecoration屬性,例如text-decoration-color、text-decoration-line和text-decoration-style。

HTML DOM樣式物件“textDecoration”屬性示例

以下示例為p元素設定textDecoration屬性。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object textDecoration Property
    </title>
</head>
<body>
    <p>Click to change text decoration.</p>
    <button onclick="fun()">Underline</button>
    <button onclick="funTwo()">Overline</button>
    <div id="decor">
        <p>
            See the effects here.
        </p>
    </div>
    <script>
        function fun() {
            document.getElementById("decor")
                .style.textDecoration = "underline solid red"
        }
        function funTwo() {
            document.getElementById("decor")
                .style.textDecoration = "overline double green"
        }
    </script>
</body>
</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
textDecoration 是 1 是 12 是 1 是 1 是 12.1
html_dom_style_object_reference.htm
廣告