如何用 JavaScript 設定文字字型大小?


要設定字型大小,請使用 JavaScript 中的fontSize屬性。你可以嘗試執行以下程式碼,以使用 JavaScript 設定文字字型大小 −

示例

線上演示
<!DOCTYPE html>
<html>
   <body>
      <h1>Heading 1</h1>
      <p id = "myID">
         This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text.
         This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text.
      </p>
      <button type = "button" onclick = "display()">Set Font Family and Size</button>
      
      <script>
         function display() {
            document.getElementById("myID").style.fontFamily = "verdana,sans-serif";
            document.getElementById("myID").style.fontSize = "smaller";
         }
      </script>
      
   </body>
</html>

更新日期: 30-Jul-2019

799 次瀏覽

開啟你的 職業生涯

完成課程即可獲得認證

開始學習
廣告
© . All rights reserved.