用js设置html标签的字体大小:
1、html页面代码:
<!DOCTYPE html ">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JS 控制网页字体放大缩小实例</title>
</head>
<body>
<input onclick="setFontsize(0,'Content')" type="button" value="缩小字体">
<input onclick="setFontsize(1,'Content')" type="button" value="放大字体"><DIV ID="Content">
这是一个测试字体大小的页面
</DIV>
</body>
</html>
2、js代码:
var initial_fontsize = 10; //初始化大小
var initial_lineheight = 18; //初始化行高
设置字体的方法:
function setFontsize(type,objname){
var whichEl = document.getElementById(objname);
if (whichEl!=null) {
if (type==1){
if(initial_fontsize<64){
whichEl.style.fontSize=(++initial_fontsize)+'pt';
whichEl.style.lineHeight=(++initial_lineheight)+'pt';
}
}else {
if(initial_fontsize>8){
whichEl.style.fontSize=(--initial_fontsize)+'pt';
whichEl.style.lineHeight=(--initial_lineheight)+'pt';
}
}
}
}
温馨提示:答案为网友推荐,仅供参考