之间有什么区别
$(document).ready(function(){
//my code here
});
and
$(window).load(function(){
//my code here
});
我想确保:
$(document).ready(function(){
})
and
$(function(){
});
and
jQuery(document).ready(function(){
});
是相同的。
你能告诉我它们之间有什么区别和相似之处吗?
$(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版本
重大更改:删除了 .load()、.unload() 和 .error()
These methods are shortcuts for event operations, but had several API
limitations. The event .load()
method conflicted with the ajax .load()
method. The .error()
method could not be used with window.onerror
because of the way the DOM method is defined. If you need to attach
events by these names, use the .on()
method, e.g. change
$("img").load(fn)
to $(img).on("load", fn)
.1
$(window).load(function() {});
应该改为
$(window).on('load', function (e) {})
这些都是等价的:
$(function(){
});
jQuery(document).ready(function(){
});
$(document).ready(function(){
});
$(document).on('ready', function(){
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)