首页 > 代码库 > jQuery——修改网页字体大小

jQuery——修改网页字体大小

HTML:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <link type="text/css" href="09.css" rel="stylesheet"/>
        <script type="text/javascript" src="jquery.js"></script>
        <title></title>
    </head>
    <body>
        <h1>wo men</h1>
        <p>cfjdsmc edvc ewrd csd wrvc d  2e34efrew8r934efc cred  ewfced
        vefwid cfer fd 3ew fcxdwdkjfdke fewf dewkdse fcedwfewdfcs
        fre dfc ed fcejfoklew ferf
        defedefcd</p>
        <input type="button" id="big" value="放大"/><br />
        <input type="button" id="small" value="缩小"/>
        <script type="text/javascript">
            $("input").click(function(){
                var t = $("p").css("font-size")
                var t1 = parseInt(t, 10)
                var unit = t.slice(-2)
                var name1 = $(this).attr("id")
                if(name1 == "big"){
                    t1 += 2
                }
                else if(name1 == "small"){
                    t1 -= 2
                }
                $("p").css("font-size", t1+unit)
            })
        </script>
    </body>
</html>

END

jQuery——修改网页字体大小