这是我在我的一些网站上使用的代码.相应地应用您的HTML:
HTML:
<span>Font Size: </span>
<a href="#" onclick="decreaseFontSize();">
<img src="/images/minus.png" alt="Decrease Font Size" />
</a>
<a href="#" onclick="increaseFontSize();">
<img src="/images/plus.png" alt="Increase Font Size" />
</a>
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
var min=8;
var max=18;
function increaseFontSize() {
p = document.getElementById("[the id of container w/font you want to size]");
if(p.style.fontSize) {
var s = parseInt(p.style.fontSize.replace("px",""));
} else {
var s = 12;
}
if(s!=max) {
s += 1;
}
p.style.fontSize = s+"px"
}
function decreaseFontSize() {
p = document.getElementById("[the id of container w/font you want to size]");
if(p.style.fontSize) {
var s = parseInt(p.style.fontSize.replace("px",""));
} else {
var s = 12;
}
if(s!=min) {
s -= 1;
}
p.style.fontSize = s+"px"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
375 次 |
| 最近记录: |