Several ways to load the page

Usually the method in js is the window.onload method, but this has a disadvantage, that is, when multiple loading events occur, the subsequent content will directly overwrite the previous content. For example, take the console output as an example:

    window.onload = function () {
        console.log("BOM方法1");
    };
    window.onload = function () {   //只会加载显示出最后一个
        console.log("BOM方法2");
    };

1. jQuery's page load event load method

Calling multiple loading events results in console.log will display the output, for example:

$(window).load(function () {
        console.log("jQuery-load方法1");
    }); //会最后输出
    $(window).load(function () {
        console.log("jQuery-load方法2");
    }); //会最后输出

Two, jQuery's page loading event read method

This method is to trigger tags, pictures, text content... after all the content in the page is loaded. The second way to write the event of page loading is to trigger after the basic tags in the page are loaded, for example:

    $(document).ready(function () {
        console.log("jQuery-ready方法1");
    });
    $(document).ready(function () {
        console.log("jQuery-ready方法2");
    });

    jQuery(function () {
        console.log("jQuery-最简单的方法1");
    });
    $(function () {
        console.log("jQuery-最简单的方法2");
    });

Overall rendering effect:
insert image description here
If there are any deficiencies, please advise.

Guess you like

Origin blog.csdn.net/weixin_42676530/article/details/107691686