0515JS事件函数操作document对象练习

Posted mjwwzy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了0515JS事件函数操作document对象练习相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            *{
                margin: 0 auto;
                padding: 0;
            }
            body{
                transition: 1s;
            }
            #first{
                width: 100px;
                height: 60px;
                background-color:#00008B;
                border-radius: 5px;
                text-align: center;
                line-height: 60px;
                font-size: 22px;
                color: white;
            }
            #first:hover{
                cursor: pointer;
            }
            #second{
                width: 160px;
                height: 60px;
                text-align: center;
                line-height: 60px;
                font-size: 15px;
            }
            #a1{
                width: 100px;
                height: 60px;
                background-color:#00008B;
                border-radius: 5px;
                margin-top: 20px;
                text-align: center;
                line-height: 60px;
                font-size: 22px;
                display: none;
                color: white;
            }
            #second:hover{
                cursor: pointer;
            }
            #third{
                width: 700px;
                height: 100px;
                background-color: #00008B;
                margin-top: 100px;
                border-radius: 10px;
                text-align: center;
                line-height: 100px;
                color: white;
            }
            #third:hover{
                cursor: pointer;
            }
            .four{
                width: 100px;
                height: 60px;
                background-color:#00008B;
                border-radius: 5px;
                margin-top: 80px;
                margin-left: 500px;
                text-align: center;
                line-height: 60px;
                font-size: 22px;
                color: white;
                float: left;
            }
            .fifth{
                width: 100px;
                height: 60px;
                background-color:#00008B;
                border-radius: 5px;
                margin-top: 80px;
                margin-left: 500px;
                text-align: center;
                line-height: 60px;
                font-size: 22px;
                color: white;
                float: left;
            }
            .fifth:hover{
                cursor: pointer;
            }
        </style>
    </head>
    <body>
        <div id="first" onclick="first()">
            按钮
        </div>
        <div id="second">
            <input type="checkbox" name="" id="" value="" onmousemove="second()"/>鼠标经过出现按钮
        </div>
        <div id="a1">
            点我
        </div>
        <div id="third">
            鼠标经过这个div变高变色,移除再恢复
        </div>
        <div class="four" onclick="four1()">
            按钮
        </div>
        <div class="four" onclick="four2()" style="margin-left: 80px;">
            按钮
        </div>
        <div class="fifth" onclick="fifth()">
            按钮
        </div>
        <div class="fifth" onclick="fifth()" style="margin-left: 40px;display: none;">
            按钮
        </div>
    </body>
</html>
<script type="text/javascript">
    function first(){
        alert("弹出窗口");
    }
    var second = document.getElementById("second");
    second.onmouseover = function(){
        var second1 = document.getElementById("a1");
        second1.style.display = "block";
    }
    second.onmouseout = function(){
        var second1 = document.getElementById("a1");
        second1.style.display = "none";
    }
    var third = document.getElementById("third");
    third.onmouseover = function(){
        third.style.height = "200px";
        third.style.backgroundColor = "red";
        third.style.transition = "3s";
    }
    var third = document.getElementById("third");
    third.onmouseout = function(){
        third.style.height = "100px";
        third.style.backgroundColor = "#00008B";
    }
    function four1(){
        var four3 = document.getElementsByTagName("body")[0];
        four3.style.backgroundColor = "darkmagenta";
        four3.style.transition = "1s";
    }
    function four2(){
        var four3 = document.getElementsByTagName("body")[0];
        four3.style.backgroundColor = "#C69500";
        four3.style.transition = "1s";
    }
    var fifth1 = document.getElementsByClassName("fifth")[1];
    var fifth2 = fifth1.style.display;
    function fifth(){
        if(fifth2 == "none"){
            fifth1.style.display = "block";
            fifth2 = "block";
        }else{
            fifth1.style.display = "none";
            fifth2 = "none";
        }
    }
</script>

 

以上是关于0515JS事件函数操作document对象练习的主要内容,如果未能解决你的问题,请参考以下文章

js 函数 常用事件 document事件 window对象

js dom操作总结

JS中基本window.document对象操作以及常用事件!

js windows对象

事件响应练习(慕课网题目)

js练习构造函数和原型对象的继承方式