美文网首页
实践出真知:JS执行顺序

实践出真知:JS执行顺序

作者: 张中华 | 来源:发表于2023-02-27 17:08 被阅读0次
    <!DOCTYPE html>
    <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>
            html {
                margin: 0;
                padding: 0;
            }
    
            body {
                margin: 0;
                padding: 0;
            }
        </style>
        <script>
            console.log('head before Mounted:' + document.querySelector('#box')?.innerHTML);
            
            window.addEventListener('DOMContentLoaded', function (e) {
                console.log('head dom content loaded: ' + document.querySelector('#box').innerHTML);
            });
    
            window.onload = function (e) {
                console.log('head window onload: ' + document.querySelector('#box').innerHTML);
            }
        </script>
    </head>
    
    <body>
        <script>
            console.log('before Mounted:' + document.querySelector('#box')?.innerHTML);
        </script>
        <div id="box">box</div>[图片上传中...(image.png-1bc259-1676256319808-0)]
    
        <script>
            console.log('dom end: ' + document.querySelector('#box').innerHTML);
        </script>
    
        <script>
            window.onload = function (e) {
                console.log('window onload: ' + document.querySelector('#box').innerHTML);
            }
        </script>
    
        <script>
            window.addEventListener('DOMContentLoaded', function (e) {
                console.log('dom content loaded: ' + document.querySelector('#box').innerHTML);
            });      
        </script>
    </body>
    
    </html>
    

    相关文章

      网友评论

          本文标题:实践出真知:JS执行顺序

          本文链接:https://www.haomeiwen.com/subject/pwcdkdtx.html