首页 > 技术文章 > 1、事件、函数、变量、判断

chwen1014 2018-04-10 11:24 原文

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>1、事件、函数、变量、判断</title>
    <link href="base.css">
    <style>
        li{
            padding-bottom: 50px;
        }

        .btn{
            width: 80px;
            height: 44px;
            border-radius: 6px;
            border: none;
            background-color: blue;
            color: white;
            font-size: 16px;
        }

        #btn1{
            width: 80px;
            height: 44px;
            border-radius: 6px;
            border: none;
            background-color: blue;
            color: white;
            font-size: 16px;
            display: none;
        }

        #aBlock{
            width:400px;
            height:100px;
            border:1px solid #ccc;
        }

        #aBlock1{
            display: none;
            width:160px;
            height:50px;
            border:1px solid #ccc;
            text-align: center;
            line-height: 50px;
            margin-top: 5px;
        }

        #btn2{
            display: none;
            width:160px;
            height:50px;
            border:1px solid #ccc;
            text-align: center;
            line-height: 50px;
            margin-top: 5px;
        }

        #yangshi1{
            width: 80px;
            height: 44px;
            border-radius: 6px;
            border: none;
            background-color: blue;
            color: white;
            font-size: 16px;
        }

        #yangshi2{
             width: 80px;
             height: 44px;
             border-radius: 6px;
             border: none;
             background-color: blue;
             color: white;
             font-size: 16px;
         }

        #xy{
            width: 80px;
            height: 44px;
            border-radius: 6px;
            border: none;
            background-color: blue;
            color: white;
            font-size: 16px;
        }

        #xyRed{
            display: none;
            width: 80px;
            height: 44px;
            border-radius: 6px;
            border: none;
            background-color: red;
            color: white;
            font-size: 16px;
        }

    </style>
</head>
<body>
<ol>
    <!--1、说明事件-->
    <li>说明事件
    <input type="button" value="按钮"  class="btn" onclick="alert('弹出窗口')">
    </li>
    
    <!--2、移入移出-->
    <li>移入移出
    <div onmouseover="mOver()" onmouseout="mOut()" style="display: inline">
    <input type="radio" class="radio1">鼠标经过出现按钮
    <input type="button" value="按钮"  id="btn1">
    </div>
    </li>

    <!--3、函数 鼠标经过这个div执行变窄变高变色 移出再恢复-->
    <li>
       <div id="aBlock" onmouseover="show()" onmouseout="back()">鼠标经过这个div执行变窄变高变色,移出再恢复</div>
    </li>

    <!--4、鼠标经过就弹出层(函数、变量)-->
    <li>
        <div onmouseover="show1()" onmouseout="back1()">鼠标经过就弹出层</div>
        <div id="aBlock1">这是弹出的层</div>
    </li>

    <!--5、鼠标点击就弹出层(函数、变量、判断)-->
    <li>
        <div onclick="dianji()">鼠标点击就弹出层</div>
        <div id="btn2">这是弹出的层</div>
    </li>

    <!--6、网页换肤-->
    <li>网页换肤
        <input type="button" value="样式1" id="yangshi1" onclick="yang1()">
        <input type="button" value="样式2" id="yangshi2" onclick="yang2()">
    </li>

    <!--7、显示隐藏-->
    <li>显示隐藏
        <input type="button" value="显示隐藏" id="xy" onclick="xy1()">
        <input type="button" value="显示隐藏" id="xyRed">
    </li>



</ol>

<script>
    /*2、移入移出*/
    function mOver()
    {
        var a=document.getElementById("btn1");
        a.style.display="block";
    }

    function mOut()
    {
        var a=document.getElementById("btn1");
        a.style.display="none";
    }
    /*2、移入移出end*/

    /*3、函数 鼠标经过这个div执行变窄变高变色 移出再恢复*/
    function show()
    {
        var a=document.getElementById("aBlock");
        a.style.background="red";
        a.style.height="200px";
        a.style.color="white";
    }

    function back()
    {
        var a=document.getElementById("aBlock");
        a.style.background="white";
        a.style.height="100px";
        a.style.color="black";
    }
    /*3、函数 鼠标经过这个div执行变窄变高变色 移出再恢复end*/

    /*4、鼠标经过就弹出层(函数、变量)*/
    function show1()
    {
        var a=document.getElementById("aBlock1");
        a.style.display="block";
    }

    function back1()
    {
        var a=document.getElementById("aBlock1");
        a.style.display="none";
    }
    /*4、鼠标经过就弹出层(函数、变量)end*/


    /*5、鼠标点击就弹出层(函数、变量、判断)*/
    function dianji()
    {
        var a=document.getElementById("btn2");
        if(a.style.display=="block"){
            a.style.display="none"
        }else{
            a.style.display="block"
        }
    }
    /*5、鼠标点击就弹出层(函数、变量、判断)end*/

    /*6、网页换肤*/
    function yang1(){
        var a=document.getElementById("yangshi1");
        document.body.style.backgroundColor="red";
    }
    function yang2(){
        var a=document.getElementById("yangshi2");
        document.body.style.backgroundColor="yellow";
    }
    /*6、网页换肤end*/

    /*7、显示隐藏*/
    function xy1(){
        var a=document.getElementById("xyRed");
        if(a.style.display=="block"){
            a.style.display='none';
        }else{
            a.style.display='block';
        }
    }
    /*7、显示隐藏end*/
</script>

</body>
</html>

 

推荐阅读