HTML DOM Style textDecorationColor 属性

htmlweb developmentfront end technology更新于 2025/6/9 8:12:17

DOM Style textDecorationColor 属性用于返回并修改 HTML 文档中元素文本装饰的颜色。

语法

以下是语法 −

  • 返回 textDecorationColor

object.style.textDecorationColor
  • 修改 textDecorationColor

object.style.textDecorationColor = “color”

示例

让我们看一个 Style textDecorationColor 属性的示例 −

<!DOCTYPE html>
<html>
<head>
<style>
   body {
      color: #000;
      background: lightblue;
      height: 100vh;
   }
   p {
      margin: 1.5rem auto;
      text-decoration: line-through;
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
   }
</style>
</head>
<body>
<h1>DOM Style textDecorationColor Property Example</h1>
<p>This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text.</p>
<button onclick="add()" class="btn">Change textDecorationColor</button>
<script>
   function add() {
      document.querySelector('p').style.textDecorationColor = "#db133a";
   }
</script>
</body>
</html>

输出

这将产生以下输出 −

点击"更改文本装饰颜色"按钮可更改贯穿段落文本的颜色。


相关文章


有用资源