JS Set Font Size code

Source: Internet
Author: User

Web effects set Font size code
Here to provide one or two JS set font size Oh, one is set up large and small three font size, one is based on the user input 1-7 font size can confirm the size of the JS code.

<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.111cn.net/tr/xhtml1/dtd/xhtml1-
Transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<style>
#content {font-size:12px;
line-height:200%;
padding:10px;
}
</style>
<script language= "Web Effects" >
function SetFont (size)
{
var obj;
Obj=document.getelementbyid ("content");
Obj.style.fontsize=size;
Obj.style.color= "#ff0000";
}
</script>
<body>
<div> font: <a href= "#" onclick= "Javascript:setfont (' 12px ')" > Small </a><a href= "#" onclick= "javascript : SetFont
(' 18px '); " > </a><a href= "#" onclick= "Javascript:setfont (' 24px ');" > Big </a></div>
<div id= "Content" >
Http://www.111cn.net welcome everyone to visit.
</div>
</body>

Method Two

<script>
function Wahaha ()
{
var fontsize = parseint (document.getElementById (' Tbox '). value,10);
if (isNaN (fontsize) | | | fontsize>6 | | fontsize<1)
{
Alert (' Please enter 1-7 direct digits ');
Return
}
var sp = document.getElementById (' span1 ');
var txt = sp.innertext;
var Objfont = document.createelement ("h" +fontsize);
Objfont.innertext = txt;
sp.innerhtml = "";
Sp.appendchild (Objfont);
}
</script>
<body>
<span id= "Span1" > Last night the Stars last night, painting building west Side Cassia East </span>
<input id= "Tbox" type= "text" onchange= "Wahaha ()" >
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.