<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>网站前端,web前端,前端脚本,前端优化&#124;时代前端 &#187; 特性</title>
	<atom:link href="http://www.52shidai.com/tag/%e7%89%b9%e6%80%a7/feed" rel="self" type="application/rss+xml" />
	<link>http://www.52shidai.com</link>
	<description>网站前端研究中心</description>
	<lastBuildDate>Thu, 02 Feb 2012 03:36:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>jQuery1.4下载、性能及新特性详解</title>
		<link>http://www.52shidai.com/javascript/jquery/401.html</link>
		<comments>http://www.52shidai.com/javascript/jquery/401.html#comments</comments>
		<pubDate>Sun, 11 Apr 2010 08:23:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jQuery1.4]]></category>
		<category><![CDATA[下载]]></category>
		<category><![CDATA[特性]]></category>
		<category><![CDATA[能及]]></category>
		<category><![CDATA[详解]]></category>

		<guid isPermaLink="false">http://www.52shidai.com/?p=401</guid>
		<description><![CDATA[jQuery1.4正式版发布了，官方同步推出了The 14 Days of jQuery 网站，来介绍jQuery1.4的新特性和教程，其中有一篇文章详细介绍了jQuery1.4的新增功能，现转载其中文翻译如下： 原文：jQuery 1.4 Released 翻译：coolnalu jQuery 1.4 发布啦 为了庆祝jQuery的四周岁生日, jQuery的团队荣幸的发布了jQuery Javascript库的最新主要版本! 这个版本包含了大量的编程，测试，和记录文档的工作，我们为此感到很骄傲。 我要以个人的名义感谢 Brandon Aaron, Ben Alman, Louis-Rémi Babe, Ariel Flesler, Paul Irish, Robert Kati?, Yehuda Katz, Dave Methvin, Justin Meyer, Karl Swedberg, and Aaron Quint。谢谢他们在修复BUG和完成这次发布上所做的工作。 下载(Downloading) 按照惯例，我们提供了两份jQuery的拷贝，一份是最小化的(我们现在采用Google Closure作为默认的压缩工具了)，一份是未压缩的(供纠错或阅读)。 jQuery压缩 (23kb Gzipped) jQuery常规 (154kb) 另外，Google也在他们的服务器上放置了一份jQuery的拷贝。这份拷贝会自动的最小化然后压缩 – 并且放在Google最快的缓存服务器上。 http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js 你可以在你的站点上直接引用上面的URL，这样就可以享受迅速加载jQuery的性能优势了。 就jQuery1.4来说，我们努力的减少大规模升级中的麻烦 [...]]]></description>
			<content:encoded><![CDATA[<p><span class='wp_keywordlink_affiliate'><a href="http://www.52shidai.com/tag/jquery1-4" title="查看 jQuery1.4 中的全部文章" target="_blank">jQuery1.4</a></span>正式版发布了，官方同步推出了<a href="http://jquery14.com/" target="_blank">The 14 Days of jQuery</a> 网站，来介绍<span class='wp_keywordlink_affiliate'><a href="http://www.52shidai.com/tag/jquery1-4" title="查看 jQuery1.4 中的全部文章" target="_blank">jQuery1.4</a></span>的新<span class='wp_keywordlink_affiliate'><a href="http://www.52shidai.com/tag/%e7%89%b9%e6%80%a7" title="查看 特性 中的全部文章" target="_blank">特性</a></span>和教程，其中有一篇文章详细介绍了<span class='wp_keywordlink_affiliate'><a href="http://www.52shidai.com/tag/jquery1-4" title="查看 jQuery1.4 中的全部文章" target="_blank">jQuery1.4</a></span>的新增功能，现转载其中文翻译如下：</p>
<blockquote><p>原文：<a href="http://jquery14.com/day-01/jquery-14" target="_blank">jQuery 1.4 Released</a></p>
<p>翻译：<a href="http://www.uxd2.com/2010/01/%E7%BF%BB%E8%AF%91-jquery1-4%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3/" target="_blank">coolnalu</a></p></blockquote>
<h3>jQuery 1.4 发布啦</h3>
<p>为了庆祝jQuery的四周岁生日, jQuery的团队荣幸的发布了jQuery Javascript库的最新主要版本! 这个版本包含了大量的编程，测试，和记录文档的工作，我们为此感到很骄傲。</p>
<p>我要以个人的名义感谢 Brandon Aaron, Ben Alman, Louis-Rémi Babe, Ariel Flesler, Paul Irish, Robert Kati?, Yehuda Katz, Dave Methvin, Justin Meyer, Karl Swedberg, and Aaron Quint。谢谢他们在修复BUG和完成这次发布上所做的工作。</p>
<h4><span class='wp_keywordlink_affiliate'><a href="http://www.52shidai.com/tag/%e4%b8%8b%e8%bd%bd" title="查看 下载 中的全部文章" target="_blank">下载</a></span>(Downloading)</h4>
<p>按照惯例，我们提供了两份jQuery的拷贝，一份是最小化的(我们现在采用<a href="http://code.google.com/closure/compiler/" target="_blank">Google Closure</a>作为默认的压缩工具了)，一份是未压缩的(供纠错或阅读)。</p>
<blockquote><p><a href="http://code.jquery.com/jquery-1.4.min.js" target="_blank">jQuery压缩</a> (23kb <a href="http://www.julienlecomte.net/blog/2007/08/13/" target="_blank">Gzipped</a>)</p>
<p><a href="http://code.jquery.com/jquery-1.4.js" target="_blank">jQuery常规</a> (154kb)</p></blockquote>
<p>另外，Google也在他们的服务器上<a href="http://code.google.com/apis/ajaxlibs/documentation/index.html" target="_blank">放置了一份jQuery的拷贝</a>。这份拷贝会自动的最小化然后压缩 – 并且放在Google最快的缓存服务器上。</p>
<blockquote><p><a href="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" target="_blank">http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js</a></p></blockquote>
<p>你可以在你的站点上直接引用上面的URL，这样就可以享受迅速加载jQuery的性能优势了。</p>
<p>就jQuery1.4来说，我们努力的减少大规模升级中的麻烦 – 通过保持所有public函数的签名。即使如此，还请通读<a href="http://www.uxd2.com/2010/01/%E7%BF%BB%E8%AF%91-jquery1-4%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3/#backwards" target="_blank">可能会造成问题的变更列表</a>，这样能够了解哪些变更可能会给你的应用造成问题。</p>
<h3>功能(新<span class='wp_keywordlink_affiliate'><a href="http://www.52shidai.com/tag/%e7%89%b9%e6%80%a7" title="查看 特性 中的全部文章" target="_blank">特性</a></span>)Features</h3>
<p>下面的内容概括了jQuery1.4里加入的变更和功能。另外所有的变更都已经在<a href="http://api.jquery.com/category/version/1.4/" target="_blank">jQuery 1.4 的文档</a>里记录了。</p>
<h4>热门方法经过了性能上的大”检修”</h4>
<p>不少比较热门的和常用的jQuery方法在1.4里被重写了。(译注:重写了方法的内部，外部调用没有大幅度改变) 我们分析源码的时候发现我们能够获得大幅的性能提升，通过把jQuery和自己比较: 查看内部函数被调用了多少次，然后努力<a href="http://ejohn.org/blog/function-call-profiling/" target="_blank">降低源码的复杂度</a>(译注:计算机算法中的Complexity)</p>
<p><a rel="lightbox[69]" href="http://www.uxd2.com/wp-content/uploads/2010/01/01-funccall.jpg" target="_blank"><img title="常用jQuery方法调用频率" src="http://www.uxd2.com/wp-content/uploads/2010/01/01-funccall.jpg" alt="常用jQuery方法调用频率" width="500" height="375" /></a><br />
<small><a title="# of Function Calls for Popular jQuery Methods by John Resig, on Flickr" href="http://www.flickr.com/photos/jeresig/4271691293/" target="_blank">View the cropped chart.</a></small></p>
<p>在1.4版里我们显著的降低了大部分热门jQuery方法的的复杂度。</p>
<h4>更易用的设置函数 (Easy Setter Functions)</h4>
<p>算来已经有一阵了，你们已经可以给<code><a href="http://api.jquery.com/attr" target="_blank">.attr()</a></code>传递一个函数，然后这个函数的结果会被用来赋给相应的HTML属性(attribute)上。这个功能现在被移植到所有的设置函数了: <code><a href="http://api.jquery.com/css" target="_blank">.css()</a></code>, <code><a href="http://api.jquery.com/attr" target="_blank">.attr()</a></code>, <code><a href="http://api.jquery.com/val" target="_blank">.val()</a></code>, <code><a href="http://api.jquery.com/html" target="_blank">.html()</a></code>, <code><a href="http://api.jquery.com/text" target="_blank">.text()</a></code>, <code><a href="http://api.jquery.com/append" target="_blank">.append()</a></code>, <code><a href="http://api.jquery.com/prepend" target="_blank">.prepend()</a></code>, <code><a href="http://api.jquery.com/before" target="_blank">.before()</a></code>, <code><a href="http://api.jquery.com/after" target="_blank">.after()</a></code>, <code><a href="http://api.jquery.com/replaceWith" target="_blank">.replaceWith()</a></code>, <code><a href="http://api.jquery.com/wrap" target="_blank">.wrap()</a></code>, <code><a href="http://api.jquery.com/wrapInner" target="_blank">.wrapInner()</a></code>, <code><a href="http://api.jquery.com/offset" target="_blank">.offset()</a></code>, <code><a href="http://api.jquery.com/addClass" target="_blank">.addClass()</a></code>, <code><a href="http://api.jquery.com/removeClass" target="_blank">.removeClass()</a></code>, 以及 <code><a href="http://api.jquery.com/toggleClass" target="_blank">.toggleClass()</a></code>.</p>
<p>另外, 对于下面几个方法，当前的值会被作为第2个变量传递给这个函数。<code><a href="http://api.jquery.com/css" target="_blank">.css()</a></code>, <code><a href="http://api.jquery.com/attr" target="_blank">.attr()</a></code>, <code><a href="http://api.jquery.com/val" target="_blank">.val()</a></code>, <code><a href="http://api.jquery.com/html" target="_blank">.html()</a></code>, <code><a href="http://api.jquery.com/text" target="_blank">.text()</a></code>, <code><a href="http://api.jquery.com/append" target="_blank">.append()</a></code>, <code><a href="http://api.jquery.com/prepend" target="_blank">.prepend()</a></code>, <code><a href="http://api.jquery.com/offset" target="_blank">.offset()</a></code>, <code><a href="http://api.jquery.com/addClass" target="_blank">.addClass()</a></code>, <code><a href="http://api.jquery.com/removeClass" target="_blank">.removeClass()</a></code>, 以及 <code><a href="http://api.jquery.com/toggleClass" target="_blank">.toggleClass()</a></code>.</p>
<p>这样代码就可以这样写:</p>
<div id="highlighter_443544">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>// 找出所有A标签里的'&amp;amp;'字符，然后用一个span标签包围 </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>$(</code><code>'a'</code><code>).html(</code><code>function</code><code>(i,html){ </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>  </code><code>return</code> <code>html.replace(/&amp;amp;/gi,</code><code>'&amp;amp;'</code><code>); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>}); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code> </code> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>// 给一些链接的title属性加些信息 </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>$(</code><code>'a[target]'</code><code>).attr(</code><code>"title"</code><code>, </code><code>function</code><code>(i,title){ </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>  </code><code>return</code> <code>title + </code><code>" (新窗口打开)"</code><code>; </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>});</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<h4>Ajax</h4>
<p><strong>嵌套参数的序列化</strong> (<a href="http://api.jquery.com/jQuery.param/" target="_blank">jQuery.param() 文档</a>, <a href="http://github.com/jquery/jquery/commit/50d78e7658382d2a2f5149cae7a6572f78ce403f" target="_blank">Commit 1</a>, <a href="http://github.com/jquery/jquery/commit/67089eedf6f84acd9c16ea2a6dadadf7b13a7c84" target="_blank">Commit 2</a>)</p>
<p>jQuery 1.4在jQuery.param方法里加入了嵌入参数序列化的支持，借用了PHP编程里兴起的，而后又被Ruby on Rails推广开来的方式。<br />
举例来说，<br />
<code>{foo: ["bar", "baz"]}</code> 会被序列化为 “foo[]=bar&amp;foo[]=baz”.</p>
<p>在jQuery 1.3版里, <code>{foo: ["bar", "baz"]}</code> 曾被序列化为 “foo=bar&amp;foo=baz”. 但是，这样做没用办法将只含有一个元素的阵列编码。如果你需要旧的序列化方式，你可以设置传统Ajax设置来进行切换。(使用<code>jQuery.ajaxSettings.traditional</code>进行全局切换，或者根据情况单独切换。</p>
<p>总共有3种方式可以切换到旧的序列化方式:</p>
<div id="highlighter_348346">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>// 全局改变序列化方式 (使用旧的) </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>jQuery.ajaxSettings.traditional = </code><code>true</code><code>; </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code> </code> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>// 指定情况使用旧的序列化方式 </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>jQuery.param( stuff, </code><code>true</code> <code>); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code> </code> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>// 针对一个单独的Ajax请求使用旧的序列化方式 </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>$.ajax({ data: stuff, traditional: </code><code>true</code> <code>});</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>更多信息参见: <a href="http://api.jquery.com/jQuery.param/" target="_blank">jQuery.param() 文档</a>, <a href="http://api.jquery.com/jQuery.ajax/" target="_blank">jQuery.ajax() 文档</a>, <a href="http://github.com/jquery/jquery/commit/39518945047413f1185682078043e70e0c5c9091" target="_blank">Commit</a>, <a href="http://github.com/jquery/jquery/blob/master/src/ajax.js#L175" target="_blank">Code</a></p>
<p><strong>JSON和脚本类型通过”content-type”自动识别。</strong> (<a href="http://api.jquery.com/jQuery.ajax/" target="_blank">jQuery.ajax 文档</a>, <a href="http://github.com/jquery/jquery/commit/787f271052220c20787104f0eba6441aedac22ff" target="_blank">Commit 1</a>, <a href="http://github.com/jquery/jquery/commit/6861b5d4eb16222ed5ea623af6ce75362b55d1d4" target="_blank">Commit 2</a>)</p>
<p>如果一个Ajax请求的回复的媒体类型是JSON(application/json), dataType默认设为”json”(如果dataType没有被指明)。另外，如果回复的媒体类型是 Javascript(application/javascript), dataType默认设为”script”(同样，如果dataType没有明确指明), 这种情况下，脚本会自动运行。</p>
<p><strong>加入了Etag的支持</strong> (<a href="http://api.jquery.com/jQuery.ajax/" target="_blank">jQuery.ajax() 文档</a>, <a href="http://github.com/jquery/jquery/commit/28ab4d32247943e1ae3409b23fe69303df0bc9eb" target="_blank">Commit</a>)</p>
<p>默认设置下, jQuery会忽略Ajax请求的”Last-Modified”页头。这样做是为了忽略浏览器的缓存。设置ifModified:true就可以使 jQuery使用可用的缓存。jQuery1.4还会发出”If-None-Match”的页头如果你设置了ifModified选项。</p>
<p><strong>严格JSON模式，本地的JSON.parse方法</strong> (<a href="http://api.jquery.com/jQuery.ajax/" target="_blank">jQuery.ajax() 文档</a>, <a href="http://github.com/jquery/jquery/commit/90a87c03b4943d75c24bc5e6246630231d12d933" target="_blank">Commit 1</a>, <a href="http://github.com/jquery/jquery/commit/308d6cdad023da190ace2a698ee4815ed8dad9c5" target="_blank">Commit 2</a>, <a href="http://github.com/jquery/jquery/commit/44e6beb10304789044de2c5a58f5bb82e8321636" target="_blank">Commit 3</a>)</p>
<p>jQuery 1.3和以前的版本曾使用Javascript的<code>eval</code>对引入的JSON解析。1.4版则会使用本地的JSON解析器，前提是如果有本地的解析器可用。它也会对引入的JSON进行校验。所以在<a href="http://api.jquery.com/jQuery.getJSON" target="_blank">jQuery.getJSON</a>方法里，或当一个Ajax请求的dataType是”json”的时候，jQuery会拒绝不合标准的JSON(例如<code>{foo: "bar"}</code>)。</p>
<p><strong>序列化HTML5的元素</strong> (<a href="http://api.jquery.com/jQuery.param/" target="_blank">jQuery.param() 文档</a>, <a href="http://github.com/jquery/jquery/commit/b31b9bd756a1489c3b1b856ed8b624c55da9e02f" target="_blank">Commit</a>)</p>
<p>新的<a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#attr-input-type-keywords" target="_blank">HTML5输入方法</a> (比如’datetime’和’range’)在序列化<code><a href="http://api.jquery.com/serialize" target="_blank">.serialize()</a></code>一个表单的时候会被包括在内。</p>
<p><strong>Ajax请求的环境</strong> (<a href="http://api.jquery.com/jQuery.ajax/" target="_blank">jQuery.ajax() 文档</a>, <a href="http://github.com/jquery/jquery/commit/183f37e4b4128af7ba096ac40046768b84b6d66e" target="_blank">Commit</a>)</p>
<p>你可以附加一个”环境”到Ajax请求上，所有的回调函数里都会拥有同样的”环境”设置(这样可以简化你的代码，尽可能避免使用闭合,或是其他对象)。</p>
<div id="highlighter_260169">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>jQuery.ajax({ </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>    </code><code>url: </code><code>"test.html"</code><code>, </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>    </code><code>context: document.body, </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>    </code><code>success: </code><code>function</code><code>(){ </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>        </code><code>jQuery(</code><code>this</code><code>).addClass(</code><code>"done"</code><code>); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>    </code><code>} </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>});</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><strong>请求成功回调函数的第三个参数会被设为原始的XHR对象</strong> (<a href="http://api.jquery.com/jQuery.ajax/" target="_blank">jQuery.ajax() 文档</a>, <a href="http://github.com/jquery/jquery/commit/c2101245c07afdb831b0c79869c7263420407b67" target="_blank">Commit</a>)</p>
<p>所有的Ajax请求的成功回调函数现在都会收到原始的XMLHttpRequest对象，作为第三个参数。之前这个XHR对象只能通过<code>$.ajax</code>一类方法的返回值来获取。</p>
<p><strong>明确设置”Content-Type”</strong> (<a href="http://api.jquery.com/jQuery.ajax/" target="_blank">jQuery.ajax() 文档</a>, <a href="http://github.com/jquery/jquery/commit/25b0ba9f9612583033b902a0e40345463a3a71d0" target="_blank">Commit</a>)</p>
<p>在1.3版，如果没有实际数据发送，<a href="http://api.jquery.com/jQuery.ajax/" target="_blank">jQuery.ajax</a>的contentType会被忽略。1.4版里，contentType将总是和请求一同发送。这修复了某些后台凭靠”Content-Type”页头判断回复类别所造成的问题。</p>
<p><strong>明确设置JSONP回调函数的名字</strong> (<a href="http://api.jquery.com/jQuery.ajax/" target="_blank">jQuery.ajax 文档</a>, <a href="http://github.com/jquery/jquery/commit/fbc73d45b487dd863886c7fd3f0af1fd4dec261b" target="_blank">Commit</a>)</p>
<p>你可以使用<a href="http://api.jquery.com/jQuery.ajax/" target="_blank">jQuery.ajax()</a>方法的jsonpCallback选项，通过名字来指定JSONP的回调函数。</p>
<p><strong>防止启动前跨域XHR</strong> (<a href="http://github.com/jquery/jquery/commit/a7678267d848fcef8775c8b9f4fa3e507b8cc5f4" target="_blank">Commit</a>)</p>
<p>跨域Ajax(针对提供支持的浏览器)将更易用，因为默认设置下，启动前XHR被阻止了。(TODO)</p>
<p><strong>jQuery.ajax()现在使用”onreadystatechange”事件替换了计时器</strong> (<a href="http://github.com/jquery/jquery/commit/fe6c86d53046b0f4d648f61c0b8e75387af65152" target="_blank">Commit</a>)</p>
<p>使用”onreadystatechange”替换了轮流探询，Ajax请求现在将使用更少的资源</p>
<h4>元素属性 (Attributes)</h4>
<p><strong><code>.css()</code>和<code>.attr()</code> 的性能被优化了。</strong></p>
<p>&lt;<a rel="lightbox[69]" href="http://www.uxd2.com/wp-content/uploads/2010/01/02-perform-cssatrr.jpg" target="_blank"><img title=".css().attr()的性能提高" src="http://www.uxd2.com/wp-content/uploads/2010/01/02-perform-cssatrr.jpg" alt=".css().attr()的性能提高" width="500" height="375" /></a></p>
<p><strong><code>.attr()</code>方法多了一个设置函数作为参数</strong> (<a href="http://api.jquery.com/attr/" target="_blank">.attr() 文档</a>)</p>
<p>你不但可以将一个函数用在<code>.attr()</code>里，还可以在这个函数里使用属性的当前值。</p>
<div id="highlighter_531146">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>jQuery(</code><code>'&lt;img src="enter.png" alt="enter your name" /&gt;'</code><code>) </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>.attr(</code><code>"alt"</code><code>, </code><code>function</code><code>(index, value) { </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>    </code><code>return</code> <code>"Please, "</code> <code>+ value; </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>});</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><strong>.val( Function )</strong> (<a href="http://api.jquery.com/val/" target="_blank">.val() 文档</a>)</p>
<div id="highlighter_616142">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>01</code></td>
<td><code>&lt;input class=</code><code>"food"</code> <code>type=</code><code>'text'</code> <code>data-index=</code><code>"0"</code> <code>/&gt; </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>02</code></td>
<td><code>&lt;input class=</code><code>"food"</code> <code>type=</code><code>'text'</code> <code>data-index=</code><code>"1"</code> <code>/&gt; </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>03</code></td>
<td><code> </code> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>04</code></td>
<td><code>jQuery(</code><code>"input:text.food"</code><code>).hide(); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>05</code></td>
<td><code> </code> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>06</code></td>
<td><code>jQuery(</code><code>"&lt;ul class='sortable'&gt;&lt;li&gt;Peanut Butter&lt;/li&gt;&lt;li&gt;Jelly&lt;/li&gt;&lt;/ul&gt;"</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>07</code></td>
<td><code> </code> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>08</code></td>
<td><code>) </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>09</code></td>
<td><code>  </code><code>.sortable() </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>  </code><code>.bind(</code><code>"endsort"</code><code>, </code><code>function</code><code>() { </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>    </code><code>$(</code><code>":text.food"</code><code>).val(</code><code>function</code><code>() { </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>      </code><code>return</code> <code>$(</code><code>"ul.sortable li:eq("</code> <code>+ $(</code><code>this</code><code>).attr(</code><code>"data-index"</code><code>)  + </code><code>")"</code><code>).text(); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td><code>    </code><code>}); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code>  </code><code>});</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><strong>text和CDATAHTML元素也支持.text()方法了</strong> (<a href="http://api.jquery.com/text/" target="_blank">.text() 文档</a>, <a href="http://github.com/jquery/jquery/commit/b30af34f28074b491929445f5aad3d62c63e772f" target="_blank">Commit</a>)</p>
<h4>核心 (Core)</h4>
<p><strong>快捷元素创建</strong> (<a href="http://api.jquery.com/jQuery/#jQuery2" target="_blank">jQuery() 文档</a>, <a href="http://github.com/jquery/jquery/commit/d40083c866738727aa7ffd7f13d2955bc9575d5e" target="_blank">Commit</a>)</p>
<p>现在当你需要使用jQuery函数创建一个元素的时候，你可以同时附递一个对象来指定属性值和事件:</p>
<div id="highlighter_123537">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>jQuery(</code><code>""</code><code>, { </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>    </code><code>id: </code><code>"foo"</code><code>, </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>    </code><code>css: { height: </code><code>"50px"</code><code>, width: </code><code>"50px"</code><code>, color: </code><code>"blue"</code><code>, backgroundColor: </code><code>"#ccc"</code> <code>}, </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>    </code><code>click: </code><code>function</code><code>() { </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>            </code><code>$(</code><code>this</code><code>).css(</code><code>"backgroundColor"</code><code>, </code><code>"red"</code><code>); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>    </code><code>} </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>}).appendTo(</code><code>"body"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>对象里的键值的名字与相关的jQuery的方法的名字是对应的，对象的值会被作为参数传递给jQuery的方法。</p>
<p>(译注:譬如<code>$("&lt;a&gt;link&lt;/a&gt;", {css:{background:"#ccc"}});</code>相当于<code>$("&lt;a&gt;link&lt;/a&gt;")).css("background", "#ccc");</code></p>
<p><strong>.eq(-N), .get(-N) (负指数)</strong> (<a href="http://api.jquery.com/eq/" target="_blank">.eq() 文档</a>, <a href="http://api.jquery.com/get/" target="_blank">.get() 文档</a>, <a href="http://github.com/jquery/jquery/commit/e532dfe5228217f55a33122a4438fd70522dbb4b" target="_blank">Commit</a>)</p>
<p>你现在可以在<code>.get()</code>和<code>.eq()</code>方法里使用负数。譬如，你要选择倒数第2个div元素，或者是倒数第2个DOM对象:</p>
<div id="highlighter_7776">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>$(</code><code>"div"</code><code>).eq(-2); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>$(</code><code>"div"</code><code>).get(-2);</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><strong>新的.first()和.last()方法</strong> (<a href="http://api.jquery.com/first/" target="_blank">.first() 文档</a>, <a href="http://api.jquery.com/last/" target="_blank">.last() 文档</a>, <a href="http://github.com/jquery/jquery/commit/9de120e6d7cfffa3d990a6ccf23db3cd74e2bdc0" target="_blank">Commit</a>)</p>
<p>方便起见, 新增的<code>.first()</code>和<code>.last()</code>方法等同于<a href="http://api.jquery.com/eq/" target="_blank">.eq(0)</a>和<a href="http://api.jquery.com/eq/" target="_blank">.eq(-1)</a>.</p>
<p><strong>新的.toArray()方法</strong> (<a href="http://api.jquery.com/toArray/" target="_blank">.toArray() 文档</a>, <a href="http://github.com/jquery/jquery/commit/e124fec5e9cfee77cb23b27c0d43dc2631c83aab" target="_blank">Commit</a>)</p>
<p><a href="http://api.jquery.com/get" target="_blank">.get()</a>方法自始就是从jQuery集合里返回一个阵列。为了能够更明确, 你可以用<a href="http://api.jquery.com/toArray/" target="_blank">.toArray()</a>来达到一样的效果。(译注:这里应该是为了以后的版本留出空间，譬如以后可能会加入.toList()方法，到时候就会易于区分。) 不过，和<code>.get()</code>不一样的是，<code>.toArray()</code>不接受参数。</p>
<p><strong>jQuery()返回一个空集</strong> (<a href="http://api.jquery.com/jQuery/" target="_blank">jQuery() 文档</a>, <a href="http://github.com/jquery/jquery/commit/04524287d3e0112deae570ff9247c734833431bb" target="_blank">Commit</a>)</p>
<p>在jQuery 1.3中,<a href="http://api.jquery.com/jQuery/" target="_blank">jQuery()</a>方法返回仅包括<code>document</code>的jQuery集合。这个可以用来创建一个空集，然后动态加入一些元素。注: <code>jQuery().ready()</code>方式在1.4中依然有效，但是被指示陈旧了。请使用<code>jQuery(document).ready()</code>或者<code>jQuery(function(){})</code>。</p>
<p><strong>jQuery(“TAG”)</strong> (<a href="http://api.jquery.com/element-selector/" target="_blank">Element Selector 文档</a>, <a href="http://github.com/jquery/jquery/commit/4ea4fad0902839c06c281b5de7b0aca29922b63d" target="_blank">Commit</a>)</p>
<p>当使用单个标签名字的时候jQuery会使用更快捷的路径。</p>
<p><strong>jQuery(“&lt;div&gt;”), jQuery(“&lt;div/&gt;”) 和 jQuery(“&lt;div&gt;&lt;/div&gt;”)</strong> (<a href="http://api.jquery.com/jQuery/#jQuery2" target="_blank">jQuery() 文档</a>, <a href="http://github.com/jquery/jquery/commit/c4c820efff4fa7bcce0d5bf0a448625278ea6379" target="_blank">Commit</a>)</p>
<p>现在这三个方法都使用同一个代码路径了(document.createElement), 来优化<code>jQuery("&lt;div&gt;&lt;/div&gt;")</code>的性能。注意，如果你指定了属性，将会使用浏览器本身的语法分析(通过设置innerHTML)。</p>
<h4>样式 (CSS)</h4>
<p><strong>.css()方法在性能是以前的2倍。</strong></p>
<p><a rel="lightbox[69]" href="http://www.uxd2.com/wp-content/uploads/2010/01/03-perform-css.jpg" target="_blank"><img title=".css()的性能提高 " src="http://www.uxd2.com/wp-content/uploads/2010/01/03-perform-css.jpg" alt=".css()的性能提高 " width="500" height="375" /></a></p>
<p><strong><code>.addClass()</code>, <code>.removeClass()</code>, 和 <code>.hasClass()</code>这几个方法在性能上是以前的3倍</strong></p>
<p><a rel="lightbox[69]" href="http://www.uxd2.com/wp-content/uploads/2010/01/04-perform-addClass.jpg" target="_blank"><img title="addClass, removeClass, 和 hasClass的性能提高" src="http://www.uxd2.com/wp-content/uploads/2010/01/04-perform-addClass.jpg" alt="addClass, removeClass, 和 hasClass的性能提高" width="500" height="375" /></a></p>
<p><strong>.toggleClass()可以切换多个css类了</strong> (<a href="http://api.jquery.com/toggleClass/" target="_blank">.toggleClass() 文档</a>, <a href="http://github.com/jquery/jquery/commit/5e6e53835e552920db4f88ac0c9eca71aaacbef0" target="_blank">Commit</a>)</p>
<p>你可以通过<a href="http://api.jquery.com/toggleClass/" target="_blank">.toggleClass()</a>调用多个css类的名字来切换他们。</p>
<div id="highlighter_622970">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>$(</code><code>"div"</code><code>).toggleClass(</code><code>"current active"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<h4>数据</h4>
<p><strong>.data()返回对象, .data(Object)设置对象</strong> (<a href="http://api.jquery.com/data/" target="_blank">.data() 文档</a>, <a href="http://github.com/jquery/jquery/commit/d36d224cc52e70d837306d33a03f517ef72abc60" target="_blank">Commit 1</a>, <a href="http://github.com/jquery/jquery/commit/f6a0bf6816f4e2e67382b1b13fdd3ff2ea4b22f8" target="_blank">Commit 2</a>)</p>
<p>有时候你可能需要在一个元素上附加一个复杂的对象。一个常见的例子是你需要从一个元素身上复制所有的数据到令一个元素上。在jQuery 1.4里, 不使用任何参数调用<a href="http://api.jquery.com/data/" target="_blank">.data()</a>时，.data会返回一个复杂对象。(译注: 包含所有键-值对的对象。) 调用<a href="http://api.jquery.com/data/" target="_blank">.data(Object)</a> 则会设置这个对象。注意这个对象还包括了元素上绑定的事件，所以用的时候要小心。</p>
<p><strong>除非需要, 不然不会创建数据缓存。</strong> (<a href="http://github.com/jquery/jquery/commit/c4f144eeffd94c745839b0ced2de9c62cfa9f075" target="_blank">Commit 1</a>, <a href="http://github.com/jquery/jquery/commit/97e134fe80a734b97170bf43c9459511f4e165c7" target="_blank">Commit 2</a>, <a href="http://github.com/jquery/jquery/commit/67d445a703491c90a7d3c46be34bcdceb4d1c896" target="_blank">Commit 3</a>)</p>
<p>jQuery使用一个独特的自定义属性来获取特定元素上附加的数据。当查找数据，但是没有新加的数据的时候，jQuery会尽量避免创建这个自定义属性。这样可能会提高性能，同时还会在这种情况下避免污染DOM。</p>
<h4>效果 (Effects)</h4>
<p><strong>单个属性缓进缓出</strong> (<a href="http://api.jquery.com/animate/#per-property-easing" target="_blank">Per-property Easing 文档</a>, <a href="http://github.com/jquery/jquery/commit/93fdbeb963a9c350f807818c7cc99982942a92f3" target="_blank">Commit</a>)</p>
<p>除了能够给一个动态效果指定缓进出函数外，你现在可以指定每个属性的缓进出函数了。James Padolsey的<a href="http://james.padolsey.com/javascript/easing-in-jquery-1-4a2/" target="_blank">blog上</a>有更进一步的信息和演示。</p>
<div id="highlighter_25150">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>$(</code><code>"#clickme"</code><code>).click(</code><code>function</code><code>() { </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>  </code><code>$(</code><code>"div"</code><code>).animate({ </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>    </code><code>width: [</code><code>"+=200px"</code><code>, </code><code>"swing"</code><code>], </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>    </code><code>height: [</code><code>"+=50px"</code><code>, </code><code>"linear"</code><code>], </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>  </code><code>}, 2000, </code><code>function</code><code>() { </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>      </code><code>$(</code><code>this</code><code>).after(</code><code>"&amp;lt;div&amp;gt;Animation complete.&amp;lt;/div&amp;gt;"</code><code>); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>  </code><code>}); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>});</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<h4>事件 (Events)</h4>
<p><strong>新方法: jQuery.proxy()</strong> (<a href="http://api.jquery.com/jQuery.proxy/" target="_blank">jQuery.proxy() Documenation</a>, <a href="http://github.com/jquery/jquery/commit/66975de2d249643779e2b3daad0457f7f5f92508" target="_blank">Commit 1</a>, <a href="http://github.com/jquery/jquery/commit/1d2b1a57dae0b73b3d99197f73f4edb623b5574a" target="_blank">Commit 2</a>)</p>
<p>如果你需要保证一个函数内的”this”恒定地保持某个值, 你可以用<code>jQuery.proxy</code>获得一个相同作用域的函数。</p>
<div id="highlighter_957088">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>var</code> <code>obj = { </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>  </code><code>name: </code><code>"John"</code><code>, </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>  </code><code>test: </code><code>function</code><code>() { </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>    </code><code>alert( </code><code>this</code><code>.name ); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>    </code><code>$(</code><code>"#test"</code><code>).unbind(</code><code>"click"</code><code>, obj.test); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>  </code><code>} </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>}; </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code> </code> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>$(</code><code>"#test"</code><code>).click( jQuery.proxy( obj, </code><code>"test"</code> <code>) );</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><strong>多个事件绑定</strong> (<a href="http://api.jquery.com/bind" target="_blank">.bind() 文档</a>)</p>
<p>你可以通过递入一个对象来一次性绑定元素的多个事件。</p>
<div id="highlighter_298686">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>01</code></td>
<td><code>$(</code><code>"div.test"</code><code>).bind({ </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>02</code></td>
<td><code>  </code><code>click: </code><code>function</code><code>(){ </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>03</code></td>
<td><code>    </code><code>$(</code><code>this</code><code>).addClass(</code><code>"active"</code><code>); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>04</code></td>
<td><code>  </code><code>}, </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>05</code></td>
<td><code>  </code><code>mouseenter: </code><code>function</code><code>(){ </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>06</code></td>
<td><code>    </code><code>$(</code><code>this</code><code>).addClass(</code><code>"inside"</code><code>); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>07</code></td>
<td><code>  </code><code>}, </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>08</code></td>
<td><code>  </code><code>mouseleave: </code><code>function</code><code>(){ </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>09</code></td>
<td><code>    </code><code>$(</code><code>this</code><code>).removeClass(</code><code>"inside"</code><code>); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>  </code><code>} </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>});</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><strong>‘change’和’submit’事件规范化</strong> (<a href="http://api.jquery.com/change" target="_blank">Change 文档</a>, <a href="http://api.jquery.com/submit" target="_blank">Submit 文档</a>)</p>
<p>普通的或是即时的<code>change</code>和<code>submit</code>事件可以在各种浏览器上稳定工作了。我们覆盖了IE里的<code>change</code>和<code>submit</code>, 替换为与其他浏览器相同的事件。</p>
<p><strong>新的事件: ‘focusin’ and ‘focusout’</strong> (<a href="http://api.jquery.com/focusin/" target="_blank">.focusin() 文档</a>, <a href="http://api.jquery.com/focusout/" target="_blank">.focusout() 文档</a>, <a href="http://github.com/jquery/jquery/commit/03481a52c72e417b01cfeb499f26738cf5ed5839" target="_blank">Commit</a>)</p>
<p><code>focusin</code>和<code>focusout</code>在一般情况下等同于<code>focus</code>和<code>blur</code>, 但是多了向父元素传递的作用。如果你自己编写你的事件代理模式(TODO), 这个功能将对你有很大帮助。请注意对<code>focus</code>和<code>blur</code>使用<code>live()</code>方法将不会起作用; 在设计的时候我们根据 <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html" target="_blank">DOM事件规范</a>决定不使其向父元素传递事件。</p>
<div id="highlighter_638453">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>$(</code><code>"form"</code><code>).focusout(</code><code>function</code><code>(event) { </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>    </code><code>var</code> <code>tgt = event.target; </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>    </code><code>if</code> <code>(tgt.nodeName == </code><code>"INPUT"</code> <code>&amp;amp;&amp;amp; !tgt.value) { </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>        </code><code>$(tgt).after(</code><code>"nothing here"</code><code>); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>    </code><code>} </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>});</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><strong>所有的事件都可以成为即时事件</strong> (<a href="http://api.jquery.com/live" target="_blank">.live() 文档</a>)</p>
<p>除了<a href="http://api.jquery.com/ready" target="_blank">ready</a>, <a href="http://api.jquery.com/focus" target="_blank">focus</a> (用focusin), 和 <a href="http://api.jquery.com/blur" target="_blank">blur</a> (用focusout)以外, 所有能用<code>.bind()</code>绑定的事件都可以成为即时事件。</p>
<p>在<code>live()</code>所支持的事件里，我们对能够支持下面这几个额外的事件感到尤其骄傲。通过<code>.live()</code>里的事件代理, 1.4版实现了对<code>change</code>, <code>submit</code>, <code>focusin</code>, <code>focusout</code>, <code>mouseenter</code>, 以及<code>mouseleave</code>事件的跨浏览器支持。</p>
<p>注: 如果你需要即时的<code>focus</code>事件，你应该用<code>focusin</code>和<code>focusout</code>, 而不要用<code>focus</code>和<code>blur</code>, 因为就像前面提到的, <code>focus</code>和<code>blur</code>不向上传递。</p>
<p>还有, <code>live()</code>也接受数据对象作为参数了, 同<code>bind()</code>方法一样 (<a href="http://github.com/jquery/jquery/commit/71efbdd3b26f3a283f8d4bfdcc7b6343142027b9" target="_blank">Commit</a>)</p>
<p><strong>live/die也支持环境变量了</strong> (<a href="http://github.com/jquery/jquery/commit/30e760b63fd6d82f30833cd2864f245dd9594cd9" target="_blank">Commit</a>)</p>
<p>现在可以在绑定事件的时候给选择符指定一个环境。如果环境被指定了, 只有属于这个环境下的元素才会被绑定事件。在创建即时事件的时候, 元素本身不需要已经被定义, 但是环境必须被创建。</p>
<p><strong>确定ready事件至少含有<code>body</code>元素</strong> (<a href="http://github.com/jquery/jquery/commit/262fcf7b7b919da1564509f621cf7480a5d5572b" target="_blank">Commit</a>)</p>
<p>jQuery现在会检查<code>body</code>是不是存在，如果不存在，会对<code>body</code>进行轮流探询。</p>
<p><strong>在不需要手动处理内存溢出的非IE浏览器中, 卸载的速度提高了。</strong> (<a href="http://github.com/jquery/jquery/commit/f3474c00cd6d9e5fd61b6ef1562003e9986ad67d" target="_blank">Commit</a>)</p>
<h4>DOM操作 (Manipulation)</h4>
<p>在jQuery 1.4里一系列的DOM操作方法的性能都有巨大的提升。</p>
<p><strong><a href="http://api.jquery.com/append" target="_blank">.append()</a>, <a href="http://api.jquery.com/prepend" target="_blank">.prepend()</a>, <a href="http://api.jquery.com/before" target="_blank">.before()</a>, and <a href="http://api.jquery.com/after" target="_blank">.after()</a>的性能提高了。</strong></p>
<p><a rel="lightbox[69]" href="http://www.uxd2.com/wp-content/uploads/2010/01/05-perform-dom.jpg" target="_blank"><img title="DOM嵌入的性能提高" src="http://www.uxd2.com/wp-content/uploads/2010/01/05-perform-dom.jpg" alt="DOM嵌入的性能提高" width="500" height="375" /></a></p>
<p><strong><a href="http://api.jquery.com/html" target="_blank">.html()</a>的性能提高到以前的3倍。</strong></p>
<p><a rel="lightbox[69]" href="http://www.uxd2.com/wp-content/uploads/2010/01/06-perform-html.jpg" target="_blank"><img title=".html()的性能提高" src="http://www.uxd2.com/wp-content/uploads/2010/01/06-perform-html.jpg" alt=".html()的性能提高" width="500" height="375" /></a></p>
<p><strong>.remove()和.empty()的速度则达到以前的4倍.</strong></p>
<p><a rel="lightbox[69]" href="http://www.uxd2.com/wp-content/uploads/2010/01/07-perform-remove.jpg" target="_blank"><img title=".remove() 和 .empty()的性能提高" src="http://www.uxd2.com/wp-content/uploads/2010/01/07-perform-remove.jpg" alt=".remove() 和 .empty()的性能提高" width="500" height="375" /></a></p>
<p><strong>新方法: .detach()</strong> (<a href="http://api.jquery.com/detach/" target="_blank">.detach() 文档</a>, <a href="http://github.com/jquery/jquery/commit/7a67f8897d3c2ed97254f0fdb969be14e77962d1" target="_blank">Commit</a>)</p>
<p><code>detach()</code>将一个元素从DOM里移除, 但是并不卸载关联的事件处理函数。这个方法可用于暂时性的将一个元素移除，执行相关操作，然后返回。</p>
<div id="highlighter_234600">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>var</code> <code>foo = $(</code><code>"#foo"</code><code>).click(</code><code>function</code><code>() { </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>    </code><code>// 相关操作 </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>}); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>foo.detach(); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>// foo保留了相关处理函数 </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>foo.appendTo(</code><code>"body"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><strong>新的unwrap()方法</strong> (<a href="http://api.jquery.com/unwrap/" target="_blank">documentation</a>, <a href="http://github.com/jquery/jquery/commit/69e6e53555f21f07b534f1169298f7b33011bb4b" target="_blank">commit</a>)</p>
<p><code>unwrap()</code>方法拿到一个已知的父元素的子元素，然后将父元素用子元素替换。(译注: 将子元素从”包裹”里拿出来, 因名unwrap)。如此这般:</p>
<div id="highlighter_384265">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>01</code></td>
<td><code>&lt;</code><code>body</code><code>&gt; </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>02</code></td>
<td><code>    </code><code>&lt;</code><code>div</code><code>&gt; </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>03</code></td>
<td><code>        </code><code>&lt;</code><code>p</code><code>&gt;annie&lt;/</code><code>p</code><code>&gt; &lt;</code><code>p</code><code>&gt;davey&lt;/</code><code>p</code><code>&gt; &lt;</code><code>p</code><code>&gt;stevie&lt;/</code><code>p</code><code>&gt; </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>04</code></td>
<td><code>    </code><code>&lt;/</code><code>div</code><code>&gt; </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>05</code></td>
<td><code>&lt;/</code><code>body</code><code>&gt; </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>06</code></td>
<td><code> </code> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>07</code></td>
<td><code>$('div').unwrap(); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>08</code></td>
<td><code> </code> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>09</code></td>
<td><code>&lt;</code><code>body</code><code>&gt; </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>   </code><code>&lt;</code><code>p</code><code>&gt;annie&lt;/</code><code>p</code><code>&gt; &lt;</code><code>p</code><code>&gt;davey&lt;/</code><code>p</code><code>&gt; &lt;</code><code>p</code><code>&gt;stevie&lt;/</code><code>p</code><code>&gt; </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>&lt;/</code><code>body</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><strong>domManip方法里的缓存</strong> (<a href="http://github.com/jquery/jquery/commit/8db967e9d52407c8e76d81b9d472800667f6fa29" target="_blank">commit</a>)</p>
<p>jQuery会将<code>jQuery("&lt;div&gt;")</code>和<code>.after("&lt;div&gt;")</code>一类方法创建的节点记入缓存。这样, 对于利用这些方法, 使用字符串进行DOM操作的页面，性能将有极大的提高。</p>
<p><strong>无连接的节点间的before, after, replaceWith操作</strong> (<a href="http://github.com/jquery/jquery/commit/173c1477ae6efc4c2eeb7131ba0646c4e1323975" target="_blank">commit</a>)</p>
<p>现在你可以对还没有放置到DOM Tree上的节点进行<code>before</code>, <code>after</code>, 和<code>replaceWith</code>的操作了。意味着你可以先对节点进行复杂的操作, 待完成后再放到合适的DOM位置上。这样也能尽量避免操作过程中造成重新排版。</p>
<div id="highlighter_821146">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>jQuery(</code><code>"&lt;div&gt;"</code><code>).before(</code><code>"&lt;p&gt;Hello&lt;/p&gt;"</code><code>).appendTo(</code><code>"body"</code><code>)</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><strong><code>.clone(true)</code> 也会复制关联数据</strong> (<a href="http://api.jquery.com/clone/" target="_blank">clone 文档</a>, <a href="http://github.com/jquery/jquery/commit/4b70f006f579fba24a882d80ca67f1971dbb4922" target="_blank">commit</a>)</p>
<p>1.3版中, <code>.clone(true)</code>虽然也是深度复制, 但是没有复制关联的数据。1.4版里，它则会复制数据, 同时还包括所有的事件。这点上和<code>jQuery.extend</code>在语义想同的, 所以普通对象和阵列会被复制, 但是自定义的对象则不会。</p>
<h4>位移 (Offset)</h4>
<p><strong>.offset( coords | Function )</strong> (<a href="http://api.jquery.com/offset/" target="_blank">.offset() 文档</a>, <a href="http://github.com/jquery/jquery/commit/daffb954e397bd5d9f8e9aaedab6c0baa9609e1e" target="_blank">commit</a>)</p>
<p>现在可以设置元素的位移了! 和所有的设置函数一样, <code>offset</code>也可以接受一个函数作为第二个参数。</p>
<h4>队列 (Queueing)</h4>
<p>队列经历了一次大修, 使用队列会比使用默认的<code>fx</code>更易掌握。</p>
<p><strong>新的 .delay() 方法</strong> (<a href="http://api.jquery.com/delay/" target="_blank">.delay() 文档</a>, <a href="http://github.com/jquery/jquery/commit/bbd933cbfe6d31a749cb336d7a84155ccfab247f" target="_blank">commit</a>)</p>
<p><code>.delay()</code>方法会根据参数滞后若干毫秒执行队列里剩下的对象。默认的它会使用”fx”队列。但你可以选择性的通过<code>delay</code>方法的第二个参数选择其他队列。(译注:每个队列都以一个名字识别。)</p>
<div id="highlighter_971393">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>$(</code><code>"div"</code><code>).fadeIn().delay(4000).fadeOut();</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><strong>队列里的<code>next</code></strong> (<a href="http://api.jquery.com/queue/" target="_blank">.queue() 文档</a>, <a href="http://github.com/jquery/jquery/commit/89b4bc53ca0ca3d4e5c80b94ce92b09cc34af8ef" target="_blank">commit</a>)</p>
<p>jQuery 1.4版里, 当队列里的一个函数被调用的时候，第一个参数会被设为另一个函数。当后者被调用的时候, 会自动排除队列里的下一个对象, 以此来推动队列到下一步。</p>
<div id="highlighter_855540">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>jQuery(</code><code>"div"</code><code>).queue(</code><code>"ajax"</code><code>, </code><code>function</code><code>(next) { </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>  </code><code>var</code> <code>self = </code><code>this</code><code>; </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>  </code><code>jQuery.getJSON(</code><code>"/update"</code><code>, </code><code>function</code><code>(json) { </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>    </code><code>$(self).html(json.text); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>    </code><code>next(); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>  </code><code>}; </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>}).queue(</code><code>"ajax"</code><code>, </code><code>function</code><code>() { </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>  </code><code>$(</code><code>this</code><code>).fadeIn(); </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>});</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><strong>.clearQueue()</strong> (<a href="http://api.jquery.com/clearQueue/" target="_blank">clearQueue 文档</a>, <a href="http://github.com/jquery/jquery/commit/d857315967a1cc07b73924bbdf2eb12f4f910c45" target="_blank">commit</a>)</p>
<p>队列可以被清空了。这个方法会移除队列里所有未执行的函数, 但不会移除正在运行的函数。无参数的情况下调用<code>.clearQueue()</code>方法将会清空默认的”fx”队列。</p>
<h4>选择符 (Selectors)</h4>
<p><strong>“#id p”效率更高</strong> (<a href="http://github.com/jeresig/sizzle/commit/c5c18ae5f17f11b39b7f261633e4bfc5ef3e99d7" target="_blank">commit</a>)</p>
<p>所有以ID开头的选择符都得到了优化, 能够在瞬间得到返回值。所有以ID为开头的选择符速度将一直快于其他选择符。</p>
<h4>页面遍访 (Traversing)</h4>
<p><strong>.index(), .index(String)</strong> (<a href="http://api.jquery.com/index/" target="_blank">index 文档</a>, <a href="http://github.com/jquery/jquery/commit/ffd457d4561eb1a6653aaef90f92a3b3010b9139" target="_blank">commit</a>)</p>
<p><code>.index()</code> 方法经过重写, 变得更加直观和灵活。</p>
<p>你可以获得一个元素相对于同父元素的指数:</p>
<div id="highlighter_308944">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>// 计算第一个 &amp;lt;li&amp;gt; 元素在它所有的同父元素中的指数: </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>$(</code><code>"li.current"</code><code>).index()</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>你也可以获得一个元素在一个jQuery元素集合中的指数, 这个集合可以用一个选择符或者是一个DOM元素来指定:</p>
<div id="highlighter_783938">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>// 计算这个 &amp;lt;h3 id="more-info"&amp;gt; 元素在页面上所有 &amp;lt;h3&amp;gt; 元素里的指数: </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>$(</code><code>"#more-info"</code><code>).index(</code><code>"h3"</code><code>)</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><strong>新的.has()方法</strong> (<a href="http://api.jquery.com/has/" target="_blank">has 文档</a>, <a href="http://github.com/jquery/jquery/commit/4e27f17007c2329e31b449e61bb31197b90a37f1" target="_blank">commit</a>)</p>
<p>这个方法相当于选择符里的<code>:has()</code>过滤法。它拿到一个jQuery集合,返回含有指定选择符的元素。</p>
<p><strong>新的 .nextUntil(), .prevUntil(), .parentsUntil() 方法</strong> (<a href="http://api.jquery.com/nextUntil/" target="_blank">.nextUntil() 文档</a>, <a href="http://api.jquery.com/prevUntil/" target="_blank">.prevUntil() 文档</a>, <a href="http://api.jquery.com/parentsUntil/" target="_blank">.parentsUntil() 文档</a>, <a href="http://github.com/jquery/jquery/commit/2b481b93cfca62f95aa7005e7db651456fa08e65" target="_blank">commit</a>)</p>
<p>新的”until”方法类似于<code>.nextAll()</code>, <code>.prevAll()</code>, 和<code>.parents()</code>。区别是可以用一个选择符来停止元素探索。</p>
<p><strong>.add(String, Element)</strong> (<a href="http://jquery14.com/day-01/%3C/p%3E%3Cp%3Ehttp://api.jquery.com/add/%3C/p%3E%3Cp%3E" target="_blank">.add() 文档</a>, <a href="http://jquery14.com/day-01/%3C/p%3E%3Cp%3Ehttp://github.com/jquery/jquery/commit/b0fe380cf89564305646bbd55d1fd7bd210fd591%3C/p%3E%3Cp%3E" target="_blank">commit</a>)</p>
<p>可以给<code>.add()</code>方法指定环境了。这个功能可以用于在一个调用链中加入和操作额外元素(比如Ajax请求里返回的新元素)。</p>
<p><strong>.closest(filter, DOMElement)</strong> (<a href="http://api.jquery.com/closest/" target="_blank">.closest() 文档</a>, <a href="http://github.com/jquery/jquery/commit/d6991fa273515a8503692324499edcc71b5c3f64" target="_blank">commit</a>)</p>
<p>可以通过<code>closest</code>方法的第2个参数设置一个<code>DOMElement</code>环境。给<code>closest</code>设置一个环境一般能够提高这个方法的运行速度。这个优化也适用<code>live()</code>, 因为这个方法内部调用了<code>closest()</code>。</p>
<h4>常用工具 (Utilities)</h4>
<p><strong>jQuery.isEmptyObject()</strong> (<a href="http://api.jquery.com/jQuery.isEmptyObject/" target="_blank">jQuery.isEmptyObject() 文档</a>, <a href="http://github.com/jquery/jquery/commit/a38a5cd531a328319f8b7f3f33a84044b54591ce" target="_blank">commit</a>)</p>
<p>如果对象,em&gt;没有任何属性, 该方法将返回<code>true</code>。<code>jQuery.isEmptyObject()</code>方法不对参数进行任何检查, 所以请保证参数是一个对象。</p>
<p><strong>jQuery.isPlainObject()</strong> (<a href="http://api.jquery.com/jQuery.isPlainObject/" target="_blank">jQuery.isPlainObject()</a>, <a href="http://github.com/jquery/jquery/commit/4b55e94d0849568a2fd121952f13a9d6571c731f" target="_blank">commit</a> )</p>
<p>如果一个对象是通过字符创建的(译注:{}),<code>jQuery.isPlainObject()</code>返回<code>true</code>; 如果对象是其他类别的对象(译注:如new Object())或者是基本类型, 则返回<code>false</code>。</p>
<p><strong>jQuery.contains()</strong> (<a href="http://api.jquery.com/jQuery.contains/" target="_blank">jQuery.contains() 文档</a>, <a href="http://github.com/jquery/jquery/commit/4e27f17007c2329e31b449e61bb31197b90a37f1" target="_blank">commit</a>)</p>
<p>如果两个参数都是DOM节点，并且第二个节点是嵌套在第一个节点内部的话, <code>jQuery.contains()</code>返回<code>true</code>。反之返回<code>false</code>。</p>
<p><strong>jQuery.noop</strong> (<a href="http://api.jquery.com/jQuery.noop/" target="_blank">jQuery.noop() 文档</a>, <a href="http://github.com/jquery/jquery/commit/6cb2945837ccca55204191a8e7a70b2b2486c28e" target="_blank">commit</a>)</p>
<p>是个空的函数, 可以用在必须要有一个函数的情况下。(译注: noop是No Operation的意思。)</p>
<p><strong>jQuery.unique()</strong> (<a href="http://api.jquery.com/jQuery.unique/" target="_blank">jQuery.unique() 文档</a>)</p>
<p>jQuery 1.4版中, <code>jQuery.unique()</code>方法返回结果里的元素是按照他们在页面里的顺序排序的。由于在创建jQuery集合的时候jQuery使用<code>jQuery.unique()</code>方法, 所以jQuery方法返回的集合也是按照他们在页面里的顺序排列的。</p>
<h4>其他 (Miscellaneous)</h4>
<p><strong>jQuery.browser以浏览器引擎为中心</strong> (<a href="http://api.jquery.com/jQuery.browser/" target="_blank">jQuery.browser 文档</a>, <a href="http://jquery14.com/day-01/%3Cbr%20/%3Ehttp://github.com/jquery/jquery/commit/ffb1867a4364ea65e60dad3469e8c8eb420ebcac" target="_blank">commit</a>)</p>
<p>例如, 你可以通过<code>jQuery.browser.webkit</code>探测引擎是否是Webkit。</p>
<p><strong>改进了对<code>applets</code>的处理</strong> (<a href="http://github.com/jquery/jquery/commit/59802928566b6be3a66d65e77c2418fff37e6f5f" target="_blank">commit 1</a>, <a href="http://github.com/jquery/jquery/commit/3ec2f1aef6b137d0f639e2fc53f95352d24b9d90" target="_blank">commit 2</a>)</p>
<p>jQuery不再试图在Java applets上绑定事件或是数据了(绑定事件或是数据会出现错误)。</p>
<p><strong>不再使用arguments.callee</strong> (<a href="http://github.com/jquery/jquery/commit/985856b823b1648bffc3fd63c1faf836d0ddaf7c" target="_blank">commit</a>)</p>
<p>为了顺应<a href="http://code.google.com/p/google-caja/" target="_blank">Caja</a>的要求, 同时也因为即将开始应用的ECMAScript 5规范里将其标记为陈旧, 我们将jQuery核心中所有用到<code>arguments.callee</code>的代码都移除了。</p>
<p><strong>用Closure Compiler替换了YUI Min</strong> (<a href="http://github.com/jquery/jquery/commit/3fd62eae9df3159fc238a515bb748140a942313d" target="_blank">commit</a>)</p>
<h4>内部重组 (Internal Reorganization)</h4>
<p>在1.4版的开发过程中的一个重点是要建立一个更易读, 更易懂的代码库。为了达到这个目标我们树立了一系列编写代码规范的向导。</p>
<p>下面是一些主要的变化:</p>
<blockquote><p>旧的’core.js’文件被分成了’attribute.js’, ‘css.js’, ‘data.js’, ‘manipulation.js’, ‘traversing.js’, and ‘queue.js’.</p>
<p>ready事件被移入了’core.js’ (因为它是jQuery的一个基本组成之一)。</p>
<p>大部分核心代码都符合新的<a href="http://docs.jquery.com/JQuery_Core_Style_Guidelines" target="_blank">代码规范</a>.</p>
<p>css和属性的逻辑被划分开来, 不再如以往相互缠绕。</p></blockquote>
<h4>测试 (Testing)</h4>
<p>jQuery 1.4版发布过程中我们<a href="http://dev.jquery.com/report/34" target="_blank">修复了207个问题</a> (比较之下1.3版里有97个修复)。</p>
<p>jQuery 1.4.此外, 测试的数量从jQuery 1.3.2中的1504例升到了1.4中的3060例。</p>
<p>所有测试都在主要浏览器里完全通过了。(Safari 3.2, Safari 4, Firefox 2, Firefox 3, Firefox 3.5, IE 6, IE 7,<br />
IE 8, Opera 10.10, and Chrome)</p>
<p><a rel="lightbox[69]" href="http://www.uxd2.com/wp-content/uploads/2010/01/08-test.jpg" target="_blank"><img title="jQuery 1.4 测试结果" src="http://www.uxd2.com/wp-content/uploads/2010/01/08-test.jpg" alt="jQuery 1.4 测试结果" width="500" height="277" /></a></p>
<h1><a name="backwards" target="_blank"></a></h1>
<p>我们尽量试图减小jQuery 1.4对大规模升级可能造成的麻烦 – 保持所有公开函数的签名不变。即使如此, 请通读下面的列表以保证你对可能对你的应用造成问题的变更。</p>
<blockquote><p><a href="http://api.jquery.com/add" target="_blank">.add()</a>不再简单的将结果串联到一起, 结果将会被混合到一起, 然后根据他们在页面里的顺序排列。</p>
<p><a href="http://api.jquery.com/clone" target="_blank">.clone(true)</a>将复制事件和数据, 而不仅是事件。</p>
<p><a href="http://api.jquery.com/jQuery.data" target="_blank">jQuery.data(elem)</a> 不再返回<code>id</code>, 取而代之的是元素的对象缓存。</p>
<p><a href="http://api.jquery.com/jQuery" target="_blank">jQuery()</a> (无参数) 不再自动转换成<a href="http://api.jquery.com/jQuery" target="_blank">jQuery(document)</a>了。</p>
<p>通过<a href="http://api.jquery.com/val" target="_blank">.val(“…”)</a>获得一个<code>option</code>或一个<code>checkbox</code>的值不再有歧义(将总是根据<code>value</code>属性选择, 而不是根据<code>text</code>的值)。(<a href="http://github.com/jquery/jquery/commit/f298cce100c6fe23840ac95e66aaea9cb2bfb447" target="_blank">Commit</a>)</p>
<p><a href="http://api.jquery.com/jQuery.browser" target="_blank">jQuery.browser.version</a>现在将返回引擎的版本.</p>
<p>现在起将对引入的JSON更严格, 如果JSON的格式不符将会报错。如果你需要对不符合JSON严格格式的Javascript进行估值, 你必须设置请求的文件类型为纯文本, 然后用<code>eval()</code>来对内容估值。</p>
<p>参数序列化默认会按照PHP/Rails的风格进行。你可以通过<code>jQuery.ajaxSettings.traditional = true;</code>来切换到旧的序列化方式。你也可以针对个别请求进行切换, 在调用<a href="http://api.jquery.com/jQuery.ajax" target="_blank">jQuery.ajax</a>的时候递入<code>{traditional: true}</code></p>
<p>内部的jQuery.className被移除了。</p>
<p><a href="http://api.jquery.com/jQuery.extend" target="_blank">jQuery.extend(true, …)</a>不再扩展复杂对象或是阵列。(TODO)</p>
<p>如果一个<a href="http://api.jquery.com/jQuery.ajax" target="_blank">Ajax请求</a>没有指定dataType, 而返回的数据类型是”text/javascript”, 那么回复将会被执行。之前, 必须明确的指定dataType。</p>
<p>设置<a href="http://api.jquery.com/jQuery.ajax" target="_blank">Ajax 请求</a>的”ifModified”属性会将ETags纳入考虑。</p></blockquote>
<p>我们还针对1.4版中可能造成问题的变更编写了一个向后兼容的<a href="http://github.com/jquery/jquery-compat-1.3" target="_blank">插件</a>。如果你升级到1.4以后出现问题, 可以在引入1.4版的文件之后引入这个插件。</p>
<p>如何使用这个插件:</p>
<div id="highlighter_898726">
<div>
<div><a title="帮助" href="http://www.oncoding.cn/2010/jquery-14-released/#about"></a></div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>&lt;</code><code>script</code> <code>src</code><code>=</code><code>"<a href="http://code.jquery.com/jquery.js">http://code.jquery.com/jquery.js</a>"</code><code>&gt;&lt;/</code><code>script</code><code>&gt; </code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>&lt;</code><code>script</code> <code>src</code><code>=</code><code>"<a href="http://code.jquery.com/jquery.compat-1.3.js">http://code.jquery.com/jquery.compat-1.3.js</a>"</code><code>&gt;&lt;/</code><code>script</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<h3>原始数据和测试页面</h3>
<p>性能测试中我们使用了下列测试套包:</p>
<blockquote><p><a href="http://ejohn.org/files/jquery1.4/slick/?type=attr" target="_blank">Attributes</a></p>
<p><a href="http://ejohn.org/files/jquery1.4/slick/?type=class" target="_blank">Class</a></p>
<p><a href="http://ejohn.org/files/jquery1.4/slick/?type=dom" target="_blank">DOM Manipulation</a></p>
<p><a href="http://ejohn.org/files/jquery1.4/slick/?type=empty" target="_blank">Empty/Remove</a></p>
<p>Function Call Profiling: <a href="http://ejohn.org/files/jquery-profile.html" target="_blank">1.3.2</a> <a href="http://ejohn.org/files/jquery-profile-14.html" target="_blank">1.4</a>.</p></blockquote>
<p>结果的原始数据 (所有的数据都是 1.3.2 vs. 1.4):</p>
<blockquote><p>函数调用的次数<br />
547 3<br />
760 3<br />
500 200<br />
896 399<br />
23909 299<br />
307 118<br />
28955 100<br />
28648 201<br />
1662 593</p>
<p>DOM嵌入<br />
558 317<br />
1079 624<br />
1079 516<br />
1155 829<br />
436 332<br />
196 194<br />
243 169</p>
<p>HTML<br />
116 46<br />
281 78<br />
313 78<br />
234 63<br />
134 43<br />
43 42<br />
91 27</p>
<p>CSS/属性<br />
703 370<br />
1780 1250<br />
1765 1250<br />
1157 749<br />
629 498<br />
346 184<br />
333 161</p>
<p>CSS<br />
114 52<br />
203 93<br />
118 93<br />
109 47<br />
116 54<br />
58 24<br />
54 22</p>
<p>CSS类<br />
553 138<br />
1578 546<br />
1515 501<br />
1033 327<br />
769 298<br />
229 80<br />
173 41</p>
<p>移除/清空<br />
3298 286<br />
9030 2344<br />
7921 1703<br />
5282 1266<br />
2898 303<br />
1166 140<br />
1034 122</p></blockquote>
<h2  class="related_post_title">您可能感兴趣的文章</h2><ul class="related_post"><li><a href="http://www.52shidai.com/wordpress/506.html" title="wordpress采集插件—wp-o-matic使用详解">wordpress采集插件—wp-o-matic使用详解</a></li><li><a href="http://www.52shidai.com/javascript/jquery/127.html" title="jQuery:1.4新版本中你应该知道的15个新特性(二)">jQuery:1.4新版本中你应该知道的15个新特性(二)</a></li><li><a href="http://www.52shidai.com/javascript/jquery/125.html" title="jQuery:1.4新版本中你应该知道的15个新特性(一)">jQuery:1.4新版本中你应该知道的15个新特性(一)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.52shidai.com/javascript/jquery/401.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery:1.4新版本中你应该知道的15个新特性(二)</title>
		<link>http://www.52shidai.com/javascript/jquery/127.html</link>
		<comments>http://www.52shidai.com/javascript/jquery/127.html#comments</comments>
		<pubDate>Sun, 21 Feb 2010 03:26:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[新版]]></category>
		<category><![CDATA[特性]]></category>

		<guid isPermaLink="false">http://52shidai.com/?p=127</guid>
		<description><![CDATA[九、去除标签元素的父标签： 在之前的版本中已经有了.wrap()方法来个标签添加新的父标签，而在1.4新版本中又添加了相对的.unwrap()方法来去除标签的父标签。实例Html代码如下： 1 2 3 &#60;div&#62; &#60;p&#62;Foo&#60;/p&#62; &#60;/div&#62; jQuery1.4版本中实现代码： 1 jQuery('p').unwrap(); 执行后的话题Html代码如下: 1 &#60;p&#62;Foo&#60;/p&#62;   &#62;&#62;&#62;&#62;阅读更多关于.unwrap()方法的资料… 十、不用删除数据，即可删除掉DOM中的标签元素： 新版本中的.detach()方法允许你删除DOM中的任何标签元素，就像.remove()方法一样。但它与.remove()方法的不同之处是：.remove()是将标签直接删除，而.detach()方法则是将标签暂时移除，并通过方法内部调用.data()方法将标签缓存后赋予变量，再后面的代码中若还需要找回该标签，变量则会自动读取缓存的数据；另外若被.detach()方法移除的标签在移除前绑定了事件机制的话，在后面恢复后，该事件机制依然存在，无需再次绑定。 jQuery1.4版本中实现代码： 1 2 3 4 5 6 7 8 9 10 11 12 13 14 var foo = jQuery('#foo'); // Bind an important event handler foo.click(function(){ alert('Foo!'); }); foo.detach(); // Remove it from the DOM // … [...]]]></description>
			<content:encoded><![CDATA[<h3>九、去除标签元素的父标签：</h3>
<p>在之前的版本中已经有了.wrap()方法来个标签添加新的父标签，而在1.4<span class='wp_keywordlink_affiliate'><a href="http://www.52shidai.com/tag/%e6%96%b0%e7%89%88" title="查看 新版 中的全部文章" target="_blank">新版</a></span>本中又添加了相对的.unwrap()方法来去除标签的父标签。实例Html代码如下：</p>
<div>
<table>
<tbody>
<tr id="p10541">
<td>
<pre>1
2
3</pre>
</td>
<td id="p1054code1">
<pre>&lt;div&gt;
    &lt;p&gt;Foo&lt;/p&gt;
&lt;/div&gt;</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p><small>jQuery1.4版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p10542">
<td>
<pre>1</pre>
</td>
<td id="p1054code2">
<pre>jQuery('p').unwrap();</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>执行后的话题Html代码如下:</p>
<div>
<table>
<tbody>
<tr id="p10543">
<td>
<pre>1</pre>
</td>
<td id="p1054code3">
<pre>&lt;p&gt;Foo&lt;/p&gt;</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p> </p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a rel="external" href="http://api.jquery.com/unwrap/" target="_blank">.unwrap()</a>方法的资料…</p>
<h3>十、不用删除数据，即可删除掉DOM中的标签元素：</h3>
<p><span class='wp_keywordlink_affiliate'><a href="http://www.52shidai.com/tag/%e6%96%b0%e7%89%88" title="查看 新版 中的全部文章" target="_blank">新版</a></span>本中的.detach()方法允许你删除DOM中的任何标签元素，就像.remove()方法一样。但它与.remove()方法的不同之处是：.remove()是将标签直接删除，而.detach()方法则是将标签暂时移除，并通过方法内部调用.data()方法将标签缓存后赋予变量，再后面的代码中若还需要找回该标签，变量则会自动读取缓存的数据；另外若被.detach()方法移除的标签在移除前绑定了事件机制的话，在后面恢复后，该事件机制依然存在，无需再次绑定。<br />
<small>jQuery1.4版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p10544">
<td>
<pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14</pre>
</td>
<td id="p1054code4">
<pre>var foo = jQuery('#foo');

// Bind an important event handler
foo.click(function(){
    alert('Foo!');
});

foo.detach(); // Remove it from the DOM

// … do stuff

foo.appendTo('body'); // Add it back to the DOM

foo.click(); // alerts "Foo!"</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p> </p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a rel="external" href="http://api.jquery.com/detach" target="_blank">.detach()</a>方法的资料…</p>
<h3>十一、对.index()方法进行了扩展：</h3>
<p>1.4新版本中新增了两个.index()的调用方法。而之前，我们将一个标签元素作为.index()方法的参数，并希望执行后返回一个标识当前集合中匹配元素序列号的数字结果。</p>
<p><small>若有一段XHtml代码如下：</small></p>
<div>
<table>
<tbody>
<tr id="p10545">
<td>
<pre>1
2
3
4
5
6
7
8</pre>
</td>
<td id="p1054code5">
<pre>&lt;ul&gt;
    &lt;li&gt;Apple&lt;/li&gt;
    &lt;li&gt;Banana&lt;/li&gt;
    &lt;li&gt;Grape&lt;/li&gt;
    &lt;li&gt;Strawberry&lt;/li&gt;
    &lt;li&gt;Pear&lt;/li&gt;
    &lt;li&gt;Peach&lt;/li&gt;
&lt;/ul&gt;</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>点击li标签获得该li标签的序号</p>
<p><small>jQuery1.32版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p10546">
<td>
<pre>1
2
3</pre>
</td>
<td id="p1054code6">
<pre>$('li').click(function() {
       alert($('li').index(this));
});</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p><small>jQuery1.4版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p10547">
<td>
<pre>1
2
3
4
5
6
7
8
9</pre>
</td>
<td id="p1054code7">
<pre>$('li').click(function() {
       alert($(this).index());
});

//或者

$('li').click(function() {
	alert($(this).index('li'));
});</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p> </p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a rel="external" href="http://api.jquery.com/index" target="_blank">.index()</a>方法的资料…</p>
<h3>十二、DOM控制方法支持回调函数：</h3>
<p>在1.4版本中绝大部分的DOM控制方法只支持回调函数作为唯一的参数，除了极个别的（比如：.attr()、.css()）方法中可以作为第二参数。这些回调函数将被匹配集合中所有元素所执行，<br />
以确定哪些应作为该方法的实际值。</p>
<p>下面的这些DOM控制方法都支持回调函数：</p>
<ul>
<li><a href="http://api.jquery.com/after" target="_blank">after</a></li>
<li><a href="http://api.jquery.com/before" target="_blank">before</a></li>
<li><a href="http://api.jquery.com/append" target="_blank">append</a></li>
<li><a href="http://api.jquery.com/prepend" target="_blank">prepend</a></li>
<li><a href="http://api.jquery.com/addClass" target="_blank">addClass</a></li>
<li><a href="http://api.jquery.com/toggleClass" target="_blank">toggleClass</a></li>
<li><a href="http://api.jquery.com/removeClass" target="_blank">removeClass</a></li>
<li><a href="http://api.jquery.com/wrap" target="_blank">wrap</a></li>
<li><a href="http://api.jquery.com/wrapAll" target="_blank">wrapAll</a></li>
<li><a href="http://api.jquery.com/wrapInner" target="_blank">wrapInner</a></li>
<li><a href="http://api.jquery.com/val" target="_blank">val</a></li>
<li><a href="http://api.jquery.com/text" target="_blank">text</a></li>
<li><a href="http://api.jquery.com/replaceWith" target="_blank">replaceWith</a></li>
<li><a href="http://api.jquery.com/css" target="_blank">css</a></li>
<li><a href="http://api.jquery.com/attr" target="_blank">attr</a></li>
<li><a href="http://api.jquery.com/html" target="_blank">html</a></li>
</ul>
<p>在回调方法中，若你想访问该匹配集合的话，你需要使用”this”，或者序号index作为该方法的第一个参数。<br />
<small>jQuery1.4版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p10548">
<td>
<pre>1
2
3</pre>
</td>
<td id="p1054code8">
<pre>jQuery('li').html(function(i){
    return 'Index of this list item: ' + i;
});</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>当然你可以给该回调函数传递第二个参数，比如是在使用设置类的DOM控制方法（如：.html()、.attr()等），你若想得到当前的值。</p>
<p><small>jQuery1.4版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p10549">
<td>
<pre>1
2
3</pre>
</td>
<td id="p1054code9">
<pre>jQuery('a').attr('href', function(i, currentHref){
    return currentHref + '?foo=bar';
});</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p> </p>
<p>正如你看到的一样，在使用.attr()和.css()方法是，当该方法的第一个是属性名称时，你可以将回调函数作为方法的第二参数。</p>
<p><small>jQuery1.4版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p105410">
<td>
<pre>1
2
3</pre>
</td>
<td id="p1054code10">
<pre>jQuery('li').css('color', function(i, currentCssColor){
    return i % 2 ? 'red' : 'blue';
});</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p> </p>
<h3>十三、检测对象类型方法：</h3>
<p>jQuery1.4新版本在命名空间下新增了两个帮助型的方法，用来帮助你检测对象类型。</p>
<p>第一个方法：.isEmptyObject()用来判断一个对象是否是空对象，返回一个布尔类型的结果；<br />
第二个方法：.isPlainObject()用来判断一个对象是否是最原始的Javascript对象(该对象是否是通过{}或者new Object()创建)，同样也返回一个布尔类型的结果。</p>
<p><small>jQuery1.4版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p105411">
<td>
<pre>1
2
3
4
5
6</pre>
</td>
<td id="p1054code11">
<pre>jQuery.isEmptyObject({}); // true
jQuery.isEmptyObject({foo:1}); // false

jQuery.isPlainObject({}); // true
jQuery.isPlainObject(window); // false
jQuery.isPlainObject(jQuery()); // false</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p> </p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a rel="external" href="http://api.jquery.com/jQuery.isEmptyObject" target="_blank">.isEmptyObject()</a><a rel="external" href="http://api.jquery.com/jQuery.isPlainObject" target="_blank">.isPlainObject()</a>方法的资料…</p>
<h3>十四、.Closest()方法扩展：</h3>
<p>扩展后的.Closest()支持数组选择器作为参数，这在遍历一个元素的祖先元素时非常有用。</p>
<div>
<table>
<tbody>
<tr id="p105412">
<td>
<pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14</pre>
</td>
<td id="p1054code12">
<pre>&lt; !DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;style&gt;&lt;/style&gt;
  &lt;script src="/scripts/jquery-1.4.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;ul&gt;&lt;li&gt;&lt;/li&gt;&lt;li&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;script&gt;var close = $("li:first").closest(["ul", "body"]);
$.each(close, function(i){
  $("li").eq(i).html( this.selector + ": " + this.elem.nodeName );
});&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>执行后的结果是：</p>
<div>
<table>
<tbody>
<tr id="p105413">
<td>
<pre>1
2</pre>
</td>
<td id="p1054code13">
<pre>    * ul: UL
    * body: BODY</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p> </p>
<p>另外该方法还支持使用上下文对象作为它的第二参数，也就是说你可以遍历任意上下文对象直到的元素的祖先元素。这个扩展使用的列子非常少，但在内部使用时非常的有效率。</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a rel="external" href="http://api.jquery.com/closest" target="_blank">.closest()</a>方法的资料…</p>
<h3>十四、新的事件机制（focusIn 、focusOut）：</h3>
<p>新版本中若要给事件对象委派”focus”和”blur”事件，也可以使用.focusIn()和.focusOut()方法（它们是一一对应的）。更加重要的是focus和blur事件不支持.live()方法委派，但focusIn和focusOut事件是支持.live()方法委派。</p>
<p><small>jQuery1.4版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p105414">
<td>
<pre>1
2
3
4
5
6
7</pre>
</td>
<td id="p1054code14">
<pre>   jQuery('form')
    .focusin(function(){
        jQuery(this).addClass('focused');
    });
    .focusout(function(){
        jQuery(this).removeClass('focused');
    });</pre>
</td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr id="p105415">
<td>
<pre>1
2
3
4
5
6
7</pre>
</td>
<td id="p1054code15">
<pre>   jQuery('input')
    .live('focusin', function(){
        jQuery(this).addClass('focused');
    });
    .live('focusout', function(){
        jQuery(this).removeClass('focused');
    });</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p> </p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a rel="external" href="http://api.jquery.com/focusin" target="_blank">.focusin()</a><a rel="external" href="http://api.jquery.com/focusout" target="_blank">.focusin()</a>方法的资料…</p>
<h2  class="related_post_title">您可能感兴趣的文章</h2><ul class="related_post"><li><a href="http://www.52shidai.com/javascript/jquery/125.html" title="jQuery:1.4新版本中你应该知道的15个新特性(一)">jQuery:1.4新版本中你应该知道的15个新特性(一)</a></li><li><a href="http://www.52shidai.com/javascript/jquery/401.html" title="jQuery1.4下载、性能及新特性详解 ">jQuery1.4下载、性能及新特性详解 </a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.52shidai.com/javascript/jquery/127.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery:1.4新版本中你应该知道的15个新特性(一)</title>
		<link>http://www.52shidai.com/javascript/jquery/125.html</link>
		<comments>http://www.52shidai.com/javascript/jquery/125.html#comments</comments>
		<pubDate>Sun, 21 Feb 2010 03:25:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[新版]]></category>
		<category><![CDATA[特性]]></category>

		<guid isPermaLink="false">http://52shidai.com/?p=125</guid>
		<description><![CDATA[一、给jQuery(…)方法传递新的参数： jQuery()方法是jQuery库的核心方法之一，在1.32版本及早期的版本中，该方法是用来获取节点或者创建DOM对象的，它只支持一个参数。在使用来创建新的DOM对象时，我们若要给该DOM对象添加属性的话，只能通过attr()方法在后面追加，很是不方便，阅读起来也比较累。在jQuery1.4中，给jQuery方法新增了一个对象型的参数，用来创建新的DOM对象设置该DOM对象相应的属性。 jQuery1.32版本中实现代码： 1 2 3 4 5 6 7 8 9 10 11 12 13 jQuery('&#60;a&#62;&#60;/a&#62;').attr({ id: 'foo', href: 'http://google.com', title: 'Become a Googler', rel: 'external' }).text('Go to Google!') .css({ fontWeight: 700, color: 'green' }) .click(function(){ alert('Foo has been clicked!'); }); jQuery1.4版本中实现代码： 1 2 3 4 5 6 7 8 9 10 11 12 [...]]]></description>
			<content:encoded><![CDATA[<h3>一、给jQuery(…)方法传递新的参数：</h3>
<p>jQuery()方法是jQuery库的核心方法之一，在1.32版本及早期的版本中，该方法是用来获取节点或者创建DOM对象的，它只支持一个参数。在使用来创建新的DOM对象时，我们若要给该DOM对象添加属性的话，只能通过attr()方法在后面追加，很是不方便，阅读起来也比较累。在jQuery1.4中，给jQuery方法新增了一个对象型的参数，用来创建新的DOM对象设置该DOM对象相应的属性。</p>
<p><small>jQuery1.32版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p10281">
<td>
<pre>1
2
3
4
5
6
7
8
9
10
11
12
13</pre>
</td>
<td id="p1028code1">
<pre>jQuery('&lt;a&gt;&lt;/a&gt;').attr({
    id: 'foo',
    href: 'http://google.com',
    title: 'Become a Googler',
    rel: 'external'
}).text('Go to Google!')
   .css({
       fontWeight: 700,
       color: 'green'
   })
   .click(function(){
       alert('Foo has been clicked!');
   });</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p><small>jQuery1.4版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p10282">
<td>
<pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14</pre>
</td>
<td id="p1028code2">
<pre>jQuery('&lt;a /&gt;', {
    id: 'foo',
    href: 'http://google.com',
    title: 'Become a Googler',
    rel: 'external',
    text: 'Go to Google!',
    css: {
        fontWeight: 700,
        color: 'green'
    },
    click: function(){
        alert('Foo has been clicked!');
    }
});</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p> </p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a rel="external" href="http://api.jquery.com/jQuery/" target="_blank">jQuery(…)</a>方法的资料…</p>
<h3>二、新增”until”系列方法：</h3>
<p>新增”until”系列方法中有三个方法：”nextUntil”, “prevUntil” 和”parentsUntil”，这些方法是用来获取符合条件内的DOM对象。中文你可以理解为“直到”的意思。</p>
<p><small>若有一段XHtml代码如下：</small></p>
<div>
<table>
<tbody>
<tr id="p10283">
<td>
<pre>1
2
3
4
5
6
7
8</pre>
</td>
<td id="p1028code3">
<pre>&lt;ul&gt;
    &lt;li&gt;Apple&lt;/li&gt;
    &lt;li&gt;Banana&lt;/li&gt;
    &lt;li&gt;Grape&lt;/li&gt;
    &lt;li&gt;Strawberry&lt;/li&gt;
    &lt;li&gt;Pear&lt;/li&gt;
    &lt;li&gt;Peach&lt;/li&gt;
&lt;/ul&gt;</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>现在我想选取从含有apple的li到含有pear的li,则代码实现：</p>
<p><small>jQuery1.32版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p10284">
<td>
<pre>1</pre>
</td>
<td id="p1028code4">
<pre>jQuery('ul li').slice(1, 4);</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p><small>jQuery1.4版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p10285">
<td>
<pre>1</pre>
</td>
<td id="p1028code5">
<pre>jQuery('ul li:contains(Apple)').nextUntil(':contains(Pear)');</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>虽然上面两者的选取效果是一样的，但若现在我在含有apple的li到含有pear的li中间再添加内容的话，1.32版本的代码就需要修改了，而1.4版本的则可继续使用，也就说1.4版本的代码可用性和语义性增强了。</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a rel="external" href="http://api.jquery.com/prevUntil/" target="_blank">prevUntil</a>, <a rel="external" href="http://api.jquery.com/nextUntil/" target="_blank">nextUntil</a>, <a rel="external" href="http://api.jquery.com/parentsUntil/" target="_blank">parentsUntil</a>方法的资料…</p>
<h3>三、给事件对象一次绑定多个事件：</h3>
<p>1.4不再像1.32版本中那样链式地给一个时间对象绑定时间，现在你可以将多个时间归纳后绑定到一个方法中。</p>
<p><small>jQuery1.32版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p10286">
<td>
<pre>1
2
3
4
5
6
7</pre>
</td>
<td id="p1028code6">
<pre>jQuery('#foo).bind('click', function() {
        // do something
}).bind('mouseover', function() {
        // do something
}).bind('mouseout‘， function() {
        // do something
});</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p><small>jQuery1.4版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p10287">
<td>
<pre>1
2
3
4
5
6
7
8
9
10
11</pre>
</td>
<td id="p1028code7">
<pre>jQuery('#foo).bind({
    click: function() {
        // do something
    },
    mouseover: function() {
        // do something
    },
    mouseout: function() {
        // do something
    }
});</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>当然对.one()一次点击事件也是适用的哦！</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a rel="external" href="http://api.jquery.com/bind/" target="_blank">.bind(…)</a>方法的资料…</p>
<h3>四、Per-Property Easing动画效果</h3>
<p>在1.32版本中，我们使用animate()方法给对象添加动画效果时，特效很单一，只能再引入jquery.easing.js插件来丰富动画特效。在<span class='wp_keywordlink_affiliate'><a href="http://www.52shidai.com/tag/%e6%96%b0%e7%89%88" title="查看 新版 中的全部文章" target="_blank">新版</a></span>本1.4中将该插件集成到了jQuery库中，这样在使用过的过程中就更加地方便了。</p>
<p><small>jQuery1.4版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p10288">
<td>
<pre>1
2
3
4</pre>
</td>
<td id="p1028code8">
<pre>jQuery('#foo').animate({
    left: 500,
    top: [500, 'easeOutBounce']
}, 2000);</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>当然也可以给附加的属性参数内添加动画效果，如：</p>
<div>
<table>
<tbody>
<tr id="p10289">
<td>
<pre>1
2
3
4
5
6
7
8
9</pre>
</td>
<td id="p1028code9">
<pre>jQuery('#foo').animate({
    left: 500,
    top: 500
}, {
    duration: 2000,
    specialEasing: {
        top: 'easeOutBounce'
    }
});</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p> </p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a rel="external" href="http://api.jquery.com/animate/#per-property-easing" target="_blank">per-property easing</a>的资料…</p>
<h3>五、新增live事件：</h3>
<p>在1.32版本中，live()方法只对click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, keydown, keypress, keyup这些时间提供了支持，而不支持也比较常用的focus和blur时间。在1.4版本中新增了submit, change, focus, blur四种时间的支持。其中focus对应的是focusin事件，而blur对应了focusout事件。</p>
<p><small>jQuery1.4版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p102810">
<td>
<pre>1
2
3
4
5</pre>
</td>
<td id="p1028code10">
<pre>jQuery('input').live('focusin', function(){
    // do something with this
}).live('focusout', function(){
    // do something with this
});</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p> </p>
<h3>六、控制方法的上下文对象：</h3>
<p>1.4版本在jQuery命名空间下新增了一个名叫”proxy“的方法，该方法有两个参数：一个是作用域，一个是准备执行的处理方法。在Javascript中，this关键字很巧妙地自动执行父亲对象或某个DOM元素对象。当有时候我们希望this指向的不是一个DOM元素对象，而是希望它指向一个之前创建的对象。</p>
<p>举个列子，就很容易明白！比如，现在我们有一个app对象，该对象内部有一个”clickHandler“方法和一个命名为”config“的对象。代码如下：</p>
<div>
<table>
<tbody>
<tr id="p102811">
<td>
<pre>1
2
3
4
5
6
7
8</pre>
</td>
<td id="p1028code11">
<pre>var app = {
    config: {
        clickMessage: 'Hi!'
    },
    clickHandler: function() {
        alert(this.config.clickMessage);
    }
};</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>当我们调用app.clickHandler()方法时，app对象就有了自己的上下文对象：clickHandler方法中的this指向的是app对象。执行后会弹出内容为”Hi!“的提示框。若现在我希望将该app对象下的clickHandler方法绑定在一个超链接上，如下：</p>
<div>
<table>
<tbody>
<tr id="p102812">
<td>
<pre>1</pre>
</td>
<td id="p1028code12">
<pre>jQuery('a').bind('click', app.clickHandler);</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>而此时，当我们点击该超链接时，app对象下的clickHandler方法并不会执行，用Firebug测试则会提示”app.clickHandler is not a function!”。原因在于jQuery（以及绝大部分的事件对象）默认地将事件对象作为了该clickHandler方法的上下文对象，也就是此时this指向了a超链接标签元素。而我们的实际愿望是希望this执行app对象，那么1.4中我们就可以使用新增的proxy()方法来处理这一问题。代码如下：</p>
<div>
<table>
<tbody>
<tr id="p102813">
<td>
<pre>1
2
3
4</pre>
</td>
<td id="p1028code13">
<pre>jQuery('a').bind(
    'click',
    jQuery.proxy(app, 'clickHandler')
);</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>这样执行后提示框就会正常地弹出了。proxy()方法返回的是一个包装后的方法，它将执行你所期望的对象（通过第一个参数传递）。这在其他上下文对象中也很实用，比如给其他方法或插件传递回调函数。</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a rel="external" href="http://api.jquery.com/jQuery.proxy" target="_blank">jQuery.proxy()</a>方法的资料…</p>
<h3>七、延迟动画队列：</h3>
<p>在平时编写代码时，你或许发现有一个动画效果还没完成呢，下面的代码就已经执行完了。而我们希望的是等动画效果执行完成后或执行一段时间后再执行后面的代码。1.4版本中新增了delay()方法来延迟代码的执行。</p>
<p><small>jQuery1.32版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p102814">
<td>
<pre>1
2
3</pre>
</td>
<td id="p1028code14">
<pre>setTimeout(500, function() {
        // do something
});</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p><small>jQuery1.4版本中实现代码：</small></p>
<div>
<table>
<tbody>
<tr id="p102815">
<td>
<pre>1
2
3
4</pre>
</td>
<td id="p1028code15">
<pre>jQuery('#foo')
    .slideDown() // Slide down
    .delay(200) // Do nothing for 200 ms
    .fadeIn(); // Fade in</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>若你希望延迟一个动画队列比默认的“fx”(queue()函数的默认参数)还要慢的话，你只需要将这个queue的变量名当作delay()方法的第二个参数传递即可。</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a rel="external" href="http://api.jquery.com/delay" target="_blank">.delay(…)</a>方法的资料…</p>
<h3>八、判断一个DOM父对象中是否含有某个匹配的子对象：</h3>
<p>1.4中新增了一个过滤型的方法has()来判断某个对象是否在某个标签或集合内出现过。该方法将返回在标签中出现的所有匹配子对象的集合，至少会包含一个子对象。若没有找到匹配子对象，则返回的是一个空的集合。</p>
<div>
<table>
<tbody>
<tr id="p102816">
<td>
<pre>1</pre>
</td>
<td id="p1028code16">
<pre>jQuery('div').has('ul');</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>当然jQuery1.32版本中的.contains()方法其实也可以达到同样的效果，1.4版本又对.contains()进行了完善。在1.4版本中通过给.contains()方法传递两个DOM对象参数，从而判断第二个参数对象是否在第一个参数对象中。代码如下：</p>
<div>
<table>
<tbody>
<tr id="p102817">
<td>
<pre>1
2
3</pre>
</td>
<td id="p1028code17">
<pre>jQuery.contains(document.documentElement, document.body);
// Returns true - &lt;body&gt; is within &lt;html&gt;
&lt;/html&gt;&lt;/body&gt;</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p> </p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a rel="external" href="http://api.jquery.com/has/" target="_blank">.has(…)</a>，<a rel="external" href="http://api.jquery.com/jQuery.contains/" target="_blank">jQuery.contains(…)</a>方法的资料…</p>
<h2  class="related_post_title">您可能感兴趣的文章</h2><ul class="related_post"><li><a href="http://www.52shidai.com/javascript/jquery/127.html" title="jQuery:1.4新版本中你应该知道的15个新特性(二)">jQuery:1.4新版本中你应该知道的15个新特性(二)</a></li><li><a href="http://www.52shidai.com/javascript/jquery/401.html" title="jQuery1.4下载、性能及新特性详解 ">jQuery1.4下载、性能及新特性详解 </a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.52shidai.com/javascript/jquery/125.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

