Style textDecoration 屬性

定義和用法
textDecoration 屬性設置或返回一個或多個的文本修飾。
提示:如需為元素規定一個以上的修飾類型,請指定一個空格分隔的列表。
語法
設置 textDecoration 屬性:
Object.style.textDecoration="none|underline|overline|line-through|blink|inherit"
返回 textDecoration 屬性:
Object.style.textDecoration
值 | 描述 |
---|---|
none | 默認。定義標準的文本。 |
underline | 定義文本下的一條線。 |
overline | 定義文本上的一條線。 |
line-through | 定義穿過文本的一條線。 |
inherit | textDecoration 屬性的值從父元素繼承。 |
流覽器支持
所有主要流覽器都支持 textDecoration 屬性。
注意:IE7 及更早的版本不支持 "inherit" 值。IE8 只有規定了 !DOCTYPE 才支持 "inherit"。IE9 支持 "inherit"。
實例
實例
裝飾文本:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.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>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.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>
