如何使用 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>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP