如何用 JavaScript 將字型設定為小寫字母顯示?


若要將字型設定為小寫字母,請使用 fontVariant 屬性。

示例

你可以嘗試執行以下程式碼,使用 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 Font Variant</button>
      <script>
         function display() {
            document.getElementById("myID").style.fontFamily = "verdana,sans-serif";
            document.getElementById("myID").style.fontVariant = "small-caps";
         }
      </script>
   </body>
</html>

更新於:23-6 月-2020

150 次瀏覽

開啟您的職業生涯

完成課程後獲得認證

開始
廣告