如何用 JavaScript 設定文字裝飾中的線條型別?


要設定文字裝飾中線條的型別,請使用 textDecorationLine 屬性。你可以嘗試執行以下程式碼,用 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.textDecorationLine = "overline";
         }
      </script>
   </body>
</html>

已更新日期:2020 年 6 月 23 日

115 次瀏覽

開啟你的 事業

完成課程獲得認證

開始
廣告
© . All rights reserved.