Home > Web Front-end > JS Tutorial > The difference between $(document).ready() and window.onload in jquery_jquery

The difference between $(document).ready() and window.onload in jquery_jquery

WBOY
Release: 2016-05-16 18:41:40
Original
989 people have browsed it

So if a certain image or other resource takes a long time to load, the visitor will see an incomplete page, or even a script that relies on dynamically added elements will be executed before the image is loaded, resulting in a script error.
window .onload = function() { testDiv.innerHTML = "

Dynamicly created div
"; }
The solution is to wait for the DOM to be parsed, Execute our function before images and external resources are loaded. To make this implementation feasible in jQuery:

Copy code Code As follows:

//jQuery uses the dynamically created $(document).ready(function) method
$(document).ready(
function() { testDiv.innerHTML = "
Use the dynamically created $(document).ready(function) method
"; }
);
//Or easy to use Syntax:
/jQuery Use $(function) method
$(
function() { testDiv.innerHTML = "
Use $(function) Method
"; }
);
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