手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >jquery中ready()函数执行的时机和window的load事件比较
jquery中ready()函数执行的时机和window的load事件比较
摘要:jquery的ready()实现的是DOMContentLoaded事件,DOMContentLoaded与windowload事件的区别简...

jquery的ready()实现的是 DOMContentLoaded 事件,DOMContentLoaded与window load事件的区别

简单的说ready()是在文档加载完成就会触发,此时图片等资源可能还没有完全加载, load是在所有资源都加载完成后才会触发

看下ready函数的代码就什么都清楚了。下面的代码加上了注释:

// Handle when the DOM is ready ready: function() { // Make sure that the DOM is not already loaded if ( !jQuery.isReady ) { // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). if ( !document.body ) { return setTimeout( jQuery.ready, 13 ); } // Remember that the DOM is ready jQuery.isReady = true; // If there are functions bound, to execute if ( readyList ) { // Execute all of them var fn, i = 0; while ( (fn = readyList[ i++ ]) ) { fn.call( document, jQuery ); } // Reset the list of functions readyList = null; } // Trigger any bound ready events if ( jQuery.fn.triggerHandler ) { jQuery( document ).triggerHandler( "ready" ); } } },

以上所述就是本文的全部内容了,希望大家能够喜欢。

【jquery中ready()函数执行的时机和window的load事件比较】相关文章:

JavaScript中isPrototypeOf函数作用和使用实例

JQuery中DOM实现事件移除的方法

javascript事件冒泡和事件捕获详解

jQuery替换textarea中换行的方法

jquery中添加属性和删除属性

JavaScipt中Function()函数的使用教程

jQuery实现表格行上下移动和置顶效果

JavaScript中停止执行setInterval和setTimeout事件的方法

浅谈jQuery中replace()方法

jQuery封装的tab选项卡插件分享

精品推荐
分类导航