如何添加默认文本大小功能-Javascript [英] How Add Default Text Size Function - Javascript
本文介绍了如何添加默认文本大小功能-Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现以下用于增加和减小字体大小的脚本,但是没有人知道如何对默认字体执行该功能吗?
I found the following script for increase and decrease font size but does anyone have any idea how to do the function for default font?
var min=8;
var max=18;
function increaseFontSize() {
var p = document.getElementsByTagName('div');
for(i=0;i<p.length;i++) {
if(p[i].style.fontSize) {
var s = parseInt(p[i].style.fontSize.replace("px",""));
} else {
var s = 12;
}
if(s!=max) {
s += 1;
}
p[i].style.fontSize = s+"px"
}
}
function decreaseFontSize() {
var p = document.getElementsByTagName('div');
for(i=0;i<p.length;i++) {
if(p[i].style.fontSize) {
var s = parseInt(p[i].style.fontSize.replace("px",""));
} else {
var s = 12;
}
if(s!=min) {
s -= 1;
}
p[i].style.fontSize = s+"px"
}
}
推荐答案
function resetToDefaultFontSize() {
var p = document.getElementsByTagName('div');
for(i=0;i<p.length;i++) {
p[i].style.fontSize = "12px";
}
}
注意:jQuery可以将所有这些功能分成3个单行代码,因此您可能需要对其进行研究.
Note: jQuery could make all these functions into 3 one-liners, so you might want to look into it.
这篇关于如何添加默认文本大小功能-Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文