前言
html+js点击大中小按钮设置文章内容字体大小
实例代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>于飞SEO前端实例</title>
<script type="text/javascript">
function SetFont(size){
var divBody=document.getElementById("news_content");
if(!divBody){return;}
divBody.style.fontSize=size+"px";
var divChildBody=divBody.childNodes;
for(var i=0;i<divChildBody.length;i++){
if(divChildBody[i].nodeType==1){
divChildBody[i].style.fontSize = size + "px";
}
}
}
</script>
</head>
<body>
字号:
<a href="javascript:SetFont(18)">大</a>
<a href="javascript:SetFont(14)">中</a>
<a href="javascript:SetFont(10)">小</a>
<div style="font-size:14px;" id="news_content">于飞SEO,于飞工作室文章内容</div>
</body>
</html>