jquery ready函数指的是
$(document).ready(function);它等同于$(function(){})
不过有经验的工程师,简便起见,更喜欢使用 $(function(){})
jquery ready函数在DOM元素渲染完后触发,不包括外部资源(img、iframe)的加载完毕。
如果想在资源(img、iframe)加载完毕后触发事件,则使用$(window).on("load",function(){})
A page can’t be manipulated safely until the document is “ready.” jQuery detects this state of readiness for you. Code included inside $( document ).ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute. Code included inside \$( window ).on( “load”, function() { … }) will run once the entire page (images or iframes), not just the DOM, is ready.
本文介绍了jQuery中的ready函数,探讨了其如何确保DOM准备好后再执行JavaScript代码,以及何时使用$(document).ready()与$(window).on('load')的区别。
939

被折叠的 条评论
为什么被折叠?



