When I first came to the company, the leaders assigned me simple tasks. . . . . Task
Once I was asked to write out the font size changing function of the article. I searched a lot online but nothing works! But hard work paid off and I found it! Take it out and share it!
Copy the code code as follows:
<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>
html part
Copy the code code as follows:
[Font size: <a href="javascript:SetFont(16)">Large</a> <a href="javascript:SetFont(14)">Medium</a> <a href="javascript:SetFont(12) ">Small</a>]
<div style="font-size:14px;" id="news_content">
Article content
</div>