<?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>Leeiio Chaos Made. &#187; JS/Ajax/AS/Flex</title>
	<atom:link href="http://leeiio.me/category/design/javascript-design/feed/" rel="self" type="application/rss+xml" />
	<link>http://leeiio.me</link>
	<description>The site is redesigning,please be patient  :P</description>
	<lastBuildDate>Sun, 29 Jan 2012 16:40:23 +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>a snippet for testing whether you could visit twtter or facebook</title>
		<link>http://leeiio.me/a-snippet-for-testing-whether-could-visit-twtter-or-facebook/</link>
		<comments>http://leeiio.me/a-snippet-for-testing-whether-could-visit-twtter-or-facebook/#comments</comments>
		<pubDate>Sun, 27 Nov 2011 16:52:20 +0000</pubDate>
		<dc:creator>Leeiio</dc:creator>
				<category><![CDATA[JS/Ajax/AS/Flex]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://leeiio.me/?p=2429</guid>
		<description><![CDATA[Some of you guys like add &#8220;Twitter button&#8221; or &#8220;Facebook Like button&#8221; on your website. But if your visitor from china that don&#8217;t use VPN or anyother jailbreak the G-F-W tools, it will slow down the page load until the &#8230; <a href="http://leeiio.me/a-snippet-for-testing-whether-could-visit-twtter-or-facebook/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Some of you guys like add &#8220;<strong>Twitter button</strong>&#8221; or &#8220;<strong>Facebook Like button</strong>&#8221; on your website. But if your visitor from china that don&#8217;t use VPN or anyother jailbreak the G-F-W tools, it will slow down the page load until the browser&#8217;s default timeout time &#8220;60s&#8221;.<br />
So i wrote this code snippet,now you can use this code snippet to test whether they could visit the Twitter or Facebook, if could then load the &#8220;Twitter button&#8221; or &#8220;Facebook Like button&#8221; scripts.</p>
<p>Enjoy it!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Leeiio <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
Leeiio.<span style="color: #660066;">isFucked</span><span style="color: #339933;">;</span>
&nbsp;
Leeiio.<span style="color: #660066;">fuck</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> imgUrl <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://twitter.com/favicon.ico?&quot;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//You can change it to &quot;http://www.facebook.com/favicon.ico?&quot;</span>
    imgUrl <span style="color: #339933;">+=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//add Time stamp to prevent the Browser's cache</span>
    <span style="color: #003366; font-weight: bold;">function</span> removeElement<span style="color: #009900;">&#40;</span>_element<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #003366; font-weight: bold;">var</span> _parentElement <span style="color: #339933;">=</span> _element.<span style="color: #660066;">parentNode</span><span style="color: #339933;">;</span>
         <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>_parentElement<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                _parentElement.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span>_element<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #003366; font-weight: bold;">function</span> testImg<span style="color: #009900;">&#40;</span>isrc<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> fuckimg <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'iframe'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//I used to createElement('img') but it have some problem in webkit</span>
        fuckimg.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> imgUrl<span style="color: #339933;">;</span>
        fuckimg.<span style="color: #660066;">style</span>.<span style="color: #660066;">cssText</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;display:none&quot;</span><span style="color: #339933;">;</span>
        document.<span style="color: #660066;">body</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>fuckimg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        fuckimg.<span style="color: #660066;">timer</span> <span style="color: #339933;">=</span> setTimeout<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Fuck it!(You know fuck what right?)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            fuckimg.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
            fuckimg.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
            removeElement<span style="color: #009900;">&#40;</span>fuckimg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Leeiio.<span style="color: #660066;">isFucked</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3290</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #006600; font-style: italic;">//set timeout to connect to twitter</span>
        fuckimg.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            clearTimeout<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">timer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Nice!You are free man!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            fuckimg.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
            fuckimg.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
            removeElement<span style="color: #009900;">&#40;</span>fuckimg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Leeiio.<span style="color: #660066;">isFucked</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    testImg<span style="color: #009900;">&#40;</span>imgUrl<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
Leeiio.<span style="color: #660066;">fuck</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> timeTest <span style="color: #339933;">=</span> setTimeout<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Leeiio.<span style="color: #660066;">isFucked</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">//add your code here that you want to</span>
        <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Fuck!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    clearTimeout<span style="color: #009900;">&#40;</span>timeTest<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">4000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>See Demo here:<a href="http://leeiio.me/demo/fuck_yeah.html" target="_blank">http://leeiio.me/demo/fuck_yeah.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://leeiio.me/a-snippet-for-testing-whether-could-visit-twtter-or-facebook/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>匹配一段文本中URL的正则问题</title>
		<link>http://leeiio.me/url-in-text-regexp/</link>
		<comments>http://leeiio.me/url-in-text-regexp/#comments</comments>
		<pubDate>Wed, 25 May 2011 15:42:56 +0000</pubDate>
		<dc:creator>Leeiio</dc:creator>
				<category><![CDATA[JS/Ajax/AS/Flex]]></category>

		<guid isPermaLink="false">http://leeiio.me/?p=2336</guid>
		<description><![CDATA[在项目中有个这样的设计，备注中的URL自动识别为点击的链接，对此的处理方式是用正则匹配出URL部分，然后替换成&#60;a href=URL>URL这样即可。其主要部分是正则匹配出URL部分。 假设有这么一段文本。 你好，我是一段文本。我链接到http://leeiio.me/test.html请大家多多指教。 那么我们可以这么写。 var text = &#34;你好，我是一段文本。我链接到http://leeiio.me/test.html请大家多多指教。&#34;; var regexp = /((http&#124;ftp&#124;https&#124;file):\/\/([\w\-]+\.)+[\w\-]+(\/[\w\-\.\/?\@\%\!\&#38;=\+\~\:\#\;\,]*)?)/ig; text = text.replace&#40;regexp,&#34;&#60;a href='$1'&#62;$1&#60;/a&#62;&#34;&#41;; console.log&#40;text&#41;; 但是如果URL中带有中文，那么以上的就不顶事了。 虽然我们不应该用中文作为URL的一部分，已经把中文部分encode掉，但是很多人比如粗心的写wordpressd的人，通常不指定Slug，那么很多URL自然也就带上了标题的中文了。比如： 假设有这么一段文本。 你好，我是一段文本。我链接到http://leeiio.me/这是一篇测试.html 请大家多多指教。 那么应该把正则改成这样 var text = &#34;你好，我是一段文本。我链接到http://leeiio.me/这是一篇测试.html 请大家多多指教。&#34;; var regexp = /((http&#124;ftp&#124;https&#124;file):\/\/([\w\-]+\.)+[\w\-]+(\/[\w\u4e00-\u9fa5\-\.\/?\@\%\!\&#38;=\+\~\:\#\;\,]*)?)/ig; text = text.replace&#40;regexp,&#34;&#60;a href='$1'&#62;$1&#60;/a&#62;&#34;&#41;; console.log&#40;text&#41;; 不过如果以上这段文本在&#8221;html&#8221;和&#8221;请&#8221;字中间没有空格的话，也会错误地把后面的&#8221;请大家多多指教。&#8221;识别为URL的一部分，所以说也并不是十分完美。而且如果标题是汉文呢？日文呢？就不行了，因为刚才正则中增加的\u4e00-\u9fa5只是中文的编码区间。 既然如此我们就使用更加暴力的正则吧。比如这么一段文本： &#8230; <a href="http://leeiio.me/url-in-text-regexp/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>在项目中有个这样的设计，备注中的URL自动识别为点击的链接，对此的处理方式是用正则匹配出URL部分，然后替换成&lt;a href=URL>URL</a>这样即可。其主要部分是正则匹配出URL部分。</p>
<p>假设有这么一段文本。</p>
<blockquote><p>
你好，我是一段文本。我链接到http://leeiio.me/test.html请大家多多指教。
</p></blockquote>
<p>那么我们可以这么写。</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> text <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;你好，我是一段文本。我链接到http://leeiio.me/test.html请大家多多指教。&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> regexp <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/((http|ftp|https|file):\/\/([\w\-]+\.)+[\w\-]+(\/[\w\-\.\/?\@\%\!\&amp;=\+\~\:\#\;\,]*)?)/ig</span><span style="color: #339933;">;</span>
text <span style="color: #339933;">=</span> text.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span>regexp<span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&lt;a href='$1'&gt;$1&lt;/a&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>但是如果URL中带有中文，那么以上的就不顶事了。<br />
<span id="more-2336"></span><br />
虽然我们不应该用中文作为URL的一部分，已经把中文部分encode掉，但是很多人比如粗心的写wordpressd的人，通常不指定Slug，那么很多URL自然也就带上了标题的中文了。比如：</p>
<p>假设有这么一段文本。</p>
<blockquote><p>
你好，我是一段文本。我链接到http://leeiio.me/这是一篇测试.html 请大家多多指教。
</p></blockquote>
<p>那么应该把正则改成这样</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> text <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;你好，我是一段文本。我链接到http://leeiio.me/这是一篇测试.html 请大家多多指教。&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> regexp <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/((http|ftp|https|file):\/\/([\w\-]+\.)+[\w\-]+(\/[\w\u4e00-\u9fa5\-\.\/?\@\%\!\&amp;=\+\~\:\#\;\,]*)?)/ig</span><span style="color: #339933;">;</span>
text <span style="color: #339933;">=</span> text.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span>regexp<span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&lt;a href='$1'&gt;$1&lt;/a&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>不过如果以上这段文本在&#8221;html&#8221;和&#8221;请&#8221;字中间没有空格的话，也会错误地把后面的&#8221;请大家多多指教。&#8221;识别为URL的一部分，所以说也并不是十分完美。而且如果标题是汉文呢？日文呢？就不行了，因为刚才正则中增加的\u4e00-\u9fa5只是中文的编码区间。</p>
<p>既然如此我们就使用更加暴力的正则吧。比如这么一段文本：</p>
<blockquote><p>
你好，我是一段文本。我链接到http://leeiio.me/这是一篇测试.html 请大家多多指教。<br />
こんにちは、私はテキストをしています。私はこれはテストですhttp://leeiio.me/にリンクしています.Html のは、展覧会をしてください。<br />
안녕, 난 텍스트입니다. 나는 이것은 테스트입니다 http://leeiio.me/에연결할수있습니다.HTML 을 전시주세요.
</p></blockquote>
<p>对应的正则匹配换成这种</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> text <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;你好，我是一段文本。我链接到http://leeiio.me/这是一篇测试.html 请大家多多指教。こんにちは、私はテキストをしています。私はこれはテストですhttp://leeiio.me/にリンクしています.Html のは、展覧会をしてください。안녕, 난 텍스트입니다. 나는 이것은 테스트입니다 http://leeiio.me/에연결할수있습니다.HTML 을 전시주세요.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> regexp <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/((http|ftp|https|file):[^'&quot;\s]+)/ig</span><span style="color: #339933;">;</span>
text <span style="color: #339933;">=</span> text.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span>regexp<span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&lt;a href='$1'&gt;$1&lt;/a&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>最终的匹配结果是：</p>
<blockquote><p>
你好，我是一段文本。我链 接到&lt;a href=&#8217;http://leeiio.me/这是一篇测试.html&#8217;>http://leeiio.me/这是一篇测试.html< /a> 请大家多多指教。こんにちは、私はテキストをしています。私はこれはテストです&lt;a href=&#8217;http://leeiio.me/にリンクしています.Html&#8217;>http://leeiio.me/にリンクしていま す.Html</a> のは、展覧会をしてください。안녕, 난 텍스트입니다. 나는 이것은 테스트입니다 &lt;a href=&#8217;http://leeiio.me/에연결할수있습니다.HTML&#8217;>http://leeiio.me/에연결할수있습니 다.HTML</a> 을 전시주세요.
</p></blockquote>
<p>当然同上，网址和文字之间得用空格隔开，不然还是会把后面的文字部分也识别为URL的一部分。对于英文文本就显得很有用了，因为英文单词之间肯定都是会用空格隔开的麽。所以也希望大家养成好习惯，在一段文本中URL部分和文本之间用空格隔开。</p>
<p>PS:识别一个邮件地址变成<a href='mailto:email'>email</a>则可以这么干</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> text <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;你好，我是一段文本。我的email地址：test@test.com&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> regexp <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/[a-z0-9_\-+=.]+@[a-z0-9\-]+(\.[a-z0-9-]+)+/ig</span><span style="color: #339933;">;</span>
text <span style="color: #339933;">=</span> text.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span>regexp<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>h<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span><span style="color: #3366CC;">&quot;&lt;a href='mailto:&quot;</span><span style="color: #339933;">+</span>h<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;'&gt;&quot;</span><span style="color: #339933;">+</span>h<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/a&gt;&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>大家的意见以及建议呢？</p>
]]></content:encoded>
			<wfw:commentRss>http://leeiio.me/url-in-text-regexp/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>The Difference Between jQuery’s .bind(), .live(), and .delegate()</title>
		<link>http://leeiio.me/the-difference-between-jquerys-bind-live-and-delegate/</link>
		<comments>http://leeiio.me/the-difference-between-jquerys-bind-live-and-delegate/#comments</comments>
		<pubDate>Mon, 16 May 2011 14:37:00 +0000</pubDate>
		<dc:creator>Leeiio</dc:creator>
				<category><![CDATA[JS/Ajax/AS/Flex]]></category>
		<category><![CDATA[bind()]]></category>
		<category><![CDATA[delegate()]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://leeiio.me/the-difference-between-jquery%e2%80%99s-bind-live-and-delegate/</guid>
		<description><![CDATA[西方不够好的朋友可以看这篇译文《jQuery的.bind()、.live()和.delegate()之间的区别》。这篇文章详细的比较了bind()，live()以及delegate()的区别。以及作者为什么推荐用delegate()。]]></description>
			<content:encoded><![CDATA[<p>西方不够好的朋友可以看这篇译文《<a href="http://article.yeeyan.org/view/213582/179910" title="jQuery的.bind()、.live()和.delegate()之间的区别" target="_blank">jQuery的.bind()、.live()和.delegate()之间的区别</a>》。这篇文章详细的比较了bind()，live()以及delegate()的区别。以及作者为什么推荐用delegate()。</p>
]]></content:encoded>
			<wfw:commentRss>http://leeiio.me/the-difference-between-jquerys-bind-live-and-delegate/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>溢出文本显示省略号,关于text-overflow:ellipsis的那些事</title>
		<link>http://leeiio.me/text-overflow-ellipsis/</link>
		<comments>http://leeiio.me/text-overflow-ellipsis/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 06:49:26 +0000</pubDate>
		<dc:creator>Leeiio</dc:creator>
				<category><![CDATA[(X)HTML/CSS/XML/XSL]]></category>
		<category><![CDATA[JS/Ajax/AS/Flex]]></category>

		<guid isPermaLink="false">http://leeiio.me/?p=2055</guid>
		<description><![CDATA[这个标题其实已经是一个老生常谈的问题了。很多时候，比如网站最基本的文章列表，标题会很长，而显示列表的区域宽度却没有这么宽，这时候最正常的做法就是让超出宽度的部分文字用省略号(&#8230;)来表示。通常做法是网站后台程序截取一定的字符然后输出到前台显示或者前台用javascript截取一定的字符，但是通过控制字数来截取的话还是存在一个大问题的，因为中文和英文的字符宽度问题，这个字数不好控制，而且通用性较差。那么有没有更好的方法呢，比如直接用CSS来解决的，当然是有的。 text-overflow是一个比较特殊的属性，W3C早前的文档中（目前的文档中没有包含text-overflow属性，FML!）对其的定义是: Name: text-overflow-mode Value: clip &#124; ellipsis &#124; ellipsis-word clip : 　不显示省略标记（&#8230;），而是简单的裁切 ellipsis : 　当对象内文本溢出时显示省略标记（&#8230;），省略标记插入的位置是最后一个字符。 ellipsis-word : 　当对象内文本溢出时显示省略标记（&#8230;），省略标记插入的位置是最后一个词（word）。 至于为什么一开始我说text-overflow是一个比较特殊的样式呢？因为我们可以用它代替我们通常所用的标题截取函数，而且这样做对搜索引擎更加友好，如：标题文件有50个汉字，而我们的列表可能只有300px的宽度。如果用标题截取函数，则标题不是完整的，如果我们用CSS样式text-overflow:ellipsis，输出的标题是完整的，只是受容器大小的局限不显示出来罢了（表现上是超出部分显示省略标记&#8230;）。 text-overflow: ellipsis属性仅是注解，当文本溢出时是否显示省略标记。并不具备其它的样式属性定义。我们想要实现溢出时产生省略号的效果。还必须定义：强制文本在一行内显示（white-space:nowrap）及溢出内容为隐藏（overflow:hidden）。只有这样才能实现溢出文本显示省略号的效果。Via. 那么，如果我们要给p标签定义text-overflow:ellipsis就可以这么写： p &#123; white-space: nowrap; width: 100%; /* IE6 需要定义宽度 */ overflow: hidden; &#160; -o-text-overflow: ellipsis; /* Opera &#8230; <a href="http://leeiio.me/text-overflow-ellipsis/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://imgs.leeiio.me/blogimgs/2010/07/20100718-ellipsis.jpg" alt="溢出文本显示省略号,关于text-overflow:ellipsis的那些事" /><br />
这个标题其实已经是一个老生常谈的问题了。很多时候，比如网站最基本的文章列表，标题会很长，而显示列表的区域宽度却没有这么宽，这时候最正常的做法就是让超出宽度的部分文字用省略号(&#8230;)来表示。通常做法是网站后台程序截取一定的字符然后输出到前台显示或者前台用javascript截取一定的字符，但是通过控制字数来截取的话还是存在一个大问题的，因为中文和英文的字符宽度问题，这个字数不好控制，而且通用性较差。那么有没有更好的方法呢，比如直接用CSS来解决的，当然是有的。<br />
<span id="more-2055"></span><br />
text-overflow是一个比较特殊的属性，<a rel="nofollow" href="http://www.w3.org/TR/2003/CR-css3-text-20030514/#text-overflow-mode">W3C早前的文档中</a>（<a rel="nofollow" href="http://www.w3.org/TR/css3-text/">目前的文档</a>中没有包含text-overflow属性，FML!）对其的定义是:</p>
<blockquote><p>Name:	text-overflow-mode<br />
Value:	clip | ellipsis | ellipsis-word</p></blockquote>
<p>clip : 　不显示省略标记（&#8230;），而是简单的裁切<br />
ellipsis : 　当对象内文本溢出时显示省略标记（&#8230;），省略标记插入的位置是最后一个字符。<br />
ellipsis-word : 　当对象内文本溢出时显示省略标记（&#8230;），省略标记插入的位置是最后一个词（word）。</p>
<p>至于为什么一开始我说text-overflow是一个比较特殊的样式呢？因为我们可以用它代替我们通常所用的标题截取函数，而且这样做对搜索引擎更加友好，如：标题文件有50个汉字，而我们的列表可能只有300px的宽度。如果用标题截取函数，则标题不是完整的，如果我们用CSS样式text-overflow:ellipsis，输出的标题是完整的，只是受容器大小的局限不显示出来罢了（表现上是超出部分显示省略标记&#8230;）。</p>
<p>text-overflow: ellipsis属性仅是注解，当文本溢出时是否显示省略标记。并不具备其它的样式属性定义。我们想要实现溢出时产生省略号的效果。还必须定义：强制文本在一行内显示（white-space:nowrap）及溢出内容为隐藏（overflow:hidden）。只有这样才能实现溢出文本显示省略号的效果。<a rel="nofollow" href="http://www.52css.com/article.asp?id=602">Via.</a></p>
<p>那么，如果我们要给p标签定义text-overflow:ellipsis就可以这么写：</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">p <span style="color: #00AA00;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">white-space</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">nowrap</span><span style="color: #00AA00;">;</span>
      <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>                  <span style="color: #808080; font-style: italic;">/* IE6 需要定义宽度 */</span>
      <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>             
&nbsp;
      -o-text-<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> ellipsis<span style="color: #00AA00;">;</span>    <span style="color: #808080; font-style: italic;">/* Opera */</span>
      text-<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span>    ellipsis<span style="color: #00AA00;">;</span>    <span style="color: #808080; font-style: italic;">/* IE, Safari (WebKit) */</span>
   <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><em>使用样式前：</em></p>
<p class="example">我是一段测试文字，请分别用IE，Safari，chrome，opera浏览器查看我哦！</p>
<p><em>使用样式后：</em></p>
<p class="example ellipsis-1">我是一段加长过的测试文字，请分别用IE，Safari，chrome，opera浏览器查看我哦！哈哈哈，看到省略号了么？</p>
<p><strong>浏览器兼容状况</strong></p>
<style type="text/css">
table.standard-table {
border: 1px solid #BBB;
border-collapse: collapse;
}
table.standard-table td.header, table.standard-table th {
background: #EEE;
border: 1px solid #BBB;
font-weight: bold;
padding: 0px 5px;
text-align: left;
}
table.standard-table td {
border: 1px solid #CCC;
padding: 5px;
text-align: left;
vertical-align: top;
}
.example{background:#ddd;border:2px solid #bbb;width: 600px;display:block}
.ellipsis-1{
      white-space: nowrap;
      overflow: hidden;    
      -o-text-overflow: ellipsis;    /* Opera */
      text-overflow:    ellipsis;    /* IE, Safari (WebKit) */
}
.xul{
-moz-binding: url('../ellipsis.xml#ellipsis');
}
</style>
<table class="standard-table">
<tbody>
<tr>
<th>Browser</th>
<th>Lowest Version</th>
<th>Support of</th>
</tr>
<tr>
<td>Internet Explorer</td>
<td><strong>6.0</strong></td>
<td>text-overflow</td>
</tr>
<tr>
<td>Firefox (Gecko)</td>
<td>&#8212;</td>
<td>&#8212;</td>
</tr>
<tr>
<td>Opera</td>
<td><strong>9.0</strong></td>
<td>-o-text-overflow</td>
</tr>
<tr>
<td>Safari (WebKit)</td>
<td><strong>1.3</strong> (312.3)</td>
<td>text-overflow</td>
</tr>
</tbody>
</table>
<p><em>OH,FML!Firefox不支持这个属性！</em>这回，Firefox你也太另类了吧！还有别的办法么，当然有，方法还挺多的。<br />
比如Mozilla developer center推荐的<a href="https://developer.mozilla.org/En/CSS/-moz-binding" rel="nofollow">-moz-binding</a> CSS属性。Mozilla developer center给出的理由是text-overflow没有W3C的规范&#8230;但是因为Firefox支持XUL，一种XML的用户界面语言。并且Firefox还支持XBL，一种XML绑定语言，这样我们就可以使用Mozilla developer center推荐的<a href="https://developer.mozilla.org/En/CSS/-moz-binding" rel="nofollow">-moz-binding</a> CSS属性来绑定XUL里的ellipsis属性了。</p>
<h4 class="part-title">1.XUL方式</h4>
<p>首先，我们创建XUL，它应该被保存为ellipsis.xml：</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>  
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bindings</span>   </span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.mozilla.org/xbl&quot;</span>  </span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:xbl</span>=<span style="color: #ff0000;">&quot;http://www.mozilla.org/xbl&quot;</span>  </span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:xul</span>=<span style="color: #ff0000;">&quot;http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul&quot;</span>  </span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;binding</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;ellipsis&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;content<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xul:window<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xul:description</span> <span style="color: #000066;">crop</span>=<span style="color: #ff0000;">&quot;end&quot;</span> <span style="color: #000066;">xbl:inherits</span>=<span style="color: #ff0000;">&quot;value=xbl:text&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;children</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/xul:description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xul:window<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/content<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/binding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bindings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>然后我们需要把这个xml文件放到一个目录，原来的css需要加一条，变成这样</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">p <span style="color: #00AA00;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">white-space</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">nowrap</span><span style="color: #00AA00;">;</span>
      <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>                  <span style="color: #808080; font-style: italic;">/* IE6 需要定义宽度 */</span>
      <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>             
&nbsp;
      -o-text-<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> ellipsis<span style="color: #00AA00;">;</span>    <span style="color: #808080; font-style: italic;">/* Opera */</span>
      text-<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span>    ellipsis<span style="color: #00AA00;">;</span>    <span style="color: #808080; font-style: italic;">/* IE, Safari (WebKit) */</span>
      -moz-binding<span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'ellipsis.xml#ellipsis'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>    <span style="color: #808080; font-style: italic;">/* Firefox */</span>
   <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>虽然Firefox通过XUL的方式实现了ellipsis，但是还是需要注意以下这些问题：<br />
1.经过XUL处理过的文本你将不能被选中，按理说-moz-user-select: text; 属性将允许文本被选中，但是我没有试验成功。<br />
2.如果你给父元素绑定了XUL，那么子元素的内容将变得不可见。例如：</p>
<p class="example xul ellipsis-1">It is a long<em>haha</em> long long long long text!</p>
<p>如果你只是给p节点绑定了XUL，那么在Firefox下你将看不到<em>haha</em>这个内容。<br />
它的源代码实际上是：</p>

<div class="wp_syntax"><div class="code"><pre class="div" style="font-family:monospace;"><span style="color: #44aa44;">&lt;</span>p<span style="color: #44aa44;">&gt;</span>It is a long<span style="color: #44aa44;">&lt;</span>em<span style="color: #44aa44;">&gt;</span> haha<span style="color: #44aa44;">&lt;/</span>em<span style="color: #44aa44;">&gt;</span> long long long long text<span style="color: #44aa44;">!&lt;/</span>p<span style="color: #44aa44;">&gt;</span></pre></div></div>

<p>参考资料:</p>
<p>http://www.w3.org/TR/2003/CR-css3-text-20030514/</p>
<p>http://www.quirksmode.org/css/contents.html</p>
<p>https://bugzilla.mozilla.org/show_bug.cgi?id=312156</p>
<p>https://developer.mozilla.org/En/XUL</p>
<p>https://developer.mozilla.org/En/XUL/Description</p>
<p>http://www.rikkertkoppes.com/thoughts/2008/6/</p>
<p>http://www.w3.org/TR/xbl/</p>
<p>http://www.w3.org/TR/css3-text/</p>
<h4 class="part-title">2.Javascript方式</h4>
<p>既然XUL无法完美解决Firefox下文字溢出显示&#8230;，那么我们就求助javascript吧，当然，并不是古老的截取一定数目的字符来实现。<br />
这里以jQuery为例，代码如下：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$.<span style="color: #660066;">fn</span>.<span style="color: #660066;">ellipsis</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>enableUpdating<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #339933;">=</span> document.<span style="color: #660066;">documentElement</span>.<span style="color: #660066;">style</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'textOverflow'</span> <span style="color: #000066; font-weight: bold;">in</span> s <span style="color: #339933;">||</span> <span style="color: #3366CC;">'OTextOverflow'</span> <span style="color: #000066; font-weight: bold;">in</span> s<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #003366; font-weight: bold;">var</span> el <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>el.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;overflow&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;hidden&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #003366; font-weight: bold;">var</span> originalText <span style="color: #339933;">=</span> el.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #003366; font-weight: bold;">var</span> w <span style="color: #339933;">=</span> el.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #003366; font-weight: bold;">var</span> t <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">cloneNode</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                        <span style="color: #3366CC;">'position'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'absolute'</span><span style="color: #339933;">,</span>
                        <span style="color: #3366CC;">'width'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'auto'</span><span style="color: #339933;">,</span>
                        <span style="color: #3366CC;">'overflow'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'visible'</span><span style="color: #339933;">,</span>
                        <span style="color: #3366CC;">'max-width'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'inherit'</span>
                    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					el.<span style="color: #660066;">after</span><span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #003366; font-weight: bold;">var</span> text <span style="color: #339933;">=</span> originalText<span style="color: #339933;">;</span>
					<span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>text.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">&amp;&amp;</span> t.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> el.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
						text <span style="color: #339933;">=</span> text.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> text.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						t.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>text <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
					el.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>t.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					t.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>enableUpdating <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
						<span style="color: #003366; font-weight: bold;">var</span> oldW <span style="color: #339933;">=</span> el.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						setInterval<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
							<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>el.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> oldW<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
								oldW <span style="color: #339933;">=</span> el.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
								el.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>originalText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
								el.<span style="color: #660066;">ellipsis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
							<span style="color: #009900;">&#125;</span>
						<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>这段js的原理很简单，就是通过不断的比较宽度值，然后逐个缩短字符宽度，当最后宽度合适的时候，停止循环，就实现了文字溢出显示&#8230;的效果。<br />
这段js还需要一段css来配合。</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">overflow</span> <span style="color: #00AA00;">&#123;</span>
	text-<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> ellipsis<span style="color: #00AA00;">;</span>
	-o-text-<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> ellipsis<span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">white-space</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">nowrap</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>js里有个判断就是当样式里出现text-overflow或者-o-text-overflow的时候，便不会执行这段js。因为支持这两个属性的浏览器可以自己实现ellipsis效果。</p>
<p>这两种方法都可以实现Firefox下ellipsis的效果，如何取舍使用，具体还得根据你要运用到的项目的具体情况来具体分析，XUL实现的方法的不足之处在以上已经很详尽地列举了，如果你可以避免或者说这些无关你项目的大问题，那么XUL不失一个好方法。</p>
<p>至于其他的一些方法你可能在网上也有看到，比如用:after伪类来实现等，个人不推荐，所以我这里也不细说了，如果你有更好的方法，也希望能与我分享，谢谢观看！</p>
<p>2011.09.28更新：Firefox7已经支持text-overflow:ellipsis了，enjoy it!</p>
]]></content:encoded>
			<wfw:commentRss>http://leeiio.me/text-overflow-ellipsis/feed/</wfw:commentRss>
		<slash:comments>61</slash:comments>
		</item>
		<item>
		<title>全世界最短的 JavaScript 判定 IE 浏览器！这个可以短！</title>
		<link>http://leeiio.me/ie_detection_in_5_bytes/</link>
		<comments>http://leeiio.me/ie_detection_in_5_bytes/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 17:50:17 +0000</pubDate>
		<dc:creator>Leeiio</dc:creator>
				<category><![CDATA[JS/Ajax/AS/Flex]]></category>
		<category><![CDATA[IE判定]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://leeiio.me/?p=1818</guid>
		<description><![CDATA[有些东西你想让它长它并不一定就会如愿，但是有一些东西你想让它短也并不一定就会如愿，这两者都要看你的本事。对于我等IT民工来说，自然是代码写得越短越好。 你知道，IE是个脑残儿浏览器，不管是什么版本，纵使版本号越来越大，可总是让人觉得这玩意儿跟标准老是扯不上暧昧。可是，你知道，只要世上还有 windows 操作系统，IE就永生不灭，阿门。对于代码工作者来说，自然是苦不堪言，为了考虑IE的兼容问题，不管是写 CSS 还是 JS，往往都要对 IE 特别对待，这就少不了做些判断。本文不讨论如何区分 IE 的样式，仅是 JS 判定 IE 浏览器。 这个目前世界上最短的 Javascript 判定 IE 浏览器的方法来自一个俄人,又是俄人！它已经在各版本的 IE 以及目前其他流行的浏览器上经过测试，基于 IE 的 Bug，微软虽然已经意识到，但是从来没有纠正过。 &#60;script type='text/javascript'&#62; var ie = !-&#91;1,&#93;; alert&#40;ie&#41;; &#60;/script&#62; 以上代码运行结果：IE 下返回true，其他标准浏览器返回false。!-[1,]，仅仅只有 6 bytes！ 不过如果反过来判断，标准浏览器返回 true 而 &#8230; <a href="http://leeiio.me/ie_detection_in_5_bytes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://imgs.leeiio.me/blogimgs/2010/01/20100131_theShortestDefinitionOfIE.jpg" alt="全世界最短的JavaScript判定IE浏览器！" /><br />
有些东西你想让它长它并不一定就会如愿，但是有一些东西你想让它短也并不一定就会如愿，这两者都要看你的本事。对于我等IT民工来说，自然是代码写得越短越好。</p>
<p>你知道，IE是个脑残儿浏览器，不管是什么版本，纵使版本号越来越大，可总是让人觉得这玩意儿跟标准老是扯不上暧昧。可是，你知道，只要世上还有 windows 操作系统，IE就永生不灭，阿门。对于代码工作者来说，自然是苦不堪言，为了考虑IE的兼容问题，不管是写 CSS 还是 JS，往往都要对 IE 特别对待，这就少不了做些判断。本文不讨论如何区分 IE 的样式，仅是 JS 判定 IE 浏览器。<br />
<span id="more-1818"></span><br />
这个目前世界上最短的 Javascript 判定 IE 浏览器的方法来自一个<a rel="nofollow" href="http://studioad.ru/blog/ie_detection_in_5_bytes/2010-01-08-103">俄人</a>,又是俄人！它已经在各版本的 IE 以及目前其他流行的浏览器上经过测试，基于 IE 的 Bug，微软虽然已经意识到，但是从来没有纠正过。</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">'text/javascript'</span><span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">var</span> ie <span style="color: #339933;">=</span> <span style="color: #339933;">!-</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>ie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>以上代码运行结果：IE 下返回true，其他标准浏览器返回false。!-[1,]，仅仅只有 6 bytes！</p>
<p>不过如果反过来判断，标准浏览器返回 true 而 IE 返回 false的话，则可以再缩短一个byte。</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">'text/javascript'</span><span style="color: #339933;">&gt;</span>
notIe <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #006600; font-style: italic;">// 标准浏览器代码</span>
<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
<span style="color: #006600; font-style: italic;">// IE Only的代码</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p><strong>看完了这些，你们是不是很好奇这些是怎么运行的？请继续看下文。</strong></p>
<p>这个 Bug 产生的原因是 IE 会添加一个空数组元素到数组元素的总数里。</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #009900;">&#93;</span>. <span style="color: #660066;">Length</span></pre></div></div>

<p>标准浏览器会返回 1 (基于标准的 ECMAscript ，在数组最后的逗号&#8221;,&#8221;会被忽略，这是为了方便在一列里显示以及自动生成等)，但是 IE 会返回 2。当你打印这个数组的时候 IE 将会返回 &#8220;1, &#8220;，也就是两个元素，而其他标准浏览器将会返回 &#8220;1&#8243;。</p>
<p>这很容易验证，比如在 IE 和 FF中运行以下代码：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">'text/javascript'</span><span style="color: #339933;">&gt;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">','</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//这是8个字符判定IE</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>[1,]实际上浏览器的操作是toString()转换成字符串的操作，-[1,]是将字符串强制转换为数字。而 IE 将会返回 NaN，但是遗憾的是 NaN 并不是一个数字，因为[1,]转换成字符串后的&#8221;1,&#8221;里面带有逗号。而其他标准浏览器会返回 -1，这是一个非 0 的数字。</p>
<p>你知道，NaN 转换成 Boolean 型将返回 false，所以-[1,]在 IE 下将返回 false。而任何非 0 的数字转换成 Boolean 型(例如-1)，在 标准浏览器下都将返回 true。所以我们得到了一个判定结果，!-[1,]在 IE 下返回true，而在其他标准浏览器下返回 false。也就达到了区分判定 IE 浏览器的目的。</p>
<p>当然，如前文所说，这个 Bug 其实微软很早就已经知道，但是却一直没有去修复它，所以在未来的 > IE8 的 IE 浏览器也就不确定是否依旧可以，不过基本上这么多代的 IE 都没有修复，未来的 IE 也不太会去修复的样子。</p>
<p><strong>以下是其他的一些区分判定 IE 浏览器的代码，也可以参考下:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">'text/javascript'</span><span style="color: #339933;">&gt;</span>
<span style="color: #006600; font-style: italic;">// Option from Dean Edwards:</span>
<span style="color: #003366; font-weight: bold;">var</span> ie <span style="color: #339933;">=</span> <span style="color: #006600; font-style: italic;">/*@cc_on!@*/</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Use the commented line:</span>
<span style="color: #003366; font-weight: bold;">var</span> ie<span style="color: #006600; font-style: italic;">//@cc_on=1;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Variation (shorter variable):</span>
<span style="color: #003366; font-weight: bold;">var</span> ie <span style="color: #339933;">=</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\v</span>'</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'v'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009966; font-style: italic;">/ /</span> Option to Gareth Hayes <span style="color: #009900;">&#40;</span>former record<span style="color: #339933;">-</span>holder<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
<span style="color: #003366; font-weight: bold;">var</span> ie <span style="color: #339933;">=</span> <span style="color: #339933;">!+</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\v</span>1&quot;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span> script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>参考文章：<br />
<a href="http://studioad.ru/blog/ie_detection_in_5_bytes/2010-01-08-103" rel="nofollow">Самое короткое определение IE</a><br />
<a href="http://webreflection.blogspot.com/2009/01/32-bytes-to-know-if-your-browser-is-ie.html" rel="nofollow">32 bytes, ehr &#8230; 9, ehr &#8230; 7!!! to know if your browser is IE</a></p>
]]></content:encoded>
			<wfw:commentRss>http://leeiio.me/ie_detection_in_5_bytes/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
		<item>
		<title>jQuery 1.4 发布，一些更新和改进，性能大幅度提升！</title>
		<link>http://leeiio.me/jquery-1_4-released/</link>
		<comments>http://leeiio.me/jquery-1_4-released/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 04:02:38 +0000</pubDate>
		<dc:creator>Leeiio</dc:creator>
				<category><![CDATA[JS/Ajax/AS/Flex]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://leeiio.me/?p=1797</guid>
		<description><![CDATA[jQuery 1.4 发布也有好几天了，api 有所增加也有所更新，总体来说，性能也有大幅度的提升。jQuery 是我接触的第一个 javascript 类库，快速上手是他的特色之一。另外更重要的一点或者说之所以容易上手并且让用户产生渐进的学习兴趣是因为他的API 设计。如射雕文中所说，“从纯功能上说，jQuery 并没有特别出色的地方。但从可记忆性和灵活性上讲，我觉得 jQuery 的设计都更人性化。jQuery 的 API 还符合学习上的渐进式思维：先学会最简单的情况el.css(prop), 再了解到还可以有两个参数，接着发现参数可以是 map, 更进一步发现 val 还可以是一个函数。func 参数甚至能带给学习者一种惊喜：居然还可以这样用！jQuery 把一种渐进和愉悦带进了学习和使用的过程中，实在漂亮！” 2010年1月14号, 恰逢jQuery四周年纪念日, jQuery的团队早早便开始了1.4版发布的准备工作, 并以每天一则公告的方式进行庆祝, 活动将持续14天。发布的首日, jQuery的团队首先列出了1.4版中的重大改进。这篇文档是这几天以来内容比较充实的一篇文档。所以我转载了coolnalu的翻译, 方便大家了解都有哪些更新和改进以及性能的提升。 翻译正文如下： 为了庆祝jQuery的四周岁生日, jQuery的团队荣幸的发布了jQuery Javascript库的最新主要版本! 这个版本包含了大量的编程，测试，和记录文档的工作，我们为此感到很骄傲。 我要以个人的名义感谢 Brandon Aaron, Ben Alman, Louis-Rémi Babe, &#8230; <a href="http://leeiio.me/jquery-1_4-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://imgs.leeiio.me/blogimgs/2010/01/20100121_jquery1_4.png" alt="jQuery 1.4 released on january 14th 2010" /><br />
jQuery 1.4 发布也有好几天了，api 有所增加也有所更新，总体来说，性能也有大幅度的提升。jQuery 是我接触的第一个 javascript 类库，快速上手是他的特色之一。另外更重要的一点或者说之所以容易上手并且让用户产生渐进的学习兴趣是因为他的API 设计。如<a href="http://lifesinger.org/blog/2010/01/the-beauty-of-jquery-api/" rel="nofollow" class="broken_link">射雕</a>文中所说，“从纯功能上说，jQuery 并没有特别出色的地方。但从可记忆性和灵活性上讲，我觉得 jQuery 的设计都更人性化。jQuery 的 API 还符合学习上的渐进式思维：先学会最简单的情况el.css(prop), 再了解到还可以有两个参数，接着发现参数可以是 map, 更进一步发现 val 还可以是一个函数。func 参数甚至能带给学习者一种惊喜：居然还可以这样用！jQuery 把一种渐进和愉悦带进了学习和使用的过程中，实在漂亮！”<br />
<span id="more-1797"></span><br />
2010年1月14号, 恰逢jQuery四周年纪念日, jQuery的团队早早便开始了1.4版发布的准备工作, 并以每天一则公告的方式进行庆祝, 活动将持续14天。发布的首日, jQuery的团队首先列出了1.4版中的重大改进。这篇文档是这几天以来内容比较充实的一篇文档。所以我转载了<a href="http://www.uxd2.com/2010/01/翻译-jquery1-4官方文档/" rel="nofollow" class="broken_link">coolnalu</a>的翻译, 方便大家了解都有哪些更新和改进以及性能的提升。</p>
<p><em>翻译正文如下：</em></p>
<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>
<h2 class="part-title">下载(Downloading)</h2>
<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> (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>
<h1>(功能) Features</h1>
<p>下面的内容概括了jQuery1.4里加入的变更和功能。另外所有的变更都已经在<a href="http://api.jquery.com/category/version/1.4/">jQuery 1.4 的文档</a>里记录了。</p>
<h2 class="part-title">热门方法经过了性能上的大”检修”</h2>
<p>不少比较热门的和常用的jQuery方法在1.4里被重写了。(译注:重写了方法的内部，外部调用没有大幅度改变) 我们分析源码的时候发现我们能够获得大幅的性能提升，通过把jQuery和自己比较: 查看内部函数被调用了多少次，然后努力<a href="http://ejohn.org/blog/function-call-profiling/">降低源码的复杂度</a>(译注:计算机算法中的Complexity)</p>
<p><a rel="lightbox[69]" href="http://imgs.leeiio.me/blogimgs/2010/01/20100121_01-funccall.jpg"><img width="500" height="375" alt="常用jQuery方法调用频率" src="http://imgs.leeiio.me/blogimgs/2010/01/20100121_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>
<h2 class="part-title">更易用的设置函数 (Easy Setter Functions)</h2>
<p>算来已经有一阵了，你们已经可以给<code class="code-inline"><a href="http://api.jquery.com/attr">.attr()</a></code>传递一个函数，然后这个函数的结果会被用来赋给相应的HTML属性(attribute)上。这个功能现在被移植到所有的设置函数了: <code class="code-inline"><a href="http://api.jquery.com/css">.css()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/attr">.attr()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/val">.val()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/html">.html()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/text">.text()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/append">.append()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/prepend">.prepend()</a></code>,  <code class="code-inline"><a href="http://api.jquery.com/before">.before()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/after">.after()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/replaceWith">.replaceWith()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/wrap">.wrap()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/wrapInner">.wrapInner()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/offset">.offset()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/addClass">.addClass()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/removeClass">.removeClass()</a></code>, 以及 <code class="code-inline"><a href="http://api.jquery.com/toggleClass">.toggleClass()</a></code>.</p>
<p>另外, 对于下面几个方法，当前的值会被作为第2个变量传递给这个函数。<code class="code-inline"><a href="http://api.jquery.com/css">.css()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/attr">.attr()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/val">.val()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/html">.html()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/text">.text()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/append">.append()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/prepend">.prepend()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/offset">.offset()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/addClass">.addClass()</a></code>, <code class="code-inline"><a href="http://api.jquery.com/removeClass">.removeClass()</a></code>, 以及 <code class="code-inline"><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>
<h2 class="part-title">Ajax</h2>
<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 class="code-inline">{foo: ["bar", "baz"]}</code> 会被序列化为 “foo[]=bar&amp;foo[]=baz”.</p>
<p>在jQuery 1.3版里, <code class="code-inline">{foo: ["bar", "baz"]}</code> 曾被序列化为 “foo=bar&amp;foo=baz”. 但是，这样做没用办法将只含有一个元素的阵列编码。如果你需要旧的序列化方式，你可以设置传统Ajax设置来进行切换。(使用<code class="code-inline">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 class="code-inline">eval</code>对引入的JSON解析。1.4版则会使用本地的JSON解析器，前提是如果有本地的解析器可用。它也会对引入的JSON进行校验。所以在<a href="http://api.jquery.com/jQuery.getJSON">jQuery.getJSON</a>方法里，或当一个Ajax请求的dataType是”json”的时候，jQuery会拒绝不合标准的JSON(例如<code class="code-inline">{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 class="code-inline"><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 class="code-inline">$.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>
<h2 class="part-title">元素属性 (Attributes)</h2>
<p><strong><code class="code-inline">.css()</code>和<code class="code-inline">.attr()</code> 的性能被优化了。</strong></p>
<p><a rel="lightbox[69]" href="http://imgs.leeiio.me/blogimgs/2010/01/20100121_02-perform-cssatrr.jpg"><img width="500" height="375" alt=".css().attr()的性能提高" src="http://imgs.leeiio.me/blogimgs/2010/01/20100121_02-perform-cssatrr.jpg" title=".css().attr()的性能提高" class="alignnone size-full wp-image-75"></a></p>
<p><strong><code class="code-inline">.attr()</code>方法多了一个设置函数作为参数</strong> (<a href="http://api.jquery.com/attr/">.attr() 文档</a>)</p>
<p>你不但可以将一个函数用在<code class="code-inline">.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>
<h2 class="part-title">核心 (Core)</h2>
<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 class="code-inline">$("&lt;a&gt;link&lt;/a&gt;", {css:{background:"#ccc"}});</code>相当于<code class="code-inline">$("&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 class="code-inline">.get()</code>和<code class="code-inline">.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 class="code-inline">.first()</code>和<code class="code-inline">.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 class="code-inline">.get()</code>不一样的是，<code class="code-inline">.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 class="code-inline">document</code>的jQuery集合。这个可以用来创建一个空集，然后动态加入一些元素。注: <code class="code-inline">jQuery().ready()</code>方式在1.4中依然有效，但是被指示陈旧了。请使用<code class="code-inline">jQuery(document).ready()</code>或者<code class="code-inline">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 class="code-inline">jQuery("&lt;div&gt;&lt;/div&gt;")</code>的性能。注意，如果你指定了属性，将会使用浏览器本身的语法分析(通过设置innerHTML)。</p>
<h2 class="part-title">样式 (CSS)</h2>
<p><strong>.css()方法在性能是以前的2倍。</strong></p>
<p><a rel="lightbox[69]" href="http://imgs.leeiio.me/blogimgs/2010/01/20100121_03-perform-css.jpg"><img width="500" height="375" alt=".css()的性能提高 " src="http://imgs.leeiio.me/blogimgs/2010/01/20100121_03-perform-css.jpg" title=".css()的性能提高 " class="alignnone size-full wp-image-76"></a></p>
<p><strong><code class="code-inline">.addClass()</code>, <code class="code-inline">.removeClass()</code>, 和 <code class="code-inline">.hasClass()</code>这几个方法在性能上是以前的3倍</strong></p>
<p><a rel="lightbox[69]" href="http://imgs.leeiio.me/blogimgs/2010/01/20100121_04-perform-addClass.jpg"><img width="500" height="375" alt="addClass, removeClass, 和 hasClass的性能提高" src="http://imgs.leeiio.me/blogimgs/2010/01/20100121_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>
<h2 class="part-title">数据</h2>
<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>
<h2 class="part-title">效果 (Effects)</h2>
<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>
<h2 class="part-title">事件 (Events)</h2>
<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 class="code-inline">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 class="code-inline">change</code>和<code class="code-inline">submit</code>事件可以在各种浏览器上稳定工作了。我们覆盖了IE里的<code class="code-inline">change</code>和<code class="code-inline">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 class="code-inline">focusin</code>和<code class="code-inline">focusout</code>在一般情况下等同于<code class="code-inline">focus</code>和<code class="code-inline">blur</code>, 但是多了向父元素传递的作用。如果你自己编写你的事件代理模式(TODO), 这个功能将对你有很大帮助。请注意对<code class="code-inline">focus</code>和<code class="code-inline">blur</code>使用<code class="code-inline">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 class="code-inline">.bind()</code>绑定的事件都可以成为即时事件。</p>
<p>在<code class="code-inline">live()</code>所支持的事件里，我们对能够支持下面这几个额外的事件感到尤其骄傲。通过<code class="code-inline">.live()</code>里的事件代理, 1.4版实现了对<code class="code-inline">change</code>, <code class="code-inline">submit</code>, <code class="code-inline">focusin</code>, <code class="code-inline">focusout</code>, <code class="code-inline">mouseenter</code>, 以及<code class="code-inline">mouseleave</code>事件的跨浏览器支持。</p>
<p>注: 如果你需要即时的<code class="code-inline">focus</code>事件，你应该用<code class="code-inline">focusin</code>和<code class="code-inline">focusout</code>, 而不要用<code class="code-inline">focus</code>和<code class="code-inline">blur</code>, 因为就像前面提到的, <code class="code-inline">focus</code>和<code class="code-inline">blur</code>不向上传递。</p>
<p>还有, <code class="code-inline">live()</code>也接受数据对象作为参数了, 同<code class="code-inline">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 class="code-inline">body</code>元素</strong> (<a href="http://github.com/jquery/jquery/commit/262fcf7b7b919da1564509f621cf7480a5d5572b">Commit</a>)</p>
<p>jQuery现在会检查<code class="code-inline">body</code>是不是存在，如果不存在，会对<code class="code-inline">body</code>进行轮流探询。</p>
<p><strong>在不需要手动处理内存溢出的非IE浏览器中, 卸载的速度提高了。</strong> (<a href="http://github.com/jquery/jquery/commit/f3474c00cd6d9e5fd61b6ef1562003e9986ad67d">Commit</a>)</p>
<h2 class="part-title">DOM操作 (Manipulation)</h2>
<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://imgs.leeiio.me/blogimgs/2010/01/20100121_05-perform-dom.jpg"><img width="500" height="375" alt="DOM嵌入的性能提高" src="http://imgs.leeiio.me/blogimgs/2010/01/20100121_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://imgs.leeiio.me/blogimgs/2010/01/20100121_06-perform-html.jpg"><img width="500" height="375" alt=".html()的性能提高" src="http://imgs.leeiio.me/blogimgs/2010/01/20100121_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://imgs.leeiio.me/blogimgs/2010/01/20100121_07-perform-remove.jpg"><img width="500" height="375" alt=".remove() 和 .empty()的性能提高" src="http://imgs.leeiio.me/blogimgs/2010/01/20100121_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 class="code-inline">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 class="code-inline">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 class="code-inline">jQuery("&lt;div&gt;")</code>和<code class="code-inline">.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 class="code-inline">before</code>, <code class="code-inline">after</code>, 和<code class="code-inline">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 class="code-inline">.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 class="code-inline">.clone(true)</code>虽然也是深度复制, 但是没有复制关联的数据。1.4版里，它则会复制数据, 同时还包括所有的事件。这点上和<code class="code-inline">jQuery.extend</code>在语义想同的, 所以普通对象和阵列会被复制, 但是自定义的对象则不会。</p>
<h2 class="part-title">位移 (Offset)</h2>
<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 class="code-inline">offset</code>也可以接受一个函数作为第二个参数。</p>
<h2 class="part-title">队列 (Queueing)</h2>
<p>队列经历了一次大修, 使用队列会比使用默认的<code class="code-inline">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 class="code-inline">.delay()</code>方法会根据参数滞后若干毫秒执行队列里剩下的对象。默认的它会使用”fx”队列。但你可以选择性的通过<code class="code-inline">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 class="code-inline">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 class="code-inline">.clearQueue()</code>方法将会清空默认的”fx”队列。</p>
<h2 class="part-title">选择符 (Selectors)</h2>
<p><strong>“#id p”效率更高</strong> (<a href="http://github.com/jeresig/sizzle/commit/c5c18ae5f17f11b39b7f261633e4bfc5ef3e99d7">commit</a>)</p>
<p>所有以ID开头的选择符都得到了优化, 能够在瞬间得到返回值。所有以ID为开头的选择符速度将一直快于其他选择符。</p>
<h2 class="part-title">页面遍访 (Traversing)</h2>
<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 class="code-inline">.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 class="code-inline">: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 class="code-inline">.nextAll()</code>, <code class="code-inline">.prevAll()</code>, 和<code class="code-inline">.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 class="code-inline">.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 class="code-inline">closest</code>方法的第2个参数设置一个<code class="code-inline">DOMElement</code>环境。给<code class="code-inline">closest</code>设置一个环境一般能够提高这个方法的运行速度。这个优化也适用<code class="code-inline">live()</code>, 因为这个方法内部调用了<code class="code-inline">closest()</code>。</p>
<h2 class="part-title">常用工具 (Utilities)</h2>
<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 class="code-inline">true</code>。<code class="code-inline">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 class="code-inline">jQuery.isPlainObject()</code>返回<code class="code-inline">true</code>; 如果对象是其他类别的对象(译注:如new Object())或者是基本类型, 则返回<code class="code-inline">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 class="code-inline">jQuery.contains()</code>返回<code class="code-inline">true</code>。反之返回<code class="code-inline">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 class="code-inline">jQuery.unique()</code>方法返回结果里的元素是按照他们在页面里的顺序排序的。由于在创建jQuery集合的时候jQuery使用<code class="code-inline">jQuery.unique()</code>方法, 所以jQuery方法返回的集合也是按照他们在页面里的顺序排列的。</p>
<h2 class="part-title">其他 (Miscellaneous)</h2>
<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" class="broken_link">commit</a>)</p>
<p>例如, 你可以通过<code class="code-inline">jQuery.browser.webkit</code>探测引擎是否是Webkit。</p>
<p><strong>改进了对<code class="code-inline">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 class="code-inline">arguments.callee</code>的代码都移除了。</p>
<p><strong>用Closure Compiler替换了YUI Min</strong> (<a href="http://github.com/jquery/jquery/commit/3fd62eae9df3159fc238a515bb748140a942313d">commit</a>)</p>
<h2 class="part-title">内部重组 (Internal Reorganization)</h2>
<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>
<h2 class="part-title">测试 (Testing)</h2>
<p>jQuery 1.4版发布过程中我们<a href="http://dev.jquery.com/report/34" class="broken_link">修复了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://imgs.leeiio.me/blogimgs/2010/01/20100121_08-test.jpg"><img width="500" height="277" alt="jQuery 1.4 测试结果" src="http://imgs.leeiio.me/blogimgs/2010/01/20100121_08-test.jpg" title="jQuery 1.4 测试结果" class="alignnone size-full wp-image-81"></a></p>
<h1><a name="backwards"></a></h1>
<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 class="code-inline">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 class="code-inline">option</code>或一个<code class="code-inline">checkbox</code>的值不再有歧义(将总是根据<code class="code-inline">value</code>属性选择, 而不是根据<code class="code-inline">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 class="code-inline">eval()</code>来对内容估值。</li>
<li>参数序列化默认会按照PHP/Rails的风格进行。你可以通过<code class="code-inline">jQuery.ajaxSettings.traditional = true;</code>来切换到旧的序列化方式。你也可以针对个别请求进行切换, 在调用<a href="http://api.jquery.com/jQuery.ajax">jQuery.ajax</a>的时候递入<code class="code-inline">{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>
<h1>原始数据和测试页面</h1>
<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>
<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>
<p>原文地址: <a href="http://jquery14.com/day-01" rel="nofollow">http://jquery14.com/day-01</a><br />
译文地址: <a href="http://www.uxd2.com/2010/01/翻译-jquery1-4官方文档/" rel="nofollow" class="broken_link">UXD2</a><br />
原译者署名:coolnalu</p>
]]></content:encoded>
			<wfw:commentRss>http://leeiio.me/jquery-1_4-released/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Sweet Titles for jQuery (美妙的标题提示) !</title>
		<link>http://leeiio.me/sweet-titles-for-jquery/</link>
		<comments>http://leeiio.me/sweet-titles-for-jquery/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 07:27:21 +0000</pubDate>
		<dc:creator>Leeiio</dc:creator>
				<category><![CDATA[JS/Ajax/AS/Flex]]></category>
		<category><![CDATA[用户体验]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Sweet Titles]]></category>

		<guid isPermaLink="false">http://leeiio.me/?p=1478</guid>
		<description><![CDATA[<img src="http://imgs.leeiio.me/blogimgs/2009/07/20090727_sweettitles-jquery.gif" alt="Sweet Titles for jQuery (美妙的标题提示)" />
Sweet Titles 这个名字源自于一个改变 Title 提示效果的 js 插件 <a rel="nofollow" href="http://www.dustindiaz.com/sweet-titles-finalized/">Sweet Titles Finalized</a>。此插件不但让你的 title 提示效果变得美观，而且可以显示出你将要点击的链接的 url，让用户知道自己将要去哪里，同时提升了用户感受度。而且我认为，系统的 title 提示有时间延迟，用 js 实现的可以迅速的展示出来。 <a href="http://leeiio.me/sweet-titles-for-jquery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://imgs.leeiio.me/blogimgs/2009/07/20090727_sweettitles-jquery.gif" alt="Sweet Titles for jQuery (美妙的标题提示)" /><br />
Sweet Titles 这个名字源自于一个改变 Title 提示效果的 js 插件 <a rel="nofollow" href="http://www.dustindiaz.com/sweet-titles-finalized/">Sweet Titles Finalized</a>。此插件不但让你的 title 提示效果变得美观，而且可以显示出你将要点击的链接的 url，让用户知道自己将要去哪里，同时提升了用户感受度。而且我认为，系统的 title 提示有时间延迟，用 js 实现的可以迅速的展示出来。<br />
<span id="more-1478"></span><br />
大家都知道 jQuery 是一个美妙且强大的 Javascript 库，用 jQuery 来写这个效果的话不单代码得到了很大的精简，效果的实现也可以更加美妙，更加容易对效果进行扩展。</p>
<p>所以我用 jQuery 对这个效果的代码进行了重新编写，请看下面的代码：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> sweetTitles <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    x <span style="color: #339933;">:</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">,</span>                             <span style="color: #006600; font-style: italic;">// @Number: x pixel value of current cursor position</span>
    y <span style="color: #339933;">:</span> <span style="color: #CC0000;">20</span><span style="color: #339933;">,</span>                             <span style="color: #006600; font-style: italic;">// @Number: y pixel value of current cursor position</span>
    tipElements <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;a&quot;</span><span style="color: #339933;">,</span>                  <span style="color: #006600; font-style: italic;">// @Array: Allowable elements that can have the toolTip,split with &quot;,&quot;</span>
    noTitle <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>                     <span style="color: #006600; font-style: italic;">//if this value is false,when the elements has no title,it will not be show</span>
    init <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> noTitle <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">noTitle</span><span style="color: #339933;">;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">tipElements</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mouseover</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>noTitle<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    isTitle <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
                    isTitle <span style="color: #339933;">=</span> $.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">title</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>isTitle<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">myTitle</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">title</span><span style="color: #339933;">;</span>
                    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">myHref</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">href</span><span style="color: #339933;">;</span>
                    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">myHref</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">myHref</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">30</span> <span style="color: #339933;">?</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">myHref</span>.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;...&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">myHref</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">title</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
                    <span style="color: #003366; font-weight: bold;">var</span> tooltip <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;div id='tooltip'&gt;&lt;p&gt;&quot;</span><span style="color: #339933;">+</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">myTitle</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;em&gt;&quot;</span><span style="color: #339933;">+</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">myHref</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/em&gt;&quot;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/p&gt;&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>tooltip<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#tooltip'</span><span style="color: #009900;">&#41;</span>
                        .<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                            <span style="color: #3366CC;">&quot;opacity&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;0.8&quot;</span><span style="color: #339933;">,</span>
                            <span style="color: #3366CC;">&quot;top&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">pageY</span><span style="color: #339933;">+</span><span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #339933;">,</span>
                            <span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">pageX</span><span style="color: #339933;">+</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fast'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mouseout</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">myTitle</span> <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">title</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">myTitle</span><span style="color: #339933;">;</span>
                        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#tooltip'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mousemove</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#tooltip'</span><span style="color: #009900;">&#41;</span>
                    .<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                        <span style="color: #3366CC;">&quot;top&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">pageY</span><span style="color: #339933;">+</span><span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #339933;">,</span>
                        <span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">pageX</span><span style="color: #339933;">+</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span>
                    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    sweetTitles.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>代码是不是很简单，记住不要忘了载入 jQuery 库哦。</p>
<p>当然光有效果没有样式还不行，需要制定一些 css 样式才能让整个效果显得更加美妙。以下是我的 css，供参考。</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body div<span style="color: #cc00cc;">#tooltip</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>z-index<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">1000</span><span style="color: #00AA00;">;</span>max-<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">220px</span><span style="color: #00AA00;">;</span>width<span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span> !important<span style="color: #00AA00;">;</span>width<span style="color: #00AA00;">:</span><span style="color: #933;">220px</span><span style="color: #00AA00;">;</span>background<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>text-align<span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>padding<span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>min-<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">1em</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
body div<span style="color: #cc00cc;">#tooltip</span> p <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>padding<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>color<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>font<span style="color: #00AA00;">:</span><span style="color: #933;">12px</span> verdana<span style="color: #00AA00;">,</span>arial<span style="color: #00AA00;">,</span><span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
body div<span style="color: #cc00cc;">#tooltip</span> p em <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>margin-<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>color<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#f60</span><span style="color: #00AA00;">;</span>font-style<span style="color: #00AA00;">:</span><span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span>font-weight<span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><p class="preview left"><a href="http://leeiio.me/demo/5-sweet-titles-for-jquery-v1/" title="查看演示">View Demo
<em title="Sweet Titles for jQuery (美妙的标题提示)">Sweet Titles for jQuery</em></a></p> <p class="download left"><a class="downloadlink" href="http://leeiio.me/wp-content/plugins/download-monitor/download.php?id=2" title="Sweet Titles for jQuery (美妙的标题提示),共被下载947次,最后更新时间：2009-07-27" >ZIP File<em title="Total Downloads:947">22.75 kB 共被下载947次</em></a></p><p class="clear"></p></p>
<p>2010.11.27更新：增加选项设置当没有title属性的时候不显示sweetTitle。</p>
]]></content:encoded>
			<wfw:commentRss>http://leeiio.me/sweet-titles-for-jquery/feed/</wfw:commentRss>
		<slash:comments>79</slash:comments>
		</item>
		<item>
		<title>改善网站体验小细节，点击改变链接的文本!</title>
		<link>http://leeiio.me/jquery-changes-link-text/</link>
		<comments>http://leeiio.me/jquery-changes-link-text/#comments</comments>
		<pubDate>Sat, 02 May 2009 08:13:47 +0000</pubDate>
		<dc:creator>Leeiio</dc:creator>
				<category><![CDATA[網頁 視覺/體驗]]></category>
		<category><![CDATA[JS/Ajax/AS/Flex]]></category>
		<category><![CDATA[点击改变链接的文本]]></category>
		<category><![CDATA[网站体验]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://leeiio.me/?p=1304</guid>
		<description><![CDATA[jQuery 真是一个非常伟大的 javascript library，至少在我不会写 JS 的时候第一时间接触了它，虽然还有其他很多优秀的 javascript library，但是目前我还是对其情有独钟，它让你的网站显得更加酷，同时在一定程度上给了用户不错的视觉体验… 有时候浏览器变得缓慢或者网络十分缓慢的时候，当你点击了一个链接，你要做的就是对着页面傻看着，页面既不刷新，也没有任何提示，并没有给用户一个好的引导。一些并不是网络从业者的访客可能都不知道你的网站到底怎么了，明明点击了链接却没有反应，从而造成了不好的印象。所以我觉得，为什么不给出一些提示来告诉他们页面正在加载中呢(当他们点击了某个链接的时候)。 $&#40;'a'&#41;.click&#40;function&#40;&#41;&#123; $&#40;this&#41;.text&#40;'loading...'&#41;; &#125;&#41;; 以上这段代码就是改变你所点击的链接的文本为 loading&#8230;当然你如果只想让局部的链接有这种效果的话，自己去选择对象吧。 也许你也已经注意到本站在点击链接的时候，除了链接文本变为 loading&#8230;之外，还会在左上角弹出页面加载的提示，虽然都是些噱头的功能，但是无疑会让用户觉得很眩，多少会吸引用户的注意力从而让等待显得不那么漫长。 我的做法是在你的模板里放置如下代码( CSS 自行控制，别忘了让其绝对定位到顶部)： &#60;div id=&#34;clickload&#34;&#62;页面假装异步加载中...&#60;/div&#62; 然后就是使用 jQuery 来控制以上的 Div 的显示： $&#40;'a'&#41;.click&#40;function&#40;&#41;&#123; $&#40;this&#41;.text&#40;'loading...'&#41;; $&#40;'#clickload'&#41;.show&#40;&#41;; &#125;&#41;; 不过有一点要提醒的是，显然你不能对全站的 a 链接都启用这个效果，因为还有一些 a 链接是在新窗口打开外链或者是 # 或者是 javascript 的，当你点击那些链接的时候当前页面显然不会跳转到新的页面，那么左上角弹出的提示显然也不会被刷新掉，所以你需要对 a &#8230; <a href="http://leeiio.me/jquery-changes-link-text/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>jQuery 真是一个非常伟大的 javascript library，至少在我不会写 JS 的时候第一时间接触了它，虽然还有其他很多优秀的 javascript library，但是目前我还是对其情有独钟，它让你的网站显得更加酷，同时在一定程度上给了用户不错的视觉体验…</p>
<p>有时候浏览器变得缓慢或者网络十分缓慢的时候，当你点击了一个链接，你要做的就是对着页面傻看着，页面既不刷新，也没有任何提示，并没有给用户一个好的引导。一些并不是网络从业者的访客可能都不知道你的网站到底怎么了，明明点击了链接却没有反应，从而造成了不好的印象。所以我觉得，为什么不给出一些提示来告诉他们页面正在加载中呢(当他们点击了某个链接的时候)。<br />
<span id="more-1304"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'loading...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>以上这段代码就是改变你所点击的链接的文本为 loading&#8230;当然你如果只想让局部的链接有这种效果的话，自己去选择对象吧。</strong></p>
<p>也许你也已经注意到本站在点击链接的时候，除了链接文本变为 loading&#8230;之外，还会在左上角弹出页面加载的提示，虽然都是些噱头的功能，但是无疑会让用户觉得很眩，多少会吸引用户的注意力从而让等待显得不那么漫长。</p>
<p>我的做法是在你的模板里放置如下代码( CSS 自行控制，别忘了让其绝对定位到顶部)：</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;clickload&quot;</span>&gt;</span>页面假装异步加载中...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>然后就是使用 jQuery 来控制以上的 Div 的显示：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'loading...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#clickload'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>不过有一点要提醒的是，显然你不能对全站的 a 链接都启用这个效果，因为还有一些 a 链接是在新窗口打开外链或者是 # 或者是 javascript 的，当你点击那些链接的时候当前页面显然不会跳转到新的页面，那么左上角弹出的提示显然也不会被刷新掉，所以你需要对 a 进行过滤。</p>
<p>我只做了简单的过滤，排除了那些新窗口打开的外链</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a[href*=&quot;http://leeiio.me&quot;]'</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>当然具体还得因你自己的站而对 a 进行筛选，你可以选择只针对侧边栏的链接啊或者导航链接啊或者只是文章标题等。</p>
<p>很简单对吧，说了只是小细节了。谢谢大家捧场！</p>
<p><strong>2009.11.11更新：增加鼠标中间点击链接的事件捕获处理。</strong>(顺便祝广大光棍朋友早日“脱光”！)<br />
当你用鼠标中键新窗口打开链接的时候还是会触发事件，导致文字变成“Loading&#8230;”，那么我们就要对鼠标的事件进行处理了，处理的代码如下：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
              <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
              $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'loading...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#clickload'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>2009.11.22更新：页面由window.location打开。</strong><br />
不知道为什么，在IE和Opera中用jquery的click(fn)函数，会丢失默认的事件也就是只执行了click(fn)函数里面写的事件，而默认的打开页面的事件丢失了，Firefox和Chrome都是正常的。不知道是不是jQuery函数的问题，往知情者告知哈。现在的解决方案代码如下：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
              <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
              $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'loading...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#clickload'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
              window.<span style="color: #660066;">location</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://leeiio.me/jquery-changes-link-text/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>用 jQuery 制作模拟下拉框，改变你的下拉框样式</title>
		<link>http://leeiio.me/jquery-select-option/</link>
		<comments>http://leeiio.me/jquery-select-option/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 06:55:35 +0000</pubDate>
		<dc:creator>Leeiio</dc:creator>
				<category><![CDATA[JS/Ajax/AS/Flex]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Select]]></category>
		<category><![CDATA[下拉框样式]]></category>

		<guid isPermaLink="false">http://leeiio.me/?p=1284</guid>
		<description><![CDATA[传统的 Select 下拉框因为样式丑陋且无法随性更改样式而遭到了我的鄙夷，相信很多人都有此种观点。并且在ie6下，下拉框的优先级大于层，经常导致下拉框显示在层的上面。但是自从有了 Javascript，这些问题便不再是问题。最近正好在改版一个网站，要修改下拉框的样式，正好看到 CssRain 已经制作了这么一个很有用的插件，下面我就教大家怎么用 jQuery 制作一个模拟下拉框，从而实现对 Select 下拉框样式的定制。 思路： 通过已知的下拉框，把里面的数据循环出来，放到另一个div的ul列表里， 另一个div就是简单的弹出层而已。 通过hidden可以 获取下拉框的选中的值和文本 。 先看这段代码： &#60;script type=&#34;text/javascript&#34;&#62; /* Dev by CssRain.cn Test in IE6,IE7,Firefox3,Chrome 感谢 CssRain的这段插件代码 */ jQuery.fn.CRselectBox = jQuery.fn.sBox = function&#40;options&#41;&#123; options = $.extend&#40;&#123; animated : false &#8230; <a href="http://leeiio.me/jquery-select-option/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://imgs.leeiio.me/blogimgs/2009/04/20090417-jquery_select.gif" alt="用 jQuery 制作模拟下拉框" /><br />
传统的 Select 下拉框因为样式丑陋且无法随性更改样式而遭到了我的鄙夷，相信很多人都有此种观点。并且在ie6下，下拉框的优先级大于层，经常导致下拉框显示在层的上面。但是自从有了 Javascript，这些问题便不再是问题。最近正好在改版一个网站，要修改下拉框的样式，正好看到 CssRain 已经制作了这么一个很有用的插件，下面我就教大家怎么用 jQuery 制作一个模拟下拉框，从而实现对 Select 下拉框样式的定制。<br />
<span id="more-1284"></span><br />
<strong>思路：<br />
通过已知的下拉框，把里面的数据循环出来，放到另一个div的ul列表里，<br />
另一个div就是简单的弹出层而已。<br />
通过hidden可以 获取下拉框的选中的值和文本 。</strong></p>
<p>先看这段代码：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #006600; font-style: italic;">/* 
Dev by CssRain.cn 
Test in IE6,IE7,Firefox3,Chrome
感谢 CssRain的这段插件代码
*/</span>
jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">CRselectBox</span> <span style="color: #339933;">=</span> jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">sBox</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	options <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		animated <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> _self <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
	<span style="color: #009966; font-style: italic;">/*构建结构*/</span>
	<span style="color: #003366; font-weight: bold;">var</span> _parent <span style="color: #339933;">=</span> _self.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> wrapHtml <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;div class=&quot;CRselectBox&quot;&gt;&lt;/div&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> $wrapHtml <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>wrapHtml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>_parent<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> selectedOptionValue <span style="color: #339933;">=</span> _self.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;option:selected&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> selectedOptionTxt <span style="color: #339933;">=</span> _self.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;option:selected&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">name</span> <span style="color: #339933;">=</span> _self.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> id <span style="color: #339933;">=</span> _self.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> inputHtml <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;input type=&quot;hidden&quot; value=&quot;'</span><span style="color: #339933;">+</span>selectedOptionValue<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; name=&quot;'</span><span style="color: #339933;">+</span><span style="color: #000066;">name</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; id=&quot;'</span><span style="color: #339933;">+</span>id<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;/&gt;'</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span>inputHtml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>$wrapHtml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> inputTxtHtml <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;input type=&quot;hidden&quot; value=&quot;'</span><span style="color: #339933;">+</span>selectedOptionTxt<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; name=&quot;'</span><span style="color: #339933;">+</span><span style="color: #000066;">name</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'_CRtext&quot; id=&quot;'</span><span style="color: #339933;">+</span>id<span style="color: #339933;">+</span><span style="color: #3366CC;">'_CRtext&quot;/&gt;'</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span>inputTxtHtml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>$wrapHtml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> aHtml <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;a class=&quot;CRselectValue&quot; href=&quot;#&quot;&gt;'</span><span style="color: #339933;">+</span>selectedOptionTxt<span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;/a&gt;'</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span>aHtml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>$wrapHtml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> ulHtml <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;ul class=&quot;CRselectBoxOptions&quot;&gt;&lt;/ul&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> $ulHtml <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>ulHtml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>$wrapHtml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> liHtml <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
	_self.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;option&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;selected&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			liHtml <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&lt;li class=&quot;CRselectBoxItem&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;selected&quot; rel=&quot;'</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;&gt;'</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;/a&gt;&lt;/li&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
			liHtml <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&lt;li class=&quot;CRselectBoxItem&quot;&gt;&lt;a href=&quot;#&quot; rel=&quot;'</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;&gt;'</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;/a&gt;&lt;/li&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span>liHtml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>$ulHtml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009966; font-style: italic;">/*添加效果*/</span>
	$<span style="color: #009900;">&#40;</span> $wrapHtml<span style="color: #339933;">,</span> _parent<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;CRselectBoxHover&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;CRselectBoxHover&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.CRselectValue&quot;</span><span style="color: #339933;">,</span>$wrapHtml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">blur</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.CRselectBoxOptions&quot;</span><span style="color: #339933;">,</span>$wrapHtml<span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;:hidden&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">animated</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.CRselectBoxOptions&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fast&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.CRselectBoxOptions&quot;</span><span style="color: #339933;">,</span>$wrapHtml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fast&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.CRselectBoxOptions&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.CRselectBoxOptions&quot;</span><span style="color: #339933;">,</span>$wrapHtml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.CRselectBoxItem a&quot;</span><span style="color: #339933;">,</span>$wrapHtml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">blur</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> value <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;rel&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> txt <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span><span style="color: #339933;">+</span>id<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span><span style="color: #339933;">+</span>id<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;_CRtext&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>txt<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.CRselectValue&quot;</span><span style="color: #339933;">,</span>$wrapHtml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>txt<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.CRselectBoxItem a&quot;</span><span style="color: #339933;">,</span>$wrapHtml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;selected&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;selected&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">animated</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.CRselectBoxOptions&quot;</span><span style="color: #339933;">,</span>$wrapHtml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fast&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.CRselectBoxOptions&quot;</span><span style="color: #339933;">,</span>$wrapHtml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> $<span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">target</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;class&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;CRselectBox&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">animated</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.CRselectBoxOptions&quot;</span><span style="color: #339933;">,</span>$wrapHtml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fast&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.CRselectBoxOptions&quot;</span><span style="color: #339933;">,</span>$wrapHtml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	_self.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> _self<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>当然既然是 jQuery 实现的，自然别忘了载入 jQuery 的库哦！<br />
-<a href="http://www.cssrain.cn/article.asp?id=1323" rel="nofollow" class="broken_link">Via</a></p>
<p>至于怎么用呢，看下面这段代码：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#abc&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">CRselectBox</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>      <span style="color: #006600; font-style: italic;">//#abc 为你的下拉框select的ID</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>只要给你的下拉框 Select 一个 ID 值即可，其余的就交给上述的 jQuery 插件了。</p>
<p>CSS部分自行定义：</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.CRselectBox</span> <span style="color: #00AA00;">&#123;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.CRselectBoxHover</span> <span style="color: #00AA00;">&#123;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.CRselectBox</span> a<span style="color: #6666ff;">.CRselectValue</span> <span style="color: #00AA00;">&#123;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.CRselectBoxOptions</span> <span style="color: #00AA00;">&#123;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.CRselectBoxOptions</span> a<span style="color: #00AA00;">&#123;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.CRselectBoxOptions</span> a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">&#123;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.CRselectBoxOptions</span> a<span style="color: #6666ff;">.selected</span><span style="color: #00AA00;">&#123;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #808080; font-style: italic;">/* 解决 firefox 点击放大出现虚线框，从而导致滚动条的问题  */</span>
<span style="color: #6666ff;">.CRselectBox</span> a <span style="color: #00AA00;">&#123;</span> 
	<span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.CRselectBox</span> a<span style="color: #3333ff;">:focus </span><span style="color: #00AA00;">&#123;</span> 
	<span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><p class="preview left"><a href="http://leeiio.me/demo/3-jquery-select/" title="查看演示">View Demo
<em title="用 jQuery 制作模拟下拉框">jQuery Select</em></a></p> <p class="download left"><a class="downloadlink" href="http://leeiio.me/wp-content/plugins/download-monitor/download.php?id=3" title="用 jQuery 制作模拟下拉框,共被下载1856次,最后更新时间：2009-04-17" >ZIP File<em title="Total Downloads:1856">34.45 kB 共被下载1856次</em></a></p><p class="clear"></p></p>
]]></content:encoded>
			<wfw:commentRss>http://leeiio.me/jquery-select-option/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>拥抱 CSS 裸奔节，用 JavaScript 强制脱衣</title>
		<link>http://leeiio.me/force-remove-css-in-css-nake-day/</link>
		<comments>http://leeiio.me/force-remove-css-in-css-nake-day/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 02:37:59 +0000</pubDate>
		<dc:creator>Leeiio</dc:creator>
				<category><![CDATA[(X)HTML/CSS/XML/XSL]]></category>
		<category><![CDATA[JS/Ajax/AS/Flex]]></category>
		<category><![CDATA[CSS 裸奔节]]></category>
		<category><![CDATA[CSS nake day]]></category>
		<category><![CDATA[强制脱衣]]></category>
		<category><![CDATA[强制去除 CSS]]></category>

		<guid isPermaLink="false">http://leeiio.me/?p=1250</guid>
		<description><![CDATA[因为我的博客很多时候都是处在调试中的，并且很多插件诸如 Simple Tags 是直接在标签里给元素加上 CSS 的，所以如果想要“裸奔”光是去除 .css 文件是远远不够的，那么有没有一种强制的方法呢？我昨晚就在想这样一种方法。于是被我想到了。也就是本文介绍如何 “<strong>强制脱衣</strong>” ，也就是教你<strong>如何强制去除网站的 CSS</strong> ！

<strong>实现原理：</strong>众所周知，CSS 调用有三种方法，一种是 link 方式，一种是 &#60;style&#62;&#60;/style&#62; 包裹方式，最后一种就是直接且暴力的 style="" 方式，通过 Javascript 代码，强制禁用 type="text/css" 的 link 或者 让 link 链接 css 的 href="" 为空，且让 &#60;style&#62;&#60;/style&#62;
被清除或者禁用，且让 style="" 为空 或者去除。 <a href="http://leeiio.me/force-remove-css-in-css-nake-day/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://imgs.leeiio.me/blogimgs/2009/04/20090409_cssnake.jpg" alt="CSS 裸奔节" /><br />
很早就有人 Twitter 说今天是 CSS 裸奔节，于是&#8230;</p>
<h3>CSS Naked Day 的来历</h3>
<p><a title="CSS Naked Day的发起者页面" rel="nofollow" href="http://naked.dustindiaz.com/">CSS Naked Day</a>，也称 CSS 裸奔节或 CSS 裸奔日。</p>
<p>在裸奔节这天，参加裸奔节的Blog 将会去除页面上所有的 CSS 样式和广告裸奔整整一天,通过这个节日来重视 CSS 的重要性.当然你的网站如果是用 table 来布局的话这个节日对你来说并不是很合适.在2006年有将近800个国际知名网站参与这个节日.而今年CSS Naked Day将由之前的24小时改为48小时!<br />
<span id="more-1250"></span></p>
<h3>CSS Naked Day 的目的</h3>
<p>推动Web标准、提倡简洁为美、使用正确的 (x)html 语义标记、良好的层次结构。暂时把页面设计抛弃，直接展示&lt;body&gt;内容！</p>
<h3>历届CSS Naked Day的举办时间</h3>
<p>第一届 CSS 裸奔节：2006年4月5日</p>
<p>第二届 CSS 裸奔节：2007年4月5日</p>
<p>第三届 CSS 裸奔节：2008年4月9日</p>
<p>第四届 CSS 裸奔节：2009年4月9日</p>
<p>- <a href="http://blog.taoxian.info/2009-css-naked-day.html">Via</a></p>
<p>你可以前往<a href="http://naked.dustindiaz.com/" rel="nofollow">官方网站</a>查看更多的介绍以及了解如何加入这个活动。</p>
<p>然后，回到本文的重点。因为我的博客很多时候都是处在调试中的，并且很多插件诸如 Simple Tags 是直接在标签里给元素加上 CSS 的，所以如果想要“裸奔”光是去除 .css 文件是远远不够的，那么有没有一种强制的方法呢？我昨晚就在想这样一种方法。于是被我想到了。也就是本文介绍如何 “<strong>强制脱衣</strong>” ，也就是教你<strong>如何强制去除网站的 CSS</strong> ！</p>
<p><strong>实现原理：</strong>众所周知，CSS 调用有三种方法，一种是 link 方式，一种是 &lt;style&gt;&lt;/style&gt; 包裹方式，最后一种就是直接且暴力的 style=&#8221;" 方式，通过 Javascript 代码，强制禁用 type=&#8221;text/css&#8221; 的 link 或者 让 link 链接 css 的 href=&#8221;" 为空，且让 &lt;style&gt;&lt;/style&gt;<br />
被清除或者禁用，且让 style=&#8221;" 为空 或者去除。</p>
<p>这里提供两种方法，一种是最普通的 Javascript 来实现，另外一种是通过目前的最流行的 Javascript 库 jQuery 来实现。</p>
<p><strong>第一种（普通版）：</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/JavaScript&quot;</span><span style="color: #339933;">&gt;</span>	
<span style="color: #006600; font-style: italic;">// 用style方式引用的css</span>
<span style="color: #003366; font-weight: bold;">var</span> style<span style="color: #339933;">=</span>document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'style'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> s<span style="color: #339933;">=</span><span style="color: #3366CC;">'Style:'</span> <span style="color: #339933;">+</span> style.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>style.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #009966; font-style: italic;">/*s += style.item(i) + '|';*/</span>
    style.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">disabled</span><span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// 用link方式引用的css</span>
<span style="color: #003366; font-weight: bold;">var</span> link <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'link'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
s <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'Link:'</span> <span style="color: #339933;">+</span> link.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>link.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'text/css'</span> <span style="color: #339933;">==</span> link.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">type</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #009966; font-style: italic;">/*s += link.item(i).href + &quot;|\\n&quot;;*/</span>
            link.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">disabled</span><span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// 任意对象的style=&quot;&quot;</span>
<span style="color: #003366; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">childNodes</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'*'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
s <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'Obj:'</span> <span style="color: #339933;">+</span> obj.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>obj.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>   
    obj1 <span style="color: #339933;">=</span> obj.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>obj1.<span style="color: #660066;">attributes</span>.<span style="color: #660066;">getNamedItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'style'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        s <span style="color: #339933;">+=</span> obj1.<span style="color: #660066;">nodeName</span> <span style="color: #339933;">+</span> obj1.<span style="color: #660066;">attributes</span>.<span style="color: #660066;">getNamedItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'style'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>n&quot;</span><span style="color: #339933;">;</span>
        obj1.<span style="color: #660066;">attributes</span>.<span style="color: #660066;">getNamedItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'style'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>只需将以上这段 JS 代码插入你的网页中即可。</p>
<p><strong>接着是第二种（jQuery版）</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/JavaScript&quot;</span><span style="color: #339933;">&gt;</span>		
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// 用link方式引用的css</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;link&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;type&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;type&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;text/css&quot;</span><span style="color: #009900;">&#41;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #006600; font-style: italic;">// 任意对象的style=&quot;&quot;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;*&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeAttr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;style&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// 用style方式引用的css</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;style&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>如果你的网站启用了 jQuery 库的话，那么毫不犹豫地用第二种吧，你看代码是何其简洁啊！</p>
<p><strong>最后祝大家裸奔愉快！</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leeiio.me/force-remove-css-in-css-nake-day/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
	</channel>
</rss>

