<?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>前端思考：专注前端开发，关注用户体验 &#187; jQuery</title>
	<atom:link href="http://www.artcss.com/archives/tag/jquery/feed" rel="self" type="application/rss+xml" />
	<link>http://www.artcss.com</link>
	<description>一个像素的距离...</description>
	<lastBuildDate>Sat, 12 Feb 2011 03:34:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>jQuery1.4官方文档中文版[转]</title>
		<link>http://www.artcss.com/archives/677.html</link>
		<comments>http://www.artcss.com/archives/677.html#comments</comments>
		<pubDate>Mon, 22 Feb 2010 02:47:59 +0000</pubDate>
		<dc:creator>Artcss</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[chm]]></category>
		<category><![CDATA[中文文档]]></category>

		<guid isPermaLink="false">http://blog.artskin.cn/?p=677</guid>
		<description><![CDATA[2010年1月14号, 恰逢jQuery四周年纪念日, jQuery的团队早早便开始了1.4版发布的准备工作, 并以每天一则公告的方式进行庆祝, 活动将持续14天。发布的首日, jQuery的团队首先列出了1.4版中的重大改进。我个人认为这篇文档是这几天以来内容比较充实的一篇文档。所以翻译过来, 以便同僚日后可以参考。时间仓促, 可能有几处不太明确的地方, 或是原文就草草带过, 可能会不大通畅。欢迎讨论或提出意见，以便共同进步。 原译者:coolnalu 原文地址: http://jquery14.com/day-01 .wp_syntax { color: #100; background-color: #f9f9f9; border: 1px solid silver; margin: 0 0 1.5em 0; overflow: auto; } .wp_syntax div{ vertical-align: top; padding: 2px 4px; } .entry h2{ background: #eeeeee; padding: 5px; } jQuery 1.4 发布啦 为了庆祝jQuery的四周岁生日, jQuery的团队荣幸的发布了jQuery Javascript库的最新主要版本! 这个版本包含了大量的编程，测试，和记录文档的工作，我们为此感到很骄傲。 我要以个人的名义感谢 Brandon [...]]]></description>
			<content:encoded><![CDATA[<p>2010年1月14号, 恰逢jQuery四周年纪念日, jQuery的团队早早便开始了1.4版发布的准备工作, 并以每天一则公告的方式进行庆祝, 活动将持续14天。发布的首日, jQuery的团队首先列出了1.4版中的重大改进。我个人认为这篇文档是这几天以来内容比较充实的一篇文档。所以翻译过来, 以便同僚日后可以参考。时间仓促, 可能有几处不太明确的地方, 或是原文就草草带过, 可能会不大通畅。欢迎讨论或提出意见，以便共同进步。<br />
<strong>原译者:coolnalu</strong></p>
<p><span id="more-69"></span><br />
<a href="http://jquery14.com/day-01">原文地址: http://jquery14.com/day-01</a></p>
<style>
.wp_syntax {
  color: #100;
  background-color: #f9f9f9;
  border: 1px solid silver;
  margin: 0 0 1.5em 0;
  overflow: auto;
}
.wp_syntax div{
  vertical-align: top;
  padding: 2px 4px;
}
.entry h2{
  background: #eeeeee;
  padding: 5px;
}
</style>
<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>下载(Downloading)</h4>
<p>按照惯例，我们提供了两份jQuery的拷贝，一份是最小化的(我们现在采用<a href="http://code.google.com/closure/compiler/">Google Closure</a>作为默认的压缩工具了)，一份是未压缩的(供纠错或阅读)。</p>
<ul>
<li><a href="http://code.jquery.com/jquery-1.4.min.js">jQuery压缩</a> (23kb <a href="http://www.julienlecomte.net/blog/2007/08/13/">Gzipped</a>)</li>
<li><a href="http://code.jquery.com/jquery-1.4.js">jQuery常规</a> (234kb)</li>
<li><a href="http://blog.artskin.cn/?page_id=486">jQuery1.4API中文文档手册chm</a> (154kb)</li>
</ul>
<p>另外，Google也在他们的服务器上<a href="http://code.google.com/apis/ajaxlibs/documentation/index.html">放置了一份jQuery的拷贝</a>。这份拷贝会自动的最小化然后压缩 &ndash; 并且放在Google最快的缓存服务器上。</p>
<ul>
<li><a href="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js">http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js</a></li>
</ul>
<p>你可以在你的站点上直接引用上面的URL，这样就可以享受迅速加载jQuery的性能优势了。</p>
<p>就jQuery1.4来说，我们努力的减少大规模升级中的麻烦 &ndash; 通过保持所有public函数的签名。即使如此，还请通读<a href="#backwards">可能会造成问题的变更列表</a>，这样能够了解哪些变更可能会给你的应用造成问题。</p>
<h3>(功能) Features</h3>
<p>下面的内容概括了jQuery1.4里加入的变更和功能。另外所有的变更都已经在<a href="http://api.jquery.com/category/version/1.4/">jQuery 1.4 的文档</a>里记录了。</p>
<h4>热门方法经过了性能上的大”检修”</h4>
<p>不少比较热门的和常用的jQuery方法在1.4里被重写了。(译注:重写了方法的内部，外部调用没有大幅度改变) 我们分析源码的时候发现我们能够获得大幅的性能提升，通过把jQuery和自己比较: 查看内部函数被调用了多少次，然后努力<a href="http://ejohn.org/blog/function-call-profiling/">降低源码的复杂度</a>(译注:计算机算法中的Complexity)</p>
<p><a rel="lightbox[69]" href="http://www.uxd2.com/wp-content/uploads/2010/01/01-funccall.jpg"><img width="500" height="375" alt="常用jQuery方法调用频率" src="http://www.uxd2.com/wp-content/uploads/2010/01/01-funccall.jpg" title="常用jQuery方法调用频率" class="alignnone size-full wp-image-74"></a><br />
<small><a href="http://www.flickr.com/photos/jeresig/4271691293/" title="# of Function Calls for Popular jQuery Methods by John Resig, on Flickr">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">.attr()</a></code>传递一个函数，然后这个函数的结果会被用来赋给相应的HTML属性(attribute)上。这个功能现在被移植到所有的设置函数了: <code><a href="http://api.jquery.com/css">.css()</a></code>, <code><a href="http://api.jquery.com/attr">.attr()</a></code>, <code><a href="http://api.jquery.com/val">.val()</a></code>, <code><a href="http://api.jquery.com/html">.html()</a></code>, <code><a href="http://api.jquery.com/text">.text()</a></code>, <code><a href="http://api.jquery.com/append">.append()</a></code>, <code><a href="http://api.jquery.com/prepend">.prepend()</a></code>,  <code><a href="http://api.jquery.com/before">.before()</a></code>, <code><a href="http://api.jquery.com/after">.after()</a></code>, <code><a href="http://api.jquery.com/replaceWith">.replaceWith()</a></code>, <code><a href="http://api.jquery.com/wrap">.wrap()</a></code>, <code><a href="http://api.jquery.com/wrapInner">.wrapInner()</a></code>, <code><a href="http://api.jquery.com/offset">.offset()</a></code>, <code><a href="http://api.jquery.com/addClass">.addClass()</a></code>, <code><a href="http://api.jquery.com/removeClass">.removeClass()</a></code>, 以及 <code><a href="http://api.jquery.com/toggleClass">.toggleClass()</a></code>.</p>
<p>另外, 对于下面几个方法，当前的值会被作为第2个变量传递给这个函数。<code><a href="http://api.jquery.com/css">.css()</a></code>, <code><a href="http://api.jquery.com/attr">.attr()</a></code>, <code><a href="http://api.jquery.com/val">.val()</a></code>, <code><a href="http://api.jquery.com/html">.html()</a></code>, <code><a href="http://api.jquery.com/text">.text()</a></code>, <code><a href="http://api.jquery.com/append">.append()</a></code>, <code><a href="http://api.jquery.com/prepend">.prepend()</a></code>, <code><a href="http://api.jquery.com/offset">.offset()</a></code>, <code><a href="http://api.jquery.com/addClass">.addClass()</a></code>, <code><a href="http://api.jquery.com/removeClass">.removeClass()</a></code>, 以及 <code><a href="http://api.jquery.com/toggleClass">.toggleClass()</a></code>.</p>
<p>这样代码就可以这样写:</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript"><span style="color: rgb(0, 102, 0); font-style: italic;">// 找出所有A标签里的'&amp;'字符，然后用一个span标签包围</span>
$<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">'a'</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">html</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span>i<span style="color: rgb(51, 153, 51);">,</span>html<span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(0, 153, 0);">{</span>
  <span style="color: rgb(0, 0, 102); font-weight: bold;">return</span> html.<span style="color: rgb(102, 0, 102);">replace</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 102); font-style: italic;">/&amp;/gi</span><span style="color: rgb(51, 153, 51);">,</span><span style="color: rgb(51, 102, 204);">'<span class="amp">&amp;</span>'</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
<span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>

<span style="color: rgb(0, 102, 0); font-style: italic;">// 给一些链接的title属性加些信息</span>
$<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">'a[target]'</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">attr</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"title"</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span>i<span style="color: rgb(51, 153, 51);">,</span>title<span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(0, 153, 0);">{</span>
  <span style="color: rgb(0, 0, 102); font-weight: bold;">return</span> title <span style="color: rgb(51, 153, 51);">+</span> <span style="color: rgb(51, 102, 204);">" (新窗口打开)"</span><span style="color: rgb(51, 153, 51);">;</span>
<span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<h4>Ajax</h4>
<p><strong>嵌套参数的序列化</strong> (<a href="http://api.jquery.com/jQuery.param/">jQuery.param() 文档</a>, <a href="http://github.com/jquery/jquery/commit/50d78e7658382d2a2f5149cae7a6572f78ce403f">Commit 1</a>, <a href="http://github.com/jquery/jquery/commit/67089eedf6f84acd9c16ea2a6dadadf7b13a7c84">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 class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript"><span style="color: rgb(0, 102, 0); font-style: italic;">// 全局改变序列化方式 (使用旧的)</span>
jQuery.<span style="color: rgb(102, 0, 102);">ajaxSettings</span>.<span style="color: rgb(102, 0, 102);">traditional</span> <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">true</span><span style="color: rgb(51, 153, 51);">;</span>

<span style="color: rgb(0, 102, 0); font-style: italic;">// 指定情况使用旧的序列化方式</span>
jQuery.<span style="color: rgb(102, 0, 102);">param</span><span style="color: rgb(0, 153, 0);">(</span> stuff<span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">true</span> <span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>

<span style="color: rgb(0, 102, 0); font-style: italic;">// 针对一个单独的Ajax请求使用旧的序列化方式</span>
$.<span style="color: rgb(102, 0, 102);">ajax</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">{</span> data<span style="color: rgb(51, 153, 51);">:</span> stuff<span style="color: rgb(51, 153, 51);">,</span> traditional<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">true</span> <span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<p>更多信息参见: <a href="http://api.jquery.com/jQuery.param/">jQuery.param() 文档</a>, <a href="http://api.jquery.com/jQuery.ajax/">jQuery.ajax() 文档</a>, <a href="http://github.com/jquery/jquery/commit/39518945047413f1185682078043e70e0c5c9091">Commit</a>, <a href="http://github.com/jquery/jquery/blob/master/src/ajax.js#L175">Code</a></p>
<p><strong>JSON和脚本类型通过”content-type”自动识别。</strong> (<a href="http://api.jquery.com/jQuery.ajax/">jQuery.ajax 文档</a>, <a href="http://github.com/jquery/jquery/commit/787f271052220c20787104f0eba6441aedac22ff">Commit 1</a>, <a href="http://github.com/jquery/jquery/commit/6861b5d4eb16222ed5ea623af6ce75362b55d1d4">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/">jQuery.ajax() 文档</a>, <a href="http://github.com/jquery/jquery/commit/28ab4d32247943e1ae3409b23fe69303df0bc9eb">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/">jQuery.ajax() 文档</a>, <a href="http://github.com/jquery/jquery/commit/90a87c03b4943d75c24bc5e6246630231d12d933">Commit 1</a>, <a href="http://github.com/jquery/jquery/commit/308d6cdad023da190ace2a698ee4815ed8dad9c5">Commit 2</a>, <a href="http://github.com/jquery/jquery/commit/44e6beb10304789044de2c5a58f5bb82e8321636">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">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/">jQuery.param() 文档</a>, <a href="http://github.com/jquery/jquery/commit/b31b9bd756a1489c3b1b856ed8b624c55da9e02f">Commit</a>)</p>
<p>新的<a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#attr-input-type-keywords">HTML5输入方法</a> (比如’datetime’和’range’)在序列化<code><a href="http://api.jquery.com/serialize">.serialize()</a></code>一个表单的时候会被包括在内。</p>
<p><strong>Ajax请求的环境</strong> (<a href="http://api.jquery.com/jQuery.ajax/">jQuery.ajax() 文档</a>, <a href="http://github.com/jquery/jquery/commit/183f37e4b4128af7ba096ac40046768b84b6d66e">Commit</a>)</p>
<p>你可以附加一个”环境”到Ajax请求上，所有的回调函数里都会拥有同样的”环境”设置(这样可以简化你的代码，尽可能避免使用闭合,或是其他对象)。</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript">jQuery.<span style="color: rgb(102, 0, 102);">ajax</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">{</span>
    url<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">"test.html"</span><span style="color: rgb(51, 153, 51);">,</span>
    context<span style="color: rgb(51, 153, 51);">:</span> document.<span style="color: rgb(102, 0, 102);">body</span><span style="color: rgb(51, 153, 51);">,</span>
    success<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(0, 153, 0);">{</span>
        jQuery<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 102); font-weight: bold;">this</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">addClass</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"done"</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
    <span style="color: rgb(0, 153, 0);">}</span>
<span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<p><strong>请求成功回调函数的第三个参数会被设为原始的XHR对象</strong> (<a href="http://api.jquery.com/jQuery.ajax/">jQuery.ajax() 文档</a>, <a href="http://github.com/jquery/jquery/commit/c2101245c07afdb831b0c79869c7263420407b67">Commit</a>)</p>
<p>所有的Ajax请求的成功回调函数现在都会收到原始的XMLHttpRequest对象，作为第三个参数。之前这个XHR对象只能通过<code>$.ajax</code>一类方法的返回值来获取。</p>
<p><strong>明确设置”Content-Type”</strong> (<a href="http://api.jquery.com/jQuery.ajax/">jQuery.ajax() 文档</a>, <a href="http://github.com/jquery/jquery/commit/25b0ba9f9612583033b902a0e40345463a3a71d0">Commit</a>)</p>
<p>在1.3版，如果没有实际数据发送，<a href="http://api.jquery.com/jQuery.ajax/">jQuery.ajax</a>的contentType会被忽略。1.4版里，contentType将总是和请求一同发送。这修复了某些后台凭靠”Content-Type”页头判断回复类别所造成的问题。</p>
<p><strong>明确设置JSONP回调函数的名字</strong> (<a href="http://api.jquery.com/jQuery.ajax/">jQuery.ajax 文档</a>,  <a href="http://github.com/jquery/jquery/commit/fbc73d45b487dd863886c7fd3f0af1fd4dec261b">Commit</a>)</p>
<p>你可以使用<a href="http://api.jquery.com/jQuery.ajax/">jQuery.ajax()</a>方法的jsonpCallback选项，通过名字来指定JSONP的回调函数。</p>
<p><strong>防止启动前跨域XHR</strong> (<a href="http://github.com/jquery/jquery/commit/a7678267d848fcef8775c8b9f4fa3e507b8cc5f4">Commit</a>)</p>
<p>跨域Ajax(针对提供支持的浏览器)将更易用，因为默认设置下，启动前XHR被阻止了。(TODO)</p>
<p><strong>jQuery.ajax()现在使用”onreadystatechange”事件替换了计时器</strong> (<a href="http://github.com/jquery/jquery/commit/fe6c86d53046b0f4d648f61c0b8e75387af65152">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"><img width="500" height="375" alt=".css().attr()的性能提高" src="http://www.uxd2.com/wp-content/uploads/2010/01/02-perform-cssatrr.jpg" title=".css().attr()的性能提高" class="alignnone size-full wp-image-75"></a></p>
<p><strong><code>.attr()</code>方法多了一个设置函数作为参数</strong> (<a href="http://api.jquery.com/attr/">.attr() 文档</a>)</p>
<p>你不但可以将一个函数用在<code>.attr()</code>里，还可以在这个函数里使用属性的当前值。</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript">jQuery<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">'&lt;img src="enter.png" alt="enter your name" /&gt;'</span><span style="color: rgb(0, 153, 0);">)</span>
.<span style="color: rgb(102, 0, 102);">attr</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"alt"</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span>index<span style="color: rgb(51, 153, 51);">,</span> value<span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span>
    <span style="color: rgb(0, 0, 102); font-weight: bold;">return</span> <span style="color: rgb(51, 102, 204);">"Please, "</span> <span style="color: rgb(51, 153, 51);">+</span> value<span style="color: rgb(51, 153, 51);">;</span>
<span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<p><strong>.val( Function )</strong> (<a href="http://api.jquery.com/val/">.val() 文档</a>)</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="html4strict"><span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(0, 0, 0); font-weight: bold;">input</span> <span style="color: rgb(0, 0, 102);">class</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"food"</span> <span style="color: rgb(0, 0, 102);">type</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">'text'</span> data-index<span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"0"</span> <span style="color: rgb(102, 204, 102);">/</span>&gt;</span>
<span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(0, 0, 0); font-weight: bold;">input</span> <span style="color: rgb(0, 0, 102);">class</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"food"</span> <span style="color: rgb(0, 0, 102);">type</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">'text'</span> data-index<span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"1"</span> <span style="color: rgb(102, 204, 102);">/</span>&gt;</span></pre>
</div>
</div>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript">jQuery<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"input:text.food"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">hide</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>

jQuery<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"&lt;ul class='sortable'&gt;&lt;li&gt;Peanut Butter&lt;/li&gt;&lt;li&gt;Jelly&lt;/li&gt;&lt;/ul&gt;"

</span><span style="color: rgb(0, 153, 0);">)</span>
  .<span style="color: rgb(102, 0, 102);">sortable</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span>
  .<span style="color: rgb(102, 0, 102);">bind</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"endsort"</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span>
    $<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">":text.food"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">val</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span>
      <span style="color: rgb(0, 0, 102); font-weight: bold;">return</span> $<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"ul.sortable li:eq("</span> <span style="color: rgb(51, 153, 51);">+</span> $<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 102); font-weight: bold;">this</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">attr</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"data-index"</span><span style="color: rgb(0, 153, 0);">)</span>  <span style="color: rgb(51, 153, 51);">+</span> <span style="color: rgb(51, 102, 204);">")"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">text</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
    <span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
  <span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<p><strong>text和CDATAHTML元素也支持.text()方法了</strong> (<a href="http://api.jquery.com/text/">.text() 文档</a>, <a href="http://github.com/jquery/jquery/commit/b30af34f28074b491929445f5aad3d62c63e772f">Commit</a>)</p>
<h4>核心 (Core)</h4>
<p><strong>快捷元素创建</strong> (<a href="http://api.jquery.com/jQuery/#jQuery2">jQuery() 文档</a>, <a href="http://github.com/jquery/jquery/commit/d40083c866738727aa7ffd7f13d2955bc9575d5e">Commit</a>)</p>
<p>现在当你需要使用jQuery函数创建一个元素的时候，你可以同时附递一个对象来指定属性值和事件:</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript">jQuery<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"
<div>"<span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 153, 0);">{</span>
    id<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">"foo"</span><span style="color: rgb(51, 153, 51);">,</span>
    css<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(0, 153, 0);">{</span>
        height<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">"50px"</span><span style="color: rgb(51, 153, 51);">,</span>
        width<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">"50px"</span><span style="color: rgb(51, 153, 51);">,</span>
        color<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">"blue"</span><span style="color: rgb(51, 153, 51);">,</span>
        backgroundColor<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">"#ccc"</span>
    <span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(51, 153, 51);">,</span>
    click<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span>
       $<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 102); font-weight: bold;">this</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">css</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"backgroundColor"</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(51, 102, 204);">"red"</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
    <span style="color: rgb(0, 153, 0);">}</span>
<span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">appendTo</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"body"</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></div>

</span></pre>
</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/">.eq() 文档</a>, <a href="http://api.jquery.com/get/">.get() 文档</a>, <a href="http://github.com/jquery/jquery/commit/e532dfe5228217f55a33122a4438fd70522dbb4b">Commit</a>)</p>
<p>你现在可以在<code>.get()</code>和<code>.eq()</code>方法里使用负数。譬如，你要选择倒数第2个div元素，或者是倒数第2个DOM对象:</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript">$<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"div"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">eq</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 153, 51);">-</span><span style="color: rgb(204, 0, 0);">2</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
$<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"div"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">get</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 153, 51);">-</span><span style="color: rgb(204, 0, 0);">2</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<p><strong>新的.first()和.last()方法</strong> (<a href="http://api.jquery.com/first/">.first() 文档</a>, <a href="http://api.jquery.com/last/">.last() 文档</a>, <a href="http://github.com/jquery/jquery/commit/9de120e6d7cfffa3d990a6ccf23db3cd74e2bdc0">Commit</a>)</p>
<p>方便起见, 新增的<code>.first()</code>和<code>.last()</code>方法等同于<a href="http://api.jquery.com/eq/">.eq(0)</a>和<a href="http://api.jquery.com/eq/">.eq(-1)</a>.</p>
<p><strong>新的.toArray()方法</strong> (<a href="http://api.jquery.com/toArray/">.toArray() 文档</a>, <a href="http://github.com/jquery/jquery/commit/e124fec5e9cfee77cb23b27c0d43dc2631c83aab">Commit</a>)</p>
<p><a href="http://api.jquery.com/get">.get()</a>方法自始就是从jQuery集合里返回一个阵列。为了能够更明确, 你可以用<a href="http://api.jquery.com/toArray/">.toArray()</a>来达到一样的效果。(译注:这里应该是为了以后的版本留出空间，譬如以后可能会加入.toList()方法，到时候就会易于区分。) 不过，和<code>.get()</code>不一样的是，<code>.toArray()</code>不接受参数。</p>
<p><strong>jQuery()返回一个空集</strong> (<a href="http://api.jquery.com/jQuery/">jQuery() 文档</a>, <a href="http://github.com/jquery/jquery/commit/04524287d3e0112deae570ff9247c734833431bb">Commit</a>)</p>
<p>在jQuery 1.3中,<a href="http://api.jquery.com/jQuery/">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/">Element Selector 文档</a>, <a href="http://github.com/jquery/jquery/commit/4ea4fad0902839c06c281b5de7b0aca29922b63d">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">jQuery() 文档</a>, <a href="http://github.com/jquery/jquery/commit/c4c820efff4fa7bcce0d5bf0a448625278ea6379">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"><img width="500" height="375" alt=".css()的性能提高 " src="http://www.uxd2.com/wp-content/uploads/2010/01/03-perform-css.jpg" title=".css()的性能提高 " class="alignnone size-full wp-image-76"></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"><img width="500" height="375" alt="addClass, removeClass, 和 hasClass的性能提高" src="http://www.uxd2.com/wp-content/uploads/2010/01/04-perform-addClass.jpg" title="addClass, removeClass, 和 hasClass的性能提高" class="alignnone size-full wp-image-77"></a></p>
<p><strong>.toggleClass()可以切换多个css类了</strong> (<a href="http://api.jquery.com/toggleClass/">.toggleClass() 文档</a>, <a href="http://github.com/jquery/jquery/commit/5e6e53835e552920db4f88ac0c9eca71aaacbef0">Commit</a>)</p>
<p>你可以通过<a href="http://api.jquery.com/toggleClass/">.toggleClass()</a>调用多个css类的名字来切换他们。</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript">$<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"div"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">toggleClass</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"current active"</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<h4>数据</h4>
<p><strong>.data()返回对象, .data(Object)设置对象</strong> (<a href="http://api.jquery.com/data/">.data() 文档</a>, <a href="http://github.com/jquery/jquery/commit/d36d224cc52e70d837306d33a03f517ef72abc60">Commit 1</a>, <a href="http://github.com/jquery/jquery/commit/f6a0bf6816f4e2e67382b1b13fdd3ff2ea4b22f8">Commit 2</a>)</p>
<p>有时候你可能需要在一个元素上附加一个复杂的对象。一个常见的例子是你需要从一个元素身上复制所有的数据到令一个元素上。在jQuery 1.4里, 不使用任何参数调用<a href="http://api.jquery.com/data/">.data()</a>时，.data会返回一个复杂对象。(译注: 包含所有键-值对的对象。) 调用<a href="http://api.jquery.com/data/">.data(Object)</a> 则会设置这个对象。注意这个对象还包括了元素上绑定的事件，所以用的时候要小心。</p>
<p><strong>除非需要, 不然不会创建数据缓存。</strong> (<a href="http://github.com/jquery/jquery/commit/c4f144eeffd94c745839b0ced2de9c62cfa9f075">Commit 1</a>, <a href="http://github.com/jquery/jquery/commit/97e134fe80a734b97170bf43c9459511f4e165c7">Commit 2</a>, <a href="http://github.com/jquery/jquery/commit/67d445a703491c90a7d3c46be34bcdceb4d1c896">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">Per-property Easing 文档</a>, <a href="http://github.com/jquery/jquery/commit/93fdbeb963a9c350f807818c7cc99982942a92f3">Commit</a>)</p>
<p>除了能够给一个动态效果指定缓进出函数外，你现在可以指定每个属性的缓进出函数了。James Padolsey的<a href="http://james.padolsey.com/javascript/easing-in-jquery-1-4a2/">blog上</a>有更进一步的信息和演示。</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript">$<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"#clickme"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">click</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span>
  $<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"div"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">animate</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">{</span>
    width<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(51, 102, 204);">"+=200px"</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(51, 102, 204);">"swing"</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(51, 153, 51);">,</span>
    height<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(51, 102, 204);">"+=50px"</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(51, 102, 204);">"linear"</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(51, 153, 51);">,</span>
  <span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(204, 0, 0);">2000</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span>
      $<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 102); font-weight: bold;">this</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">after</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"&lt;div&gt;Animation complete.&lt;/div&gt;"</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
  <span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
<span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<h4>事件 (Events)</h4>
<p><strong>新方法: jQuery.proxy()</strong> (<a href="http://api.jquery.com/jQuery.proxy/">jQuery.proxy() Documenation</a>, <a href="http://github.com/jquery/jquery/commit/66975de2d249643779e2b3daad0457f7f5f92508">Commit 1</a>, <a href="http://github.com/jquery/jquery/commit/1d2b1a57dae0b73b3d99197f73f4edb623b5574a">Commit 2</a>)</p>
<p>如果你需要保证一个函数内的”this”恒定地保持某个值, 你可以用<code>jQuery.proxy</code>获得一个相同作用域的函数。</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript"><span style="color: rgb(0, 51, 102); font-weight: bold;">var</span> obj <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(0, 153, 0);">{</span>
  <span style="color: rgb(0, 0, 102);">name</span><span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">"John"</span><span style="color: rgb(51, 153, 51);">,</span>
  test<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span>
    <span style="color: rgb(0, 0, 102);">alert</span><span style="color: rgb(0, 153, 0);">(</span> <span style="color: rgb(0, 0, 102); font-weight: bold;">this</span>.<span style="color: rgb(0, 0, 102);">name</span> <span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
    $<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"#test"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">unbind</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"click"</span><span style="color: rgb(51, 153, 51);">,</span> obj.<span style="color: rgb(102, 0, 102);">test</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
  <span style="color: rgb(0, 153, 0);">}</span>
<span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(51, 153, 51);">;</span>

$<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"#test"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">click</span><span style="color: rgb(0, 153, 0);">(</span> jQuery.<span style="color: rgb(102, 0, 102);">proxy</span><span style="color: rgb(0, 153, 0);">(</span> obj<span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(51, 102, 204);">"test"</span> <span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<p><strong>多个事件绑定</strong> (<a href="http://api.jquery.com/bind">.bind() 文档</a>)</p>
<p>你可以通过递入一个对象来一次性绑定元素的多个事件。</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript">$<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"div.test"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">bind</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">{</span>
  click<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(0, 153, 0);">{</span>
    $<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 102); font-weight: bold;">this</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">addClass</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"active"</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
  <span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(51, 153, 51);">,</span>
  mouseenter<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(0, 153, 0);">{</span>
    $<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 102); font-weight: bold;">this</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">addClass</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"inside"</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
  <span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(51, 153, 51);">,</span>
  mouseleave<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(0, 153, 0);">{</span>
    $<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 102); font-weight: bold;">this</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">removeClass</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"inside"</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
  <span style="color: rgb(0, 153, 0);">}</span>
<span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<p><strong>‘change’和’submit’事件规范化</strong> (<a href="http://api.jquery.com/change">Change 文档</a>, <a href="http://api.jquery.com/submit">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/">.focusin() 文档</a>, <a href="http://api.jquery.com/focusout/">.focusout() 文档</a>, <a href="http://github.com/jquery/jquery/commit/03481a52c72e417b01cfeb499f26738cf5ed5839">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">DOM事件规范</a>决定不使其向父元素传递事件。</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript">$<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"form"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">focusout</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span>event<span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span>
    <span style="color: rgb(0, 51, 102); font-weight: bold;">var</span> tgt <span style="color: rgb(51, 153, 51);">=</span> event.<span style="color: rgb(102, 0, 102);">target</span><span style="color: rgb(51, 153, 51);">;</span>
    <span style="color: rgb(0, 0, 102); font-weight: bold;">if</span> <span style="color: rgb(0, 153, 0);">(</span>tgt.<span style="color: rgb(102, 0, 102);">nodeName</span> <span style="color: rgb(51, 153, 51);">==</span> <span style="color: rgb(51, 102, 204);">"INPUT"</span> <span style="color: rgb(51, 153, 51);">&amp;&amp;</span> <span style="color: rgb(51, 153, 51);">!</span>tgt.<span style="color: rgb(102, 0, 102);">value</span><span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span>
        $<span style="color: rgb(0, 153, 0);">(</span>tgt<span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">after</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"<span>nothing here</span>"</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
    <span style="color: rgb(0, 153, 0);">}</span>
<span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<p><strong>所有的事件都可以成为即时事件</strong> (<a href="http://api.jquery.com/live">.live() 文档</a>)</p>
<p>除了<a href="http://api.jquery.com/ready">ready</a>, <a href="http://api.jquery.com/focus">focus</a> (用focusin), 和 <a href="http://api.jquery.com/blur">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">Commit</a>)</p>
<p><strong>live/die也支持环境变量了</strong> (<a href="http://github.com/jquery/jquery/commit/30e760b63fd6d82f30833cd2864f245dd9594cd9">Commit</a>)</p>
<p>现在可以在绑定事件的时候给选择符指定一个环境。如果环境被指定了, 只有属于这个环境下的元素才会被绑定事件。在创建即时事件的时候, 元素本身不需要已经被定义, 但是环境必须被创建。</p>
<p><strong>确定ready事件至少含有<code>body</code>元素</strong> (<a href="http://github.com/jquery/jquery/commit/262fcf7b7b919da1564509f621cf7480a5d5572b">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">Commit</a>)</p>
<h4>DOM操作 (Manipulation)</h4>
<p>在jQuery 1.4里一系列的DOM操作方法的性能都有巨大的提升。</p>
<p><strong><a href="http://api.jquery.com/append">.append()</a>, <a href="http://api.jquery.com/prepend">.prepend()</a>, <a href="http://api.jquery.com/before">.before()</a>, and <a href="http://api.jquery.com/after">.after()</a>的性能提高了。</strong></p>
<p><a rel="lightbox[69]" href="http://www.uxd2.com/wp-content/uploads/2010/01/05-perform-dom.jpg"><img width="500" height="375" alt="DOM嵌入的性能提高" src="http://www.uxd2.com/wp-content/uploads/2010/01/05-perform-dom.jpg" title="DOM嵌入的性能提高" class="alignnone size-full wp-image-78"></a></p>
<p><strong><a href="http://api.jquery.com/html">.html()</a>的性能提高到以前的3倍。</strong></p>
<p><a rel="lightbox[69]" href="http://www.uxd2.com/wp-content/uploads/2010/01/06-perform-html.jpg"><img width="500" height="375" alt=".html()的性能提高" src="http://www.uxd2.com/wp-content/uploads/2010/01/06-perform-html.jpg" title=".html()的性能提高" class="alignnone size-full wp-image-79"></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"><img width="500" height="375" alt=".remove() 和 .empty()的性能提高" src="http://www.uxd2.com/wp-content/uploads/2010/01/07-perform-remove.jpg" title=".remove() 和 .empty()的性能提高" class="alignnone size-full wp-image-80"></a></p>
<p><strong>新方法: .detach()</strong> (<a href="http://api.jquery.com/detach/">.detach() 文档</a>, <a href="http://github.com/jquery/jquery/commit/7a67f8897d3c2ed97254f0fdb969be14e77962d1">Commit</a>)</p>
<p><code>detach()</code>将一个元素从DOM里移除, 但是并不卸载关联的事件处理函数。这个方法可用于暂时性的将一个元素移除，执行相关操作，然后返回。</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript"><span style="color: rgb(0, 51, 102); font-weight: bold;">var</span> foo <span style="color: rgb(51, 153, 51);">=</span> $<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"#foo"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">click</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span>
    <span style="color: rgb(0, 102, 0); font-style: italic;">// 相关操作</span>
<span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
foo.<span style="color: rgb(102, 0, 102);">detach</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
<span style="color: rgb(0, 102, 0); font-style: italic;">// foo保留了相关处理函数</span>
foo.<span style="color: rgb(102, 0, 102);">appendTo</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"body"</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<p><strong>新的unwrap()方法</strong> (<a href="http://api.jquery.com/unwrap/">documentation</a>, <a href="http://github.com/jquery/jquery/commit/69e6e53555f21f07b534f1169298f7b33011bb4b">commit</a>)</p>
<p><code>unwrap()</code>方法拿到一个已知的父元素的子元素，然后将父元素用子元素替换。(译注: 将子元素从”包裹”里拿出来, 因名unwrap)。如此这般:</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="html4strict"><span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(0, 0, 0); font-weight: bold;">body</span>&gt;</span>
    <span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(0, 0, 0); font-weight: bold;">div</span>&gt;</span>
        <span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(0, 0, 0); font-weight: bold;">p</span>&gt;</span>annie<span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(102, 204, 102);">/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">p</span>&gt;</span> <span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(0, 0, 0); font-weight: bold;">p</span>&gt;</span>davey<span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(102, 204, 102);">/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">p</span>&gt;</span> <span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(0, 0, 0); font-weight: bold;">p</span>&gt;</span>stevie<span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(102, 204, 102);">/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">p</span>&gt;</span>
    <span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(102, 204, 102);">/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">div</span>&gt;</span>
<span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(102, 204, 102);">/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">body</span>&gt;</span></pre>
</div>
</div>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript">$<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">'div'</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">unwrap</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="html4strict"><span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(0, 0, 0); font-weight: bold;">body</span>&gt;</span>
   <span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(0, 0, 0); font-weight: bold;">p</span>&gt;</span>annie<span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(102, 204, 102);">/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">p</span>&gt;</span> <span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(0, 0, 0); font-weight: bold;">p</span>&gt;</span>davey<span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(102, 204, 102);">/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">p</span>&gt;</span> <span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(0, 0, 0); font-weight: bold;">p</span>&gt;</span>stevie<span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(102, 204, 102);">/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">p</span>&gt;</span>
<span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(102, 204, 102);">/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">body</span>&gt;</span></pre>
</div>
</div>
<p><strong>domManip方法里的缓存</strong> (<a href="http://github.com/jquery/jquery/commit/8db967e9d52407c8e76d81b9d472800667f6fa29">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">commit</a>)</p>
<p>现在你可以对还没有放置到DOM Tree上的节点进行<code>before</code>, <code>after</code>, 和<code>replaceWith</code>的操作了。意味着你可以先对节点进行复杂的操作, 待完成后再放到合适的DOM位置上。这样也能尽量避免操作过程中造成重新排版。</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript">jQuery<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"&lt;div&gt;"<span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">before</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"&lt;p&gt;Hello&lt;/p&gt;"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">appendTo</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"body"</span><span style="color: rgb(0, 153, 0);">)</span></span></pre>
</div>
</div>
<p><strong><code>.clone(true)</code> 也会复制关联数据</strong> (<a href="http://api.jquery.com/clone/">clone 文档</a>, <a href="http://github.com/jquery/jquery/commit/4b70f006f579fba24a882d80ca67f1971dbb4922">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/">.offset() 文档</a>, <a href="http://github.com/jquery/jquery/commit/daffb954e397bd5d9f8e9aaedab6c0baa9609e1e">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/">.delay() 文档</a>, <a href="http://github.com/jquery/jquery/commit/bbd933cbfe6d31a749cb336d7a84155ccfab247f">commit</a>)</p>
<p><code>.delay()</code>方法会根据参数滞后若干毫秒执行队列里剩下的对象。默认的它会使用”fx”队列。但你可以选择性的通过<code>delay</code>方法的第二个参数选择其他队列。(译注:每个队列都以一个名字识别。)</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript">$<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"div"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">fadeIn</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">delay</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(204, 0, 0);">4000</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">fadeOut</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<p><strong>队列里的<code>next</code></strong> (<a href="http://api.jquery.com/queue/">.queue() 文档</a>, <a href="http://github.com/jquery/jquery/commit/89b4bc53ca0ca3d4e5c80b94ce92b09cc34af8ef">commit</a>)</p>
<p>jQuery 1.4版里, 当队列里的一个函数被调用的时候，第一个参数会被设为另一个函数。当后者被调用的时候, 会自动排除队列里的下一个对象, 以此来推动队列到下一步。</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript">jQuery<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"div"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">queue</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"ajax"</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span>next<span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span>
  <span style="color: rgb(0, 51, 102); font-weight: bold;">var</span> self <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(0, 0, 102); font-weight: bold;">this</span><span style="color: rgb(51, 153, 51);">;</span>
  jQuery.<span style="color: rgb(102, 0, 102);">getJSON</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"/update"</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span>json<span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span>
    $<span style="color: rgb(0, 153, 0);">(</span>self<span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">html</span><span style="color: rgb(0, 153, 0);">(</span>json.<span style="color: rgb(102, 0, 102);">text</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
    next<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
  <span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(51, 153, 51);">;</span>
<span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">queue</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"ajax"</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span>
  $<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 102); font-weight: bold;">this</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">fadeIn</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span>
<span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<p><strong>.clearQueue()</strong> (<a href="http://api.jquery.com/clearQueue/">clearQueue 文档</a>, <a href="http://github.com/jquery/jquery/commit/d857315967a1cc07b73924bbdf2eb12f4f910c45">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">commit</a>)</p>
<p>所有以ID开头的选择符都得到了优化, 能够在瞬间得到返回值。所有以ID为开头的选择符速度将一直快于其他选择符。</p>
<h4>页面遍访 (Traversing)</h4>
<p><strong>.index(), .index(String)</strong> (<a href="http://api.jquery.com/index/">index 文档</a>, <a href="http://github.com/jquery/jquery/commit/ffd457d4561eb1a6653aaef90f92a3b3010b9139">commit</a>)</p>
<p><code>.index()</code> 方法经过重写, 变得更加直观和灵活。</p>
<p>你可以获得一个元素相对于同父元素的指数:</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript"><span style="color: rgb(0, 102, 0); font-style: italic;">// 计算第一个 &lt;li class="current"&gt; 元素在它所有的同父元素中的指数:</span>
$<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"li.current"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">index</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span></pre>
</div>
</div>
<p>你也可以获得一个元素在一个jQuery元素集合中的指数, 这个集合可以用一个选择符或者是一个DOM元素来指定:</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="javascript"><span style="color: rgb(0, 102, 0); font-style: italic;">// 计算这个 &lt;h3 id="more-info"&gt; 元素在页面上所有 &lt;h3&gt; 元素里的指数:
$<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"#more-info"</span><span style="color: rgb(0, 153, 0);">)</span>.<span style="color: rgb(102, 0, 102);">index</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">"h3"</span><span style="color: rgb(0, 153, 0);">)</span>

</span></pre>
</div>
</div>
<p><strong>新的.has()方法</strong> (<a href="http://api.jquery.com/has/">has 文档</a>, <a href="http://github.com/jquery/jquery/commit/4e27f17007c2329e31b449e61bb31197b90a37f1">commit</a>)</p>
<p>这个方法相当于选择符里的<code>:has()</code>过滤法。它拿到一个jQuery集合,返回含有指定选择符的元素。</p>
<p><strong>新的 .nextUntil(), .prevUntil(), .parentsUntil() 方法</strong> (<a href="http://api.jquery.com/nextUntil/">.nextUntil() 文档</a>, <a href="http://api.jquery.com/prevUntil/">.prevUntil() 文档</a>, <a href="http://api.jquery.com/parentsUntil/">.parentsUntil() 文档</a>, <a href="http://github.com/jquery/jquery/commit/2b481b93cfca62f95aa7005e7db651456fa08e65">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">.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">commit</a>)</p>
<p>可以给<code>.add()</code>方法指定环境了。这个功能可以用于在一个调用链中加入和操作额外元素(比如Ajax请求里返回的新元素)。</p>
<p><strong>.closest(filter, DOMElement)</strong> (<a href="http://api.jquery.com/closest/">.closest() 文档</a>, <a href="http://github.com/jquery/jquery/commit/d6991fa273515a8503692324499edcc71b5c3f64">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/">jQuery.isEmptyObject() 文档</a>, <a href="http://github.com/jquery/jquery/commit/a38a5cd531a328319f8b7f3f33a84044b54591ce">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/">jQuery.isPlainObject()</a>, <a href="http://github.com/jquery/jquery/commit/4b55e94d0849568a2fd121952f13a9d6571c731f">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/">jQuery.contains() 文档</a>, <a href="http://github.com/jquery/jquery/commit/4e27f17007c2329e31b449e61bb31197b90a37f1">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/">jQuery.noop() 文档</a>, <a href="http://github.com/jquery/jquery/commit/6cb2945837ccca55204191a8e7a70b2b2486c28e">commit</a>)</p>
<p>是个空的函数, 可以用在必须要有一个函数的情况下。(译注: noop是No Operation的意思。)</p>
<p><strong>jQuery.unique()</strong> (<a href="http://api.jquery.com/jQuery.unique/">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/">jQuery.browser 文档</a>, <a href="http://jquery14.com/day-01/%3Cbr%20/%3Ehttp://github.com/jquery/jquery/commit/ffb1867a4364ea65e60dad3469e8c8eb420ebcac">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">commit 1</a>, <a href="http://github.com/jquery/jquery/commit/3ec2f1aef6b137d0f639e2fc53f95352d24b9d90">commit 2</a>)</p>
<p>jQuery不再试图在Java applets上绑定事件或是数据了(绑定事件或是数据会出现错误)。</p>
<p><strong>不再使用arguments.callee</strong> (<a href="http://github.com/jquery/jquery/commit/985856b823b1648bffc3fd63c1faf836d0ddaf7c">commit</a>)</p>
<p>为了顺应<a href="http://code.google.com/p/google-caja/">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">commit</a>)</p>
<h4>内部重组 (Internal Reorganization)</h4>
<p>在1.4版的开发过程中的一个重点是要建立一个更易读, 更易懂的代码库。为了达到这个目标我们树立了一系列编写代码规范的向导。</p>
<p>下面是一些主要的变化:</p>
<ul>
<li>旧的’core.js’文件被分成了’attribute.js’, ‘css.js’, ‘data.js’, ‘manipulation.js’, ‘traversing.js’, and ‘queue.js’.</li>
<li>ready事件被移入了’core.js’ (因为它是jQuery的一个基本组成之一)。</li>
<li>大部分核心代码都符合新的<a href="http://docs.jquery.com/JQuery_Core_Style_Guidelines">代码规范</a>.</li>
<li>css和属性的逻辑被划分开来, 不再如以往相互缠绕。</li>
</ul>
<h4>测试 (Testing)</h4>
<p>jQuery 1.4版发布过程中我们<a href="http://dev.jquery.com/report/34">修复了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"><img width="500" height="277" alt="jQuery 1.4 测试结果" src="http://www.uxd2.com/wp-content/uploads/2010/01/08-test.jpg" title="jQuery 1.4 测试结果" class="alignnone size-full wp-image-81"></a></p>
<h3><a name="backwards"></a></h3>
<p>我们尽量试图减小jQuery 1.4对大规模升级可能造成的麻烦 &ndash; 保持所有公开函数的签名不变。即使如此, 请通读下面的列表以保证你对可能对你的应用造成问题的变更。</p>
<ul>
<li><a href="http://api.jquery.com/add">.add()</a>不再简单的将结果串联到一起, 结果将会被混合到一起, 然后根据他们在页面里的顺序排列。</li>
<li><a href="http://api.jquery.com/clone">.clone(true)</a>将复制事件和数据, 而不仅是事件。</li>
<li><a href="http://api.jquery.com/jQuery.data">jQuery.data(elem)</a> 不再返回<code>id</code>, 取而代之的是元素的对象缓存。</li>
<li><a href="http://api.jquery.com/jQuery">jQuery()</a> (无参数) 不再自动转换成<a href="http://api.jquery.com/jQuery">jQuery(document)</a>了。</li>
<li>通过<a href="http://api.jquery.com/val">.val(“…”)</a>获得一个<code>option</code>或一个<code>checkbox</code>的值不再有歧义(将总是根据<code>value</code>属性选择, 而不是根据<code>text</code>的值)。(<a href="http://github.com/jquery/jquery/commit/f298cce100c6fe23840ac95e66aaea9cb2bfb447">Commit</a>)</li>
<li><a href="http://api.jquery.com/jQuery.browser">jQuery.browser.version</a>现在将返回引擎的版本.</li>
<li>现在起将对引入的JSON更严格, 如果JSON的格式不符将会报错。如果你需要对不符合JSON严格格式的Javascript进行估值, 你必须设置请求的文件类型为纯文本, 然后用<code>eval()</code>来对内容估值。</li>
<li>参数序列化默认会按照PHP/Rails的风格进行。你可以通过<code>jQuery.ajaxSettings.traditional = true;</code>来切换到旧的序列化方式。你也可以针对个别请求进行切换, 在调用<a href="http://api.jquery.com/jQuery.ajax">jQuery.ajax</a>的时候递入<code>{traditional: true}</code></li>
<li>内部的jQuery.className被移除了。</li>
<li><a href="http://api.jquery.com/jQuery.extend">jQuery.extend(true, …)</a>不再扩展复杂对象或是阵列。(TODO)</li>
<li>如果一个<a href="http://api.jquery.com/jQuery.ajax">Ajax请求</a>没有指定dataType, 而返回的数据类型是”text/javascript”, 那么回复将会被执行。之前, 必须明确的指定dataType。</li>
<li>设置<a href="http://api.jquery.com/jQuery.ajax">Ajax 请求</a>的”ifModified”属性会将ETags纳入考虑。</li>
</ul>
<p>我们还针对1.4版中可能造成问题的变更编写了一个向后兼容的<a href="http://github.com/jquery/jquery-compat-1.3">插件</a>。如果你升级到1.4以后出现问题, 可以在引入1.4版的文件之后引入这个插件。</p>
<p>如何使用这个插件:</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace;" class="html4strict"><span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(0, 0, 0); font-weight: bold;">script</span> <span style="color: rgb(0, 0, 102);">src</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"http://code.jquery.com/jquery.js"</span>&gt;&lt;<span style="color: rgb(102, 204, 102);">/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">script</span>&gt;</span>
<span style="color: rgb(0, 153, 0);">&lt;<span style="color: rgb(0, 0, 0); font-weight: bold;">script</span> <span style="color: rgb(0, 0, 102);">src</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"http://code.jquery.com/jquery.compat-1.3.js"</span>&gt;&lt;<span style="color: rgb(102, 204, 102);">/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">script</span>&gt;</span></pre>
</div>
</div>
<h3>原始数据和测试页面</h3>
<p>性能测试中我们使用了下列测试套包:</p>
<ul>
<li><a href="http://ejohn.org/files/jquery1.4/slick/?type=attr">Attributes</a></li>
<li><a href="http://ejohn.org/files/jquery1.4/slick/?type=class">Class</a></li>
<li><a href="http://ejohn.org/files/jquery1.4/slick/?type=dom">DOM Manipulation</a></li>
<li><a href="http://ejohn.org/files/jquery1.4/slick/?type=empty">Empty/Remove</a></li>
<li>Function Call Profiling: <a href="http://ejohn.org/files/jquery-profile.html">1.3.2</a> <a href="http://ejohn.org/files/jquery-profile-14.html">1.4</a>.</li>
</ul>
<p>结果的原始数据 (所有的数据都是 1.3.2 vs. 1.4):</p>
<pre>函数调用的次数
547    3
760    3
500    200
896    399
23909    299
307    118
28955    100
28648    201
1662    593

DOM嵌入
558    317
1079    624
1079    516
1155    829
436    332
196    194
243    169

HTML
116    46
281    78
313    78
234    63
134    43
43    42
91    27

CSS/属性
703    370
1780    1250
1765    1250
1157    749
629    498
346    184
333    161

CSS
114    52
203    93
118    93
109    47
116    54
58    24
54    22

CSS类
553    138
1578    546
1515    501
1033    327
769    298
229    80
173    41

移除/清空
3298    286
9030    2344
7921    1703
5282    1266
2898    303
1166    140
1034    122</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.artcss.com/archives/677.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery 简介[转]</title>
		<link>http://www.artcss.com/archives/156.html</link>
		<comments>http://www.artcss.com/archives/156.html#comments</comments>
		<pubDate>Tue, 21 Jul 2009 02:17:33 +0000</pubDate>
		<dc:creator>Artcss</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.artskin.cn/blog/?p=156</guid>
		<description><![CDATA[Query是一个优秀的javascript类库，jQuery以其简洁、快速等优点征服了众多javascript开发者。jQuery使用户能更方便地处理DOM、events、实现动画效果，并且方便地为网站提供Ajax 交互。jQuery能够使用户的html页保持代码和html内容分离，也就是说，不用再在html里面插入一堆javascript来调用命令了，只需定义id即可。(跟css有点类似)jQuery如何操作DOM等等，另外还会介绍一些常用的jQuery插件分享给大家，希望通过jQuery快乐的学习javascript。 JQuery由美国人John Resig创建，至今已吸引了来自世界各地的众多javascript高手加入其team，包括来自德国的Jörn Zaefferer，罗马尼亚的Stefan Petre等等。 jQuery是继prototype之后又一个优秀的Javascrīpt框架。其宗旨是——WRITE LESS,DO MORE,写更少的代码,做更多的事情。jQuery对象？ 它是轻量级的js库(压缩后只有21k) ，这是其它的js库所不及的，它兼容CSS3，还兼容各种浏览器 （IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+）。 jQuery是一个快速的，简洁的javaScript库，使用户能更方便地处理HTML documents、events、实现动画效果，并且方便地为网站提供AJAX交互。 jQuery还有一个比较大的优势是，它的文档说明很全，而且各种应用也说得很详细，同时还有许多成熟的插件可供选择。 jQuery能够使用户的html页保持代码和html内容分离，也就是说，不用再在html里面插入一堆js来调用命令了，只需定义id即可。 Jquery是继prototype之后又一个优秀的Javascrīpt框架。对prototype我使用不多，简单了解过。但使用上jquery之后，马上被她的优雅吸引住了。有人使用这样的一比喻来比较prototype和jquery：prototype就像Java，而jquery就像 ruby.实际上我比较喜欢java（少接触Ruby 罢了）但是jquery的简单的实用的确有相当大的吸引力啊！在项目里我把jquery作为自己唯一的框架类包。使用其间也有一点点心得，其实这些心得，在jquery的文档上面也可能有讲，不过还是记下来，以备忘罢。 一、找到你了！ 还记得$()这个东西吧？prototype还是DWR都使用了这个函数代替document.getElementById()。没错，jquery也跟风了。为达到document.getElementById()的目的，jquery是这样写的： 代码 var someElement = $(”#myId”); 看起来比其他两个框架的要多了一个#，好，看看下面的用法： 代码 $(”div p”);(1) $(”div.container”)(2) $(”div #msg”);(3) $(”table a”,context);(4) 在prototype里看过这样的写法吗？第一行代码得到所有&#60;div&#62;标签下的&#60;p&#62;元素。第二行代码得到class 为container的&#60;div&#62;元素,第三行代码得到&#60;div&#62;标签下面id为msg的元素。第四行代码得到context为上下文的table里面所有的连接元素。 如果你熟悉CSS，你会觉得这些写法很眼熟！对了。正是。看出奥妙了吧。jquery就是通过这样的方式来找到Dom对象里面的元素。跟CSS的选择器相类似。 二、Jquery函数 jquery提供了很多便利的函数，如each(fn)，但是使用这些函数的前提是：你使用的对象是Jquer对象。使一个Dom对象成为一个Jquery对象很简单，通过下面一些方式（只是一部分）： 代码 var a = $(”#cid”);(1) var b = [...]]]></description>
			<content:encoded><![CDATA[<p>Query是一个优秀的javascript类库，jQuery以其简洁、快速等优点征服了众多javascript开发者。<span id="more-156"></span>jQuery使用户能更方便地处理DOM、events、实现动画效果，并且方便地为网站提供Ajax 交互。jQuery能够使用户的html页保持代码和html内容分离，也就是说，不用再在html里面插入一堆javascript来调用命令了，只需定义id即可。(跟css有点类似)jQuery如何操作DOM等等，另外还会介绍一些常用的jQuery插件分享给大家，希望通过jQuery快乐的学习javascript。</p>
<p>JQuery由美国人John Resig创建，至今已吸引了来自世界各地的众多javascript高手加入其team，包括来自德国的Jörn Zaefferer，罗马尼亚的Stefan Petre等等。<br />
jQuery是继prototype之后又一个优秀的Javascrīpt框架。其宗旨是——WRITE LESS,DO MORE,写更少的代码,做更多的事情。jQuery对象？</p>
<p>它是轻量级的js库(压缩后只有21k) ，这是其它的js库所不及的，它兼容CSS3，还兼容各种浏览器 （IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+）。</p>
<p>jQuery是一个快速的，简洁的javaScript库，使用户能更方便地处理HTML documents、events、实现动画效果，并且方便地为网站提供AJAX交互。</p>
<p>jQuery还有一个比较大的优势是，它的文档说明很全，而且各种应用也说得很详细，同时还有许多成熟的插件可供选择。<br />
jQuery能够使用户的html页保持代码和html内容分离，也就是说，不用再在html里面插入一堆js来调用命令了，只需定义id即可。</p>
<p>Jquery是继prototype之后又一个优秀的Javascrīpt框架。对prototype我使用不多，简单了解过。但使用上jquery之后，马上被她的优雅吸引住了。有人使用这样的一比喻来比较prototype和jquery：prototype就像Java，而jquery就像 ruby.实际上我比较喜欢java（少接触Ruby 罢了）但是jquery的简单的实用的确有相当大的吸引力啊！在项目里我把jquery作为自己唯一的框架类包。使用其间也有一点点心得，其实这些心得，在jquery的文档上面也可能有讲，不过还是记下来，以备忘罢。</p>
<h4>一、找到你了！</h4>
<p>还记得$()这个东西吧？prototype还是DWR都使用了这个函数代替document.getElementById()。没错，jquery也跟风了。为达到document.getElementById()的目的，jquery是这样写的：<br />
代码<br />
var someElement = $(”#myId”);<br />
看起来比其他两个框架的要多了一个#，好，看看下面的用法：<br />
代码<br />
$(”div p”);(1)<br />
$(”div.container”)(2)<br />
$(”div #msg”);(3)<br />
$(”table a”,context);(4)</p>
<p>在prototype里看过这样的写法吗？第一行代码得到所有&lt;div&gt;标签下的&lt;p&gt;元素。第二行代码得到class 为container的&lt;div&gt;元素,第三行代码得到&lt;div&gt;标签下面id为msg的元素。第四行代码得到context为上下文的table里面所有的连接元素。<br />
如果你熟悉CSS，你会觉得这些写法很眼熟！对了。正是。看出奥妙了吧。jquery就是通过这样的方式来找到Dom对象里面的元素。跟CSS的选择器相类似。 </p>
<h4>二、Jquery函数</h4>
<p>jquery提供了很多便利的函数，如each(fn)，但是使用这些函数的前提是：你使用的对象是Jquer对象。使一个Dom对象成为一个Jquery对象很简单，通过下面一些方式（只是一部分）：</p>
<p>代码</p>
<p>var a = $(”#cid”);(1)<br />
var b = $(”</p>
<p>hello</p>
<p>”);(2)<br />
var c = document.createElement(”table”); var tb = $©;</p>
<h4>三、代替body标签的onload</h4>
<p>这个惯例，也许是除了$()之外，用得最多的地方了。下面一段代码：</p>
<p>代码</p>
<p>$(document).ready(function(){<br />
alert(”hello”);<br />
});(1)</p>
<p>（2）</p>
<p>上面两段代码是等价的。但代码1的好处是做到表现和逻辑分离。并且可以在不同的js文件中做相同的操作，即$(document).ready (fn)可以在一个页面中重复出现，而不会冲突。基本上Jqeury的很多plugin都是利用这个特性，正因为这个特性，多个plugin共同使用起来，在初始化时不会发生冲突。<br />
不管怎么说，这个惯例可以分离javascrīpt与HTML。推荐使用。</p>
<h4>四、事件机制</h4>
<p>我大量使用的事件可能就是button的onclick了。以前习惯在input 元素上写onclick = “fn()”,使用jquery可以使javascrīpt代码与html代码分离，保持HTML的清洁，还可以很轻松地绑定事件，甚至你可以不知道“事件”这个名词。</p>
<p>代码</p>
<p>$(document).ready(function(){<br />
$(”#clear”).click(function(){<br />
alert(”i am about to clear the table”);<br />
});<br />
$(”form[0]”).submit(validate);<br />
});<br />
function validate(){<br />
//do some form validation<br />
}</p>
<h4>五、同一函数实现set</h4>
<p>代码</p>
<p>$(”#msg”).html();<br />
$(”#msg”).html(”hello”);<br />
上面两行代码，调用了同样的函数。但结果却差别很大。<br />
第一行是返回指定元素的HTML值，第二行则是将hello这串字符设置到指定元素中。jquery的函数大部分有这样的特性。</p>
<h4>六、ajax</h4>
<p>这是一个ajax横行的时代。多少人，了不了解ajax的都跟着用上一把。呵。使用jquery实现ajax同样简单异常</p>
<p>代码</p>
<p>$.get(”search.do”,{id:1},rend);<br />
function rend(xml){<br />
alert(xml);<br />
} (1)<br />
$.post(”search.do”,{id:1},rend);<br />
function rend(xml){<br />
alert(xml);<br />
} (2)</p>
<p>$(”#msg”).ajaxStart(function(){<br />
this.html(”正在加载。。。。”);<br />
});(3)<br />
$(”#msg”).ajaxSuccess(function(){<br />
this.html(”加载完成！”);<br />
});(4)</p>
<p>这些都是较常用的方法，get和post用法一样。第一个参数是异步请求的url，第二个为参数，第三个回调方法。<br />
3，4的方法会在指定的Dom对象上绑定响应ajax执行的事件。当然，jquery的AJAX相关的函数不仅是这些，有兴趣可以去研究再多。</p>
<h4>七、渐入淡出</h4>
<p>代码<br />
$(”#msg”).fadeIn(”fast”);<br />
$(”#msg”).fadeOut(”slow”);</p>
<p>没错，上面两行代码已经分别实现了一个id为Msg的jquery对象的渐入和淡出。做一个像Gmail一样的动态加载通知条，用jquery就那么简单。两个函数接受的参数除了快慢等，还可以接收整型，作为渐入或淡出的完成时间，单位为MS。</p>
<h4>八、plugin</h4>
<p>这也是一个插件的时代。</p>
<p>jquery插件给我的感觉清一色的清洁，简单。如Jtip，要使用它的功能，只需要在你的元素的class上加上Jtip,并引入jtip.js及其样式即可以了。其他事情插件全包。我喜欢jquery的一个重要原因是发现她已经有了很多很好，很精彩的插件。</p>
<p>写得很烂。可能大家看不出jquery的好处。嗯，光听是没用的，试用一下吧。你会发觉很有趣。</p>
<p>暂时告一段落吧。待有新的发现再来分享。</p>
<p>加一些Jquery的资源：<br />
http://www.visualjquery.com/index.xml 很好的API查询站点<br />
http://jquery.com/demo/thickbox/ 知道lightBox吧，看看Jquery是怎样实现相同的东西<br />
http://www.codylindley.com/blogstuff/js/jtip/ Jtip，实用的提示工具<br />
http://jquery.com/plugins/ 很多牛的插件。<br />
http://15daysofjquery.com/jquery 的15天教程<br />
http://jquery.org.cn/visual/cn/index.xml //不错的JQUERY 中文学习 推荐</p>
<p>jquery来源</p>
<p>jQuery由美国人John Resig创建，至今已吸引了来自世界各地的众多javascript高手加入其team，包括来自德国的Jörn Zaefferer，罗马尼亚的Stefan Petre等等。</p>
<p>jQuery是继prototype之后又一个优秀的Javascrīpt框架。其宗旨是——WRITE LESS,DO MORE,写更少的代码,做更多的事情。</p>
<p>它是轻量级的js库(压缩后只有21k) ，这是其它的js库所不及的，它兼容CSS3，还兼容各种浏览器 （IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+）。</p>
<p>jQuery是一个快速的，简洁的javaScript库，使用户能更方便地处理HTML documents、events、实现动画效果，并且方便地为网站提供AJAX交互。</p>
<p>jQuery还有一个比较大的优势是，它的文档说明很全，而且各种应用也说得很详细，同时还有许多成熟的插件可供选择。<br />
jQuery能够使用户的html页保持代码和html内容分离，也就是说，不用再在html里面插入一堆js来调用命令了，只需定义id即可。</p>
<p>jQuery的官方下载地址为：http://jquery.com/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artcss.com/archives/156.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>不可错过的Jquery UI库（一）</title>
		<link>http://www.artcss.com/archives/35.html</link>
		<comments>http://www.artcss.com/archives/35.html#comments</comments>
		<pubDate>Wed, 15 Jul 2009 07:42:50 +0000</pubDate>
		<dc:creator>Artcss</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://artskin.jhost.cn/blog/?p=35</guid>
		<description><![CDATA[Jquery Tools是一组基于Jquery构建的用户界面常用组件的集合。通过使用Jquery Tools，网站前端开发无疑会变得更加高效。值得注意的是，Jquery Tools的gzip压缩版本仅有5.8k，如此轻量级而且功能实用的UI组件绝对值得我们关注。下面是官方主页对它的一个描述： Jquery Tools包含如今网站六个最有用的javascript工具。它的一个优点是所有这些工具可以一起使用、扩展、配置和样式化。 最终，通过它你可以制作出众多不同的网站部件，或用个人的方式创造新的应用。（This library contains six of the most useful JavaScript tools available for today’s website. The beauty of this library is that all of these tools can be used together, extended, configured and styled. In the end, you can have hundreds of different widgets and new personal ways of using [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.artskin.cn/blog/wp-content/uploads/2009/07/jquery-tools.jpg"><img class="alignnone size-full wp-image-36" title="jquery-tools" src="http://www.artskin.cn/blog/wp-content/uploads/2009/07/jquery-tools.jpg" alt="jquery-tools" width="480" height="171" /></a></p>
<p><a onclick="javascript:pageTracker._trackPageview('/outbound/article/flowplayer.org');" href="http://flowplayer.org/tools/">Jquery Tools</a>是一组基于Jquery构建的用户界面常用组件的集合。通过使用Jquery Tools<span id="more-35"></span>，网站前端开发无疑会变得更加高效。值得注意的是，Jquery Tools的gzip压缩版本仅有5.8k，如此轻量级而且功能实用的UI组件绝对值得我们关注。下面是官方主页对它的一个描述：</p>
<blockquote><p>Jquery Tools包含如今网站六个最有用的javascript工具。它的一个优点是所有这些工具可以一起使用、扩展、配置和样式化。</p>
<p>最终，通过它你可以制作出众多不同的网站部件，或用个人的方式创造新的应用。（This library contains six of the most useful JavaScript tools available for today’s website. The beauty of this library is that all of these tools can be used together, extended, configured and styled. In the end, you can have hundreds of different widgets and new personal ways of using the library. ）</p></blockquote>
<p>下面是Jquery UI包含的工具列表：</p>
<ol>
<li>选项卡功能(Tabs)</li>
<li>提示工具条功能(ToolTips)</li>
<li>信息滚动功能(Scrollable)</li>
<li>遮罩效果(overlay)</li>
<li>突出效果(expose)</li>
<li>Flash嵌入</li>
</ol>
<p>有人可能会拿jquery tools和jquery ui去做对比，因为这个，国外还有过不小的争论。感兴趣的可以看看这篇文章：<a onclick="javascript:pageTracker._trackPageview('/outbound/article/marcgrabanski.com');" href="http://marcgrabanski.com/article/jquery-tools-vs-jquery-ui">Jquery Tools VS Jquery UI</a>，国内也有人对此发表过<a onclick="javascript:pageTracker._trackPageview('/outbound/article/dalada.blogspot.com');" href="http://dalada.blogspot.com/2009/06/jquery-tools.html">言论</a>（blogspot被墙了，可能访问不了），下面是一些引用：</p>
<blockquote><p>原因就出在於TOOLS官網上寫明了它就是要補jQuery UI不足之處，例如：TOOLS有UI缺乏的tooltips、tabs、overlays等功能，且強調檔案比UI還要小。</p>
<p>marcgrabanski認為TOOLS既然對於UI不足之處有意見，最初就應該加入該UI團隊，一起協同開發改造出新版本，畢竟當初是受到UI的啟發，到後來卻因UI不足之處，甚至另起爐灶創立一個新品牌，這樣的行徑並不厚道。</p>
<p>但支持TOOLS的人卻也有不同的聲音，認為網頁開發者本來就是會殷切期望會有更小、更有效率的plugin，UI長久來效能不是最好，不過大家也都無從選擇起，如今又有新的plugin出現，大家樂見其成，應該給予鼓勵。</p></blockquote>
<p>Jquery Tools在以下浏览器中测试通过：</p>
<ul>
<li><a onclick="javascript:pageTracker._trackPageview('/outbound/article/www.microsoft.com');" href="http://www.microsoft.com/windows/products/winfamily/ie/">Internet Explorer</a> 6+</li>
<li><a onclick="javascript:pageTracker._trackPageview('/outbound/article/www.mozilla.com');" href="http://www.mozilla.com/en-US/firefox/">Firefox</a> 2.0+</li>
<li><a onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');" href="http://www.google.com/chrome/">Chrome</a> 1+</li>
<li><a onclick="javascript:pageTracker._trackPageview('/outbound/article/www.opera.com');" href="http://www.opera.com/browser/">Opera</a> 9+</li>
<li><a onclick="javascript:pageTracker._trackPageview('/outbound/article/www.apple.com');" href="http://www.apple.com/safari/">Safari</a> 3+</li>
</ul>
<p>由于Jquery Tools相关使用要写的东西比较多，所以本博决定分成几篇来写，本篇主要是给大家一个基本的介绍。从下一篇开始依次介绍Jquery Tools中各工具的使用及示例。心急的朋友可以去官方站点的<a onclick="javascript:pageTracker._trackPageview('/outbound/article/flowplayer.org');" href="http://flowplayer.org/tools/demos/index.html">这个页面</a>，上面给出了丰富的示例。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artcss.com/archives/35.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

