现在的位置: 首页 > 综合 > 正文

通过JS变更页面字体的大小

2018年06月10日 ⁄ 综合 ⁄ 共 644字 ⁄ 字号 评论关闭

JS:

 

//========================= 设置字体大中小 start =============
function doZoom(size){
   var artibody = document.getElementById('artibody');
   if(!artibody){
    return;
   }
   var artibodyChild = artibody.childNodes;
   artibody.style.fontSize = size + 'px';
   //再对artibody div内的直接html节点设置fontSize属性
   for(var i = 0; i < artibodyChild.length; i++){
    if(artibodyChild[i].nodeType == 1){
     artibodyChild[i].style.fontSize = size + 'px';
    }
   }
}
//========================= 设置字体大中小 end =============

 

 

JSP:

 

<body id="artibody">
  <br />
  <DIV id="button_print" align="center">
  <a href="javascript:doZoom(16)">大</a>
  <a href="javascript:doZoom(14)">中</a>
  <a href="javascript:doZoom(12)">小</a>
  </DIV>

抱歉!评论已关闭.