其他事件

104 阅读1分钟
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            width: 200px;
            height: 1000px;
            background-color: yellow;
        }
    </style>
    <script>
        // onlode 文档加载事件
        // 给window加,等body里面的dom结构全部加载完成之后在触发
        // 注:1一个window.onload在一个script标签中只能出现一次
        // 2会等图片加载完成之后才触发
        window.onload=function(){
            var bt1=document.getElementsByTagName("button")[0];
            bt1.onclick=function(){
                console.log("hello");
            }
        }

        // 滚动事件
        window.onscroll=function(){
            console.log("滚动事件");
        }
    </script>
</head>
<body>
    <button>按钮</button>
    <div class="box">

    </div>
</body>
</html>