当前位置:首页 > jQuery.API源码深入剖析以及应用实现(2)-jQuery对象访问和数据缓存

jQuery.API源码深入剖析以及应用实现(2)-jQuery对象访问和数据缓存

点击次数:1616  更新日期:2011-01-05
\n

前言


\n

上篇主要介绍JQuery的核心函数的原理机制,这篇将开始介绍jQuery对象访问和数据缓存原理,主要内容包括:


\n

\n

分析


\n

一、jQuery对象访问


\n

1. 【each(callback)


\n

例子:


\n


\n

\n


\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
HTML代码jQuery代码运行结果
<img/><img/>
\n

(“img”).each(function(i){
this.src = “test” + i + “.jpg”;
});

[ <img src="test0.jpg" />, <img src="test1.jpg" /> ]
<img/><img/>
\n

(“img”).each(function(){
(this).toggleClass(“example”);
});

切换样式example


\n

现在来看each方法的具体实现如下:


\n
<!–

\n

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

\n

–>jQuery.fn = jQuery.prototype = {
each: function( callback, args ) {
return jQuery.each( this, callback, args );
}
}

\n