Click the button to change the font size (js small homework)

    Whether in major websites or small personal web pages, there will be settings to change the font size. Next, we use two small buttons and a div to store the content to achieve this small function.

<input type="button" id="up" value="字号增大"> <input type="button" id="down" value="字号减小">

<div id="wrapper">text text text text text text text text text text</div>

<script type = "text/javascript">

       // get an element

        var oUp = document.getElementById('up'); // Note the quotation marks, use English half-width

        var oDown = document.getElementById('down');

        var oDiv = document.getElementById('wrapper');

        var num = 16; // default font size

        oUp.onclick = function () {

               num += 1.2;

               oDiv.style.fontSize = num + 'px';

        }

        oDown.onclick = function () {

            num-= 1.2;

            oDiv.style.fontSize = num+'px';

        }

</script>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324950347&siteId=291194637