Latest web development tutorials

HTML DOM Style textDecoration 屬性

Style 對象參考手冊 Style對象

定義和用法

textDecoration 屬性設置或返回一個或多個的文本修飾。

提示:如需為元素規定一個以上的修飾類型,請指定一個空格分隔的列表。

語法

設置textDecoration 屬性:

Object.style.textDecoration="none|underline|overline|line-through|blink|inherit"

返回textDecoration 屬性:

Object.style.textDecoration

描述
none 默认。定义标准的文本。
underline 定义文本下的一条线。
overline 定义文本上的一条线。
line-through 定义穿过文本的一条线。
inherit textDecoration 属性的值从父元素继承。


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要瀏覽器都支持textDecoration 屬性。

注意: 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.textDecoration="underline overline";
}
</script>
</head>
<body>

<p id="p1">这是一些文本。</p>
<br>
<button type="button" onclick="displayResult()">装饰文本</button>

</body>
</html>

嘗試一下»


Style 對象參考手冊 Style對象