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

<channel>
	<title>网站前端,web前端,前端脚本,前端优化&#124;时代前端 &#187; 新版</title>
	<atom:link href="http://www.52shidai.com/tag/%e6%96%b0%e7%89%88/feed" rel="self" type="application/rss+xml" />
	<link>http://www.52shidai.com</link>
	<description>网站前端研究中心</description>
	<lastBuildDate>Thu, 02 Feb 2012 03:36:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>jQuery:1.4新版本中你应该知道的15个新特性(二)</title>
		<link>http://www.52shidai.com/javascript/jquery/127.html</link>
		<comments>http://www.52shidai.com/javascript/jquery/127.html#comments</comments>
		<pubDate>Sun, 21 Feb 2010 03:26:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[新版]]></category>
		<category><![CDATA[特性]]></category>

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

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

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

// … do stuff

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

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

//或者

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

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

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

