如何用 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>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式語言
C++
C#
MongoDB
MySQL
Javascript
PHP