Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器 软件资源

软件开发小程序制作系统集成与运维空间租用硬件开发视频监控技术咨询与支持——联系电话:0311-88999002/88999003

首页 / 脚本样式 / JavaScript / jquery中ready()函数执行的时机和window的load事件比较

jquery的ready()实现的是 DOMContentLoaded 事件,DOMContentLoaded与window load事件的区别
简单的说ready()是在文档加载完成就会触发,此时图片等资源可能还没有完全加载, load是在所有资源都加载完成后才会触发
看下ready函数的代码就什么都清楚了。下面的代码加上了注释:
// Handle when the DOM is readyready: function() {// Make sure that the DOM is not already loadedif ( !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 readyjQuery.isReady = true;// If there are functions bound, to executeif ( readyList ) {// Execute all of themvar fn, i = 0;while ( (fn = readyList[ i++ ]) ) {fn.call( document, jQuery );}// Reset the list of functionsreadyList = null;}// Trigger any bound ready eventsif ( jQuery.fn.triggerHandler ) {jQuery( document ).triggerHandler( "ready" );}}},
以上所述就是本文的全部内容了,希望大家能够喜欢。