如何使用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>热门推荐
10 校庆祝福语简短独特
11 祝福语大全短句简短英语
12 生日祝福语 简短独特潮
13 圣诞祝福语大全简短星座
14 生日祝福语 简短独特情话
15 生日祝福语宿舍舍友 简短
16 元旦英文祝福语大全简短
17 白族结婚祝福语简短大全
18 生日祝福语对妈妈简短