会挽雕弓如满月,西北望,射天狼。 注册 | 登陆

可能是jQuery1.3.2的一个小bug

我在用$(document).ready()的时候,会出现undefined的错误,当然这也不一定是jQuery的bug,也可能是我用的其它库不完善。

跟踪程序后,发现是readyList里有一个元素变成了undefined。
我决定修改jQuery库,因为觉得比较方便。
修改后的代码见下。
可以替换原来的相应部分,或者附在引用标准的jQuery库后以覆盖原来的方法。

jQuery.extend({
isReady: false,
readyList: [],
// Handle when the DOM is ready
ready: function() {
// Make sure that the DOM is not already loaded
if ( !jQuery.isReady ) {
// Remember that the DOM is ready
jQuery.isReady = true;

// If there are functions bound, to execute
if ( jQuery.readyList ) {
// Delete the undefined item!! add by lijs 2009-12-25
for(var i = 0;i < jQuery.readyList.length; i++){
if(jQuery.readyList[i] === undefined){
jQuery.readyList.remove(i);
i--;
}
}
// Execute all of them
jQuery.each( jQuery.readyList, function(){
this.call( document, jQuery );
});

// Reset the list of functions
jQuery.readyList = null;
}

// Trigger any bound ready events
jQuery(document).triggerHandler("ready");
}
}
});

Tags: 网页, 编程

« 上一篇 | 下一篇 »

只显示5条记录相关文章

今天对JavaScript的一点小收获 (浏览: 960, 评论: 2)
扫雷对战版 (浏览: 5103, 评论: 2)
一个用Qt写的多线程聊天室软件 (浏览: 2020, 评论: 3)
div下拉菜单-添加鼠标动作 (浏览: 1382, 评论: 0)
div下拉菜单的实现 (浏览: 2447, 评论: 0)

1条记录访客评论

传说中的沙发\(^o^)/~

Post by 白癜风 on 2010, August 9, 11:02 AM 引用此文发表评论 #1


发表评论

评论内容 (必填):