返回JS控制DIV......登陆

JS控制DIV样式

清玉2019-01-31 21:43:44219
<!DOCTYPE html>
<html>
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>JS控制DIV样式</title>
        <style>
</style>
    </head>
    
    <body>
        <div id="box"></div>
        <input type="button" value="变高" onclick="changeh(this)">
        <input type="button" value="变宽" onclick="changew(this)">
        <input type="button" value="变色" onclick="changec(this)">
        <input type="button" value="重置" onclick="reset(this)">
        <input type="button" value="隐藏" onclick="hide(this)">
        <input type="button" value="显示" onclick="show(this)">
        <script>
            var box;
            window.onload = function() {
                box = document.getElementById("box");
            }

            function changeh() {
                box.style.height = "300px";
            }

            function changew() {
                box.style.width = "300px";
            }

            function changec() {
                box.style.background = "#000";
            }

            function reset() {
                box.style = "reset";
            }

            function hide() {
                box.style.display = "none";
            }

            function show() {
                box.style.display = "block";
            }
        </script>
    </body>

</html>

多多练习,重置样式也可以使用reset。

最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送