如何使用 JavaScript 设置文本的装饰?

javascriptobject oriented programmingfront end technology更新于 2024/6/21 16:44:17

使用 JavaScript 中的 textDecoration属性来装饰文本。您可以使用此属性为文本添加下划线。

示例

您可以尝试运行以下代码,使用 JavaScript 设置文本的装饰 −

<!DOCTYPE html>
<html>
   <body>
      <div id = "myText">This is demo text.</div><br>

      <button onclick = "display()">Set Text Decoration</button>
      <script>
         function display() {
            document.getElementById("myText").style.textDecoration = "underline";
         }
      </script>
   </body>
</html>

相关文章


有用资源