Home > Web Front-end > JS Tutorial > Analysis of the difference between window.onload and $(document).ready()_javascript skills

Analysis of the difference between window.onload and $(document).ready()_javascript skills

WBOY
Release: 2016-05-16 15:57:12
Original
1118 people have browsed it

The example in this article describes the difference between window.onload and $(document).ready(). Share it with everyone for your reference. The specific analysis is as follows:

window.onload is a function in Javascript, which means: wait for all content in the web page to be loaded (including images);
$(documetn).ready() can be executed after all the DOM structures in the web page have been drawn. There may be elements associated with the DOM that have not been loaded, so it is faster in comparison;

For example, let’s take a simple example:

window.onload=function(){
  alert('I am No.1');
};
window.onload=function(){
 alert('I am No.2');
}

Copy after login

According to the above meaning, the result can only output "I am No.2"

Replace

with:

$(document).ready(function(){
alert('I am No.1');
});
$(document).ready(function(){
alert('I am No.2');
});

Copy after login

Result output I am No.1 ,I am No.2

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template