HTML - DOM Style 物件 textDecorationStyle 屬性



HTML DOM Style 物件的 **textDecorationStyle** 屬性設定或返回文字裝飾線的樣式,例如可以顯示為實線、虛線、點線或波浪線。

語法

設定 textDecorationStyle 屬性
object.style.textDecorationStyle= "solid | double | dotted | dashed | wavy | initial | inherit";
獲取 textDecorationStyle 屬性
object.style.textDecorationStyle;

屬性值

描述
solid 這是預設值,顯示實線。
double 顯示雙線。
dotted 顯示點線。
dashed 顯示虛線。
wavy 顯示波浪線。
initial 用於將此屬性設定為其預設值。
inherit 用於繼承其父元素的屬性。

返回值

它返回一個字串值,表示元素的文字裝飾樣式屬性。

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

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

將 textDecorationStyle 設定為“double”和“dotted”

以下示例將 p 元素的文字裝飾樣式設定為雙線和點線。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object textDecorationStyle Property
    </title>
    <style>
        #decorstyle {
            text-decoration: overline green;
        }
    </style>
</head>
<body>
    <p>
        Click to change text decoration styles.
    </p>
    <button onclick="fun()">Double</button>
    <button onclick="funTwo()">Dotted</button>
    <p id="decorstyle">
        Welcome to Tutorials Point
    </p>
    <script>
        function fun() {
            document.getElementById("decorstyle")
                .style.textDecorationStyle = "double";
        }
        function funTwo() {
            document.getElementById("decorstyle")
                .style.textDecorationStyle = "dotted";
        }
    </script>
</body>
</html>

將 textDecorationStyle 設定為“dashed”和“wavy”

以下示例將 p 元素的文字裝飾樣式設定為虛線和波浪線。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object textDecorationStyle Property
    </title>
    <style>
        #decorstyle {
            text-decoration: overline green;
        }
    </style>
</head>
<body>
    <p>
        Click to change text decoration styles.
    </p>
    <button onclick="fun()">Dashed</button>
    <button onclick="funTwo()">Wavy</button>
    <p id="decorstyle">
        Welcome to Tutorials Point
    </p>
    <script>
        function fun() {
            document.getElementById("decorstyle")
                .style.textDecorationStyle = "dashed";
        }
        function funTwo() {
            document.getElementById("decorstyle")
                .style.textDecorationStyle = "wavy";
        }
    </script>
</body>
</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
textDecorationStyle 是 57 是 79 是 36 是 12.1 是 44
html_dom_style_object_reference.htm
廣告