本文介绍了jQuery-$(document).ready和$(window).load有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两者之间有什么区别

$(document).ready(function(){
 //my code here
});

$(window).load(function(){
  //my code here
});


我想确保:


And I want to make sure that:

$(document).ready(function(){

})

$(function(){

});

jQuery(document).ready(function(){

});

一样.

你能告诉我它们之间有什么区别和相似之处吗?

Can you tell me what differences and similarities between them?

推荐答案

$(document).ready(function() {
  // executes when HTML-Document is loaded and DOM is ready
  console.log("document is ready");
});


$(window).load(function() {
  // executes when complete page is fully loaded, including all frames, objects and images
  console.log("window is loaded");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

查询3.0版本

$(window).load(function() {});

应更改为

$(window).on('load', function (e) {})

这些都是等效的:

$(function(){
});

jQuery(document).ready(function(){
});

$(document).ready(function(){
});

$(document).on('ready', function(){
})

这篇关于jQuery-$(document).ready和$(window).load有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 21:00