JS 变换按钮及函数

原创2019-02-15 00:09:28116
摘要:<head><style type="text/css">#box{width: 100px;height: 100px;background:bisque}</style></head><body><div id="box"></div>   

<head>

<style type="text/css">

#box{width: 100px;height: 100px;background:bisque}



</style>


</head>

<body>

<div id="box"></div>

    <input type="button" value="变高" onclick="Alterheight()">

    <input type="button" value="变宽" onclick="Alterwidth()">

    <input type="button" value="变色" onclick="Altercolor()">

    <input type="button" value="重置" onclick="Reset()">

    <input type="button" value="隐藏" onclick="Hide()">

    <input type="button" value="显示" onclick="Display()">


<script type="text/javascript">

    var box

    window.onload = function(){

            box = document.getElementById('box')

    }

    function Alterheight(){

            box.style.height = '500px'

    }

    function Alterwidth(){

            box.style.width = "500px"

     }

     function Altercolor(){

            box.style.background = "red";

        }

    function Reset(){

            box.style.height="100px";

            box.style.width="100px";

            box.style.background="bisque";

        }

    function Hide(){

            box.style.display="none"


        }

     function Display(){

            box.style.display="block"


}


</script>


</body>


批改老师:查无此人批改时间:2019-02-15 09:19:22
老师总结:完成的不错。js代码,每行结束要加上 ; 号。要养成习惯,因为上线的项目,需要把js文件压缩,这样用户访问时,请求的文件会小一些,速度快一些。继续加油。

发布手记

热门词条