如何使用JavaScript在文本装饰中设置线条样式?

要在JavaScript中设置线条的样式,请使用textDecorationStyle 属性。您可以为线条样式设置下划线,双线或上划线等。

示例

您可以尝试运行以下代码以使用JavaScript在文本修饰中返回行的样式-

<!DOCTYPE html>
<html>
   <body>
      <div id = "myText" style = "text-decoration: underline;">
         This is demo text.
      </div>
      <br>
      <button onclick = "display()"> Set Text Decoration </button>
      <script>
         function display() {
            document.getElementById("myText").style.textDecorationColor = "red";
            document.getElementById("myText").style.textDecorationStyle = "double";
         }
      </script>
   </body>
</html>