jquery的ready事件

<!DOCTYPE html>
<html lang="en">
<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>Document</title>
</head>
<body>
    <script src="lib/jquery-2.2.2.js"></script>
    <script>
        //当DOM载入就绪就可以查询及操作时绑定一个要执行的函数。不必等到页面中图片或其他外部文件都加载完毕
        $(document).ready(function(){
            alert('ready!');
        });
        // window.onload=function(){
        //     alert('onload');
        // };
        //可以定义多次,按顺序触发
        $(document).ready(function(){
            alert('2');
        });
        //简化版
        $(function(){
            alert('3');
        });
    </script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_44606660/article/details/88198340