A table tells you the difference between Windows.onload of and $of document.ready of

  • 2020-03-30 03:00:04
  • OfStack

After the browser loads the DOM, it adds events to the DOM element through javascript, which typically USES the window.onload() method.

In jquery, you use the $(document).ready() method. Here's the difference.

  Window. The onload () The $(document) ready () Execution time Execute after all elements of the page (including images, reference files) are loaded.

All of the HTML DOM in the page is executed after the CSS DOM structure is loaded, and other images may not be loaded.

If you want all the contents of the page (including pictures, etc.) to load, and then register the event, use $(window).load(function);

Equivalent to the window. The onload ()

Write the number

Can't write more than one at a time, the back will overwrite the front. Ex:

Window. The onload = function () {alert (" A "); }

Window. The onload = function () {alert (" B "); }

The result will be "B"

If you want to execute alert("A") and alert("B") sequentially, you need to write this

Window. The onload = function () {

Alert (" A ");

Alert (" B ");


You can write more than one at a time shorthand There is no

The $(document). Ready (function () {

/ / to do;


Can be written as

$().ready(function(){//$() with no arguments the default is document

/ / to do;

}); or

$(function () {

/ / to do;



Related articles: