如何用 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.