【发布时间】:2022-01-09 19:42:25
【问题描述】:
我正在尝试使用 javascript 增加页面的字体大小。 我有这段代码,但它没有按预期工作。有人可以检查我做错了什么吗?
这里是 HTML 和 javascript 代码:
<body>
<center>
<button type="button"
onclick="changeSizeByBtn(15)" name="btn1">
-A
</button>
<button type="button"
onclick="changeSizeByBtn(20)" name="btn2">
A
</button>
<button type="button" onclick="changeSizeByBtn(25)"
name="btn3">
A+
</button>
<br /><br />
<div style="padding: 20px; margin: 50px;
font-size: 20px; border: 5px solid red;"
id="container" class="container">
<p>
I need to increase this texts here by clicking on A+ button and decrease them by clicking -A button above.<br>
Or increase and decrease them by draging the range below to left or right<br> What is wrong in my code?
</p>
</div>
<input type="range" min="10" max="100" id="slider"
onchange="changeSizeBySlider()" value="40" />
</center>
<script>
var cont = document.getElementById("container");
function changeSizeByBtn(size) {
// Set value of the parameter as fontSize
cont.style.fontSize = size;
}
function changeSizeBySlider() {
var slider = document.getElementById("slider");
// Set slider value as fontSize
cont.style.fontSize = slider.value;
}
</script>
【问题讨论】:
标签: javascript html button font-size