<?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>YSlove.net &#187; javascript</title>
	<atom:link href="http://yslove.net/tag/js/feed/" rel="self" type="application/rss+xml" />
	<link>http://yslove.net</link>
	<description>Playing Keyboard</description>
	<lastBuildDate>Fri, 27 Jan 2012 06:20:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>[转]让开发也懂前端</title>
		<link>http://yslove.net/2011/07/guide-to-fed/</link>
		<comments>http://yslove.net/2011/07/guide-to-fed/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 01:12:00 +0000</pubDate>
		<dc:creator>YSjia</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[实验室]]></category>

		<guid isPermaLink="false">http://yslove.net/2011/07/guide-to-fed/</guid>
		<description><![CDATA[让开发也懂前端 View more presentations from lifesinger 原文地址：http://lifesinger.wordpress.com/2011/07/07/guide-to-fed/ 也许这些文章您也感兴趣:TWO IT-Services Web Design玩玩Flash开发流程中的可用性之三jQuery UI组件开发[转]UE学习笔记：Facebook如何利用数据指导设计Copyright &#169; 2010 by YSlove.net欢迎留言 &#124; 作者: YSjia &#124; 原文链接：http://yslove.net/2011/07/guide-to-fed/数字指纹 3abf2858e3aa210a1750056317836753 (38.107.179.207)]]></description>
			<content:encoded><![CDATA[<div style="width: 425px" id="__ss_8533438"><strong style="margin: 12px 0px 4px; display: block"><a title="让开发也懂前端" href="http://www.slideshare.net/lifesinger/ss-8533438" target="_blank">让开发也懂前端</a></strong> <iframe height="355" marginheight="0" src="http://www.slideshare.net/slideshow/embed_code/8533438" frameborder="0" width="425" marginwidth="0" scrolling="no"></iframe>
<div style="padding-bottom: 12px; padding-left: 0px; padding-right: 0px; padding-top: 5px">View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/lifesinger" target="_blank">lifesinger</a> </div>
</p></div>
<p>原文地址：<a href="http://lifesinger.wordpress.com/2011/07/07/guide-to-fed/">http://lifesinger.wordpress.com/2011/07/07/guide-to-fed/</a></p>
<hr /><h2>也许这些文章您也感兴趣:</h2><ul><li><a href="http://yslove.net/2010/04/twoit-serviceswebdesign/" rel="bookmark" title="Permanent Link: TWO IT-Services Web Design">TWO IT-Services Web Design</a></li><li><a href="http://yslove.net/2010/04/flash-for-funny/" rel="bookmark" title="Permanent Link: 玩玩Flash">玩玩Flash</a></li><li><a href="http://yslove.net/2009/07/the-availability-of-development-process-3/" rel="bookmark" title="Permanent Link: 开发流程中的可用性之三">开发流程中的可用性之三</a></li><li><a href="http://yslove.net/2011/01/jquery-ui-widget-development/" rel="bookmark" title="Permanent Link: jQuery UI组件开发">jQuery UI组件开发</a></li><li><a href="http://yslove.net/2010/10/how-to-use-data-to-guide-design-of-facebook/" rel="bookmark" title="Permanent Link: [转]UE学习笔记：Facebook如何利用数据指导设计">[转]UE学习笔记：Facebook如何利用数据指导设计</a></li></ul><hr /><small>Copyright &copy; 2010 by <a href="http://yslove.net">YSlove.net</a><br /><a href="http://yslove.net/2011/07/guide-to-fed/#comments" title="留言">欢迎留言</a> | 作者: <a href="" >YSjia</a> | 原文链接：<a href="http://yslove.net/2011/07/guide-to-fed/">http://yslove.net/2011/07/guide-to-fed/</a><br /><em>数字指纹 3abf2858e3aa210a1750056317836753 (38.107.179.207) </em></small>]]></content:encoded>
			<wfw:commentRss>http://yslove.net/2011/07/guide-to-fed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>getBoundingClientRect方法在IE8以上版本需要注意</title>
		<link>http://yslove.net/2011/06/javascript-getboundingclientrect-ie7-has-different/</link>
		<comments>http://yslove.net/2011/06/javascript-getboundingclientrect-ie7-has-different/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 04:21:00 +0000</pubDate>
		<dc:creator>YSjia</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[实验室]]></category>

		<guid isPermaLink="false">http://yslove.net/2011/06/javascript-getboundingclientrect-ie7-has-different/</guid>
		<description><![CDATA[getBoundingClientRect方法可以获得当前元素相对于浏览器的位置。 但是在IE8以前的版本中，在DOM加载完成后，使用该方法会返回当前元素的物理位置，即没有CSS样式渲染时的位置。 而IE8以后会返回一个渲染后的位置，这样的差异就导致了一些问题的产生。 比如说当页面上面有几个选卡，但是当没有CSS渲染时，是不会重叠的，所以非常高。 这种情况下想要获取下面元素的高度时，误差非常大！ 也许这些文章您也感兴趣:ie6 javascript:void(0);javascript 函数备忘 &#8211; indexOfjavascript 函数备忘 &#8211; unique消失的神族PCRE Partterns &#8211; AssertionsCopyright &#169; 2010 by YSlove.net欢迎留言 &#124; 作者: YSjia &#124; 原文链接：http://yslove.net/2011/06/javascript-getboundingclientrect-ie7-has-different/数字指纹 3abf2858e3aa210a1750056317836753 (38.107.179.207)]]></description>
			<content:encoded><![CDATA[<p>getBoundingClientRect方法可以获得当前元素相对于浏览器的位置。</p>
<p>但是在IE8以前的版本中，在DOM加载完成后，使用该方法会返回当前元素的<strong>物理位置</strong>，即没有CSS样式渲染时的位置。</p>
<p>而IE8以后会返回一个<strong>渲染后的位置</strong>，这样的差异就导致了一些问题的产生。</p>
<p>比如说当页面上面有几个选卡，但是当没有CSS渲染时，是不会重叠的，所以非常高。</p>
<p>这种情况下想要获取下面元素的高度时，误差非常大！</p>
<hr /><h2>也许这些文章您也感兴趣:</h2><ul><li><a href="http://yslove.net/2011/02/ie6-javascriptvoid0/" rel="bookmark" title="Permanent Link: ie6 javascript:void(0);">ie6 javascript:void(0);</a></li><li><a href="http://yslove.net/2011/03/javascript-indexof/" rel="bookmark" title="Permanent Link: javascript 函数备忘 &#8211; indexOf">javascript 函数备忘 &#8211; indexOf</a></li><li><a href="http://yslove.net/2011/04/javascript-array-unique/" rel="bookmark" title="Permanent Link: javascript 函数备忘 &ndash; unique">javascript 函数备忘 &ndash; unique</a></li><li><a href="http://yslove.net/2009/05/doodle-protoss-gone/" rel="bookmark" title="Permanent Link: 消失的神族">消失的神族</a></li><li><a href="http://yslove.net/2011/04/pcre-partterns-assertions/" rel="bookmark" title="Permanent Link: PCRE Partterns &#8211; Assertions">PCRE Partterns &#8211; Assertions</a></li></ul><hr /><small>Copyright &copy; 2010 by <a href="http://yslove.net">YSlove.net</a><br /><a href="http://yslove.net/2011/06/javascript-getboundingclientrect-ie7-has-different/#comments" title="留言">欢迎留言</a> | 作者: <a href="" >YSjia</a> | 原文链接：<a href="http://yslove.net/2011/06/javascript-getboundingclientrect-ie7-has-different/">http://yslove.net/2011/06/javascript-getboundingclientrect-ie7-has-different/</a><br /><em>数字指纹 3abf2858e3aa210a1750056317836753 (38.107.179.207) </em></small>]]></content:encoded>
			<wfw:commentRss>http://yslove.net/2011/06/javascript-getboundingclientrect-ie7-has-different/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>javascript 函数备忘 &#8211; unique</title>
		<link>http://yslove.net/2011/04/javascript-array-unique/</link>
		<comments>http://yslove.net/2011/04/javascript-array-unique/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 08:05:39 +0000</pubDate>
		<dc:creator>YSjia</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[实验室]]></category>

		<guid isPermaLink="false">http://yslove.net/2011/04/javascript-array-unique/</guid>
		<description><![CDATA[这并不是一标准的函数，而是利用Array的方法来自定义而以。 if (!Array.prototype.unique){ Array.prototype.unique = function(){ var self = this, _a = self.concat().sort(); _a.sort(function(a, b){ if(a === b){ var n = self.indexOf(b); self.splice(n,1); } return -1; }); }; } 其中值得注意的是sort函数如果是使用函数做为参数的话，一定要有返回值，并且一定是数字！ 相关问题与讨论: http://www.zachleat.com/web/array-sort/ http://stackoverflow.com/questions/2956432/js-sort-works-in-firefox-but-not-ie-cant-work-out-why 也许这些文章您也感兴趣:javascript 函数备忘 &#8211; indexOfjavascript教程-数组ie6 javascript:void(0);javascript-函数getBoundingClientRect方法在IE8以上版本需要注意Copyright &#169; 2010 by YSlove.net欢迎留言 &#124; 作者: YSjia &#124; 原文链接：http://yslove.net/2011/04/javascript-array-unique/数字指纹 3abf2858e3aa210a1750056317836753 (38.107.179.207)]]></description>
			<content:encoded><![CDATA[<p>这并不是一标准的函数，而是利用Array的方法来自定义而以。</p>
<pre>if (!Array.prototype.unique){
	Array.prototype.unique = function(){
		var self = this,
		    _a = self.concat().sort();

		_a.sort(function(a, b){
			if(a === b){
				var n = self.<a href="http://yslove.net/2011/03/javascript-indexof/" target="_blank">indexOf</a>(b);
				self.splice(n,1);
			}

			return -1;
		});	

	};
}</pre>
<p>其中值得注意的是<code>sort</code>函数如果是使用函数做为参数的话，一定要有返回值，并且一定是数字！</p>
<p>相关问题与讨论:</p>
<p><a href="http://www.zachleat.com/web/array-sort/">http://www.zachleat.com/web/array-sort/</a></p>
<p><a href="http://stackoverflow.com/questions/2956432/js-sort-works-in-firefox-but-not-ie-cant-work-out-why">http://stackoverflow.com/questions/2956432/js-sort-works-in-firefox-but-not-ie-cant-work-out-why</a></p>
<hr /><h2>也许这些文章您也感兴趣:</h2><ul><li><a href="http://yslove.net/2011/03/javascript-indexof/" rel="bookmark" title="Permanent Link: javascript 函数备忘 &#8211; indexOf">javascript 函数备忘 &#8211; indexOf</a></li><li><a href="http://yslove.net/2009/05/javascript-array/" rel="bookmark" title="Permanent Link: javascript教程-数组">javascript教程-数组</a></li><li><a href="http://yslove.net/2011/02/ie6-javascriptvoid0/" rel="bookmark" title="Permanent Link: ie6 javascript:void(0);">ie6 javascript:void(0);</a></li><li><a href="http://yslove.net/2009/05/javascript-function/" rel="bookmark" title="Permanent Link: javascript-函数">javascript-函数</a></li><li><a href="http://yslove.net/2011/06/javascript-getboundingclientrect-ie7-has-different/" rel="bookmark" title="Permanent Link: getBoundingClientRect方法在IE8以上版本需要注意">getBoundingClientRect方法在IE8以上版本需要注意</a></li></ul><hr /><small>Copyright &copy; 2010 by <a href="http://yslove.net">YSlove.net</a><br /><a href="http://yslove.net/2011/04/javascript-array-unique/#comments" title="留言">欢迎留言</a> | 作者: <a href="" >YSjia</a> | 原文链接：<a href="http://yslove.net/2011/04/javascript-array-unique/">http://yslove.net/2011/04/javascript-array-unique/</a><br /><em>数字指纹 3abf2858e3aa210a1750056317836753 (38.107.179.207) </em></small>]]></content:encoded>
			<wfw:commentRss>http://yslove.net/2011/04/javascript-array-unique/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>会说话的代码</title>
		<link>http://yslove.net/2011/03/the-code-will-speak/</link>
		<comments>http://yslove.net/2011/03/the-code-will-speak/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 17:40:21 +0000</pubDate>
		<dc:creator>YSjia</dc:creator>
				<category><![CDATA[杂谈]]></category>
		<category><![CDATA[闲聊]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[前端开发]]></category>

		<guid isPermaLink="false">http://yslove.net/2011/03/the-code-will-speak/</guid>
		<description><![CDATA[在开发中，说实话，一般的公司可能都不会有写文档的时间，并且个人也不一定都有这习惯。 但是对于你来说，代码就是你的一张脸，当别人读的时候，你总不希望别人说：“天阿！怎么这么丑！！！”如果正好你这时在旁边，那将会是一件多么悲催的事~~ 那么让我们简单的为这张脸美容一下，代表自己嘛，肯定不要太悲催了，哈哈。 让代码自己说明白为什么这样，大家肯定想到了写注释。 写注释也有好多种写法，比如说能直接生成javaDoc的注释风格等 但是即使生成了，这文档又会有多少人去看呢？又有多少人能看懂呢？ 所以，还是让我们来简单点吧，只会占用你一点点时间，就让你的代码看起来更加的漂亮。 CSS 对于CSS，也许经常会使用到缩写，但是过一段时间，自己也许都已经已经不记得了~囧！ 写一些必要的注释，解释缩写的意义。对于其他人来看，这让他们更快的明白；对于自己过一段时间后再看，可以迅速的回想起当时的思路，易于修改。 jQuery ui theme的风格，这种命名方法，个人感觉是非常不错的方法，即易于记忆，同时也易于理解。 命名空间，虽然CSS里面这个概念很弱，或者说因为权重的问题不存在命名空间这个概念。但是如果把页面上每一块都分割开的话，那么每一块应该是相对独立，在独立的范畴内应该使用同一父级的class做为命名空间。这不仅仅是权重的问题，也增强代码的可读性。 多使用换行，对于不同的区块，应该使用换行让代码上的逻辑也更清晰。 javascript javascript有很多不同的注释写法，我这里绝对不是标准的，大家请仅仅做为参考。 写注释的目的就是为了让代码自己可以解释自己，并且说明自己的用法等。 在注释段里面放些简单的实例，让新人更容易理解已经公司现有的Base类库。 遵循着某总风格。因为javascript的灵活性，使得使用这门语言的人可以用各种写法来达到目的，但是实事让，如果在团队里每个人的代码风格都相差很大，不但看起来不爽，读起来更不爽。 所以我们一定要遵循某种结构。 噢，对了，在组件的前面，或者段落前要写上自己的名字，这点很重要，因为其他人要修改的话，至少要知道这东西是谁做的，可以找谁商议。 &#160; 以上一些步骤其实都不复杂，但是你的代码会因此清晰点。 输入的指令是要让编译器明白，如果它不明白，OK没商量直接给你抛Error~ 写注释，是为了给人看的，如果只是机器能看懂，那还不如不写了。 也许这些文章您也感兴趣:Adobe Air的CSS样式支持（1.5*）伪类与伪元素ie z-index bug符合XHTML Strict 1.0 W3C组织标准的标签与结构PCRE Partterns &#8211; AssertionsCopyright &#169; 2010 by YSlove.net欢迎留言 &#124; 作者: YSjia &#124; 原文链接：http://yslove.net/2011/03/the-code-will-speak/数字指纹 3abf2858e3aa210a1750056317836753 (38.107.179.207)]]></description>
			<content:encoded><![CDATA[<p>在开发中，说实话，一般的公司可能都不会有写文档的时间，并且个人也不一定都有这习惯。</p>
<p>但是对于你来说，代码就是你的一张脸，当别人读的时候，你总不希望别人说：“天阿！怎么这么丑！！！”如果正好你这时在旁边，那将会是一件多么悲催的事~~</p>
<p>那么让我们简单的为这张脸美容一下，代表自己嘛，肯定不要太悲催了，哈哈。</p>
<p>让代码自己说明白为什么这样，大家肯定想到了写注释。</p>
<p>写注释也有好多种写法，比如说能直接生成javaDoc的注释风格等</p>
<p>但是即使生成了，这文档又会有多少人去看呢？又有多少人能看懂呢？</p>
<p>所以，还是让我们来简单点吧，只会占用你一点点时间，就让你的代码看起来更加的漂亮。</p>
<h3>CSS</h3>
<p>对于CSS，也许经常会使用到缩写，但是过一段时间，自己也许都已经已经不记得了~囧！</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://gd.yslove.net/5cb332ad3c4b_13D3/image.png" width="500" height="255" /> </p>
</p>
<p>写一些必要的注释，解释缩写的意义。对于其他人来看，这让他们更快的明白；对于自己过一段时间后再看，可以迅速的回想起当时的思路，易于修改。</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://gd.yslove.net/5cb332ad3c4b_13D3/image_3.png" width="500" height="220" /> </p>
<p>jQuery ui theme的风格，这种命名方法，个人感觉是非常不错的方法，即易于记忆，同时也易于理解。</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://gd.yslove.net/5cb332ad3c4b_13D3/image_4.png" width="500" height="180" /> </p>
<p>命名空间，虽然CSS里面这个概念很弱，或者说因为权重的问题不存在命名空间这个概念。但是如果把页面上每一块都分割开的话，那么每一块应该是相对独立，在独立的范畴内应该使用同一父级的class做为命名空间。这不仅仅是权重的问题，也增强代码的可读性。</p>
</p>
<p>多使用换行，对于不同的区块，应该使用换行让代码上的逻辑也更清晰。</p>
<h3>javascript</h3>
<p>javascript有很多不同的注释写法，我这里绝对不是标准的，大家请仅仅做为参考。</p>
<p>写注释的目的就是为了让代码自己可以解释自己，并且说明自己的用法等。</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://gd.yslove.net/5cb332ad3c4b_13D3/image_5.png" width="500" height="348" /> </p>
<p>在注释段里面放些简单的实例，让新人更容易理解已经公司现有的Base类库。</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://gd.yslove.net/5cb332ad3c4b_13D3/image_6.png" width="500" height="408" /> </p>
</p>
<p>遵循着某总风格。因为javascript的灵活性，使得使用这门语言的人可以用各种写法来达到目的，但是实事让，如果在团队里每个人的代码风格都相差很大，不但看起来不爽，读起来更不爽。</p>
<p>所以我们一定要遵循某种结构。</p>
<p>噢，对了，在组件的前面，或者段落前要写上自己的名字，这点很重要，因为其他人要修改的话，至少要知道这东西是谁做的，可以找谁商议。</p>
<p>&#160;</p>
<p>以上一些步骤其实都不复杂，但是你的代码会因此清晰点。</p>
<p>输入的指令是要让编译器明白，如果它不明白，OK没商量直接给你抛Error~</p>
<p>写注释，是为了给人看的，如果只是机器能看懂，那还不如不写了。</p>
<hr /><h2>也许这些文章您也感兴趣:</h2><ul><li><a href="http://yslove.net/2009/12/air-css-1-5/" rel="bookmark" title="Permanent Link: Adobe Air的CSS样式支持（1.5*）">Adobe Air的CSS样式支持（1.5*）</a></li><li><a href="http://yslove.net/2009/10/css-selector-pseudo-elements/" rel="bookmark" title="Permanent Link: 伪类与伪元素">伪类与伪元素</a></li><li><a href="http://yslove.net/2010/10/ie-z-index-bug/" rel="bookmark" title="Permanent Link: ie z-index bug">ie z-index bug</a></li><li><a href="http://yslove.net/2009/08/xhtml-strict-1-0-structural-element/" rel="bookmark" title="Permanent Link: 符合XHTML Strict 1.0 W3C组织标准的标签与结构">符合XHTML Strict 1.0 W3C组织标准的标签与结构</a></li><li><a href="http://yslove.net/2011/04/pcre-partterns-assertions/" rel="bookmark" title="Permanent Link: PCRE Partterns &#8211; Assertions">PCRE Partterns &#8211; Assertions</a></li></ul><hr /><small>Copyright &copy; 2010 by <a href="http://yslove.net">YSlove.net</a><br /><a href="http://yslove.net/2011/03/the-code-will-speak/#comments" title="留言">欢迎留言</a> | 作者: <a href="" >YSjia</a> | 原文链接：<a href="http://yslove.net/2011/03/the-code-will-speak/">http://yslove.net/2011/03/the-code-will-speak/</a><br /><em>数字指纹 3abf2858e3aa210a1750056317836753 (38.107.179.207) </em></small>]]></content:encoded>
			<wfw:commentRss>http://yslove.net/2011/03/the-code-will-speak/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>javascript 函数备忘 &#8211; indexOf</title>
		<link>http://yslove.net/2011/03/javascript-indexof/</link>
		<comments>http://yslove.net/2011/03/javascript-indexof/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 06:44:56 +0000</pubDate>
		<dc:creator>YSjia</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[实验室]]></category>

		<guid isPermaLink="false">http://yslove.net/2011/03/javascript-indexof/</guid>
		<description><![CDATA[if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt /*, from*/) { var len = this.length; var from = Number(arguments[1]) &#124;&#124; 0; from = (from &#60; 0) ? Math.ceil(from) : Math.floor(from); if (from &#60; 0) from += len; for (; from &#60; len; from++) { if (from in this &#38;&#38; this[from] === elt) return from; } return -1; [...]]]></description>
			<content:encoded><![CDATA[<pre>if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from &lt; 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from &lt; 0)
      from += len;

    for (; from &lt; len; from++)
    {
      if (from in this &amp;&amp;
          this[from] === elt)
        return from;
    }
    return -1;
  };
}</pre>
<pre>&#160;</pre>
<pre>ECMA-262 standard</pre>
<pre>&#160;</pre>
<p><a href="http://www.tutorialspoint.com/javascript/array_indexof.htm">http://www.tutorialspoint.com/javascript/array_indexof.htm</a></p>
<hr /><h2>也许这些文章您也感兴趣:</h2><ul><li><a href="http://yslove.net/2011/04/javascript-array-unique/" rel="bookmark" title="Permanent Link: javascript 函数备忘 &ndash; unique">javascript 函数备忘 &ndash; unique</a></li><li><a href="http://yslove.net/2011/02/ie6-javascriptvoid0/" rel="bookmark" title="Permanent Link: ie6 javascript:void(0);">ie6 javascript:void(0);</a></li><li><a href="http://yslove.net/2011/06/javascript-getboundingclientrect-ie7-has-different/" rel="bookmark" title="Permanent Link: getBoundingClientRect方法在IE8以上版本需要注意">getBoundingClientRect方法在IE8以上版本需要注意</a></li><li><a href="http://yslove.net/2009/05/doodle-protoss-gone/" rel="bookmark" title="Permanent Link: 消失的神族">消失的神族</a></li><li><a href="http://yslove.net/2011/04/pcre-partterns-assertions/" rel="bookmark" title="Permanent Link: PCRE Partterns &#8211; Assertions">PCRE Partterns &#8211; Assertions</a></li></ul><hr /><small>Copyright &copy; 2010 by <a href="http://yslove.net">YSlove.net</a><br /><a href="http://yslove.net/2011/03/javascript-indexof/#comments" title="留言">欢迎留言</a> | 作者: <a href="" >YSjia</a> | 原文链接：<a href="http://yslove.net/2011/03/javascript-indexof/">http://yslove.net/2011/03/javascript-indexof/</a><br /><em>数字指纹 3abf2858e3aa210a1750056317836753 (38.107.179.207) </em></small>]]></content:encoded>
			<wfw:commentRss>http://yslove.net/2011/03/javascript-indexof/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ie6 javascript:void(0);</title>
		<link>http://yslove.net/2011/02/ie6-javascriptvoid0/</link>
		<comments>http://yslove.net/2011/02/ie6-javascriptvoid0/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 09:39:16 +0000</pubDate>
		<dc:creator>YSjia</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[实验室]]></category>
		<category><![CDATA[ie6]]></category>

		<guid isPermaLink="false">http://yslove.net/2011/02/ie6-javascriptvoid0/</guid>
		<description><![CDATA[遇到过几次这种问题，现在总结一下。 代码： &#60;a onclick=&#34;window.location.href='http://www.google.com'&#34; href=&#34;javascript:void(0);&#34;&#62;google&#60;/a&#62; 这段代码在主流的浏览器里面都没问题，但是在IE6下就会出现不能跳转的现象。 经过一翻排查，发现绑定的事件都会执行，是由于DOM本身的冒泡事件所以会最后执行href属性内的javascript:void(0);导致的。 a标签 a标签本来就是用来进行页面跳转的标签，其运行机制是告诉浏览器URL地址并且跳转。当然，我们可以在href属中直接执行javascript。 代码： &#60;a href=&#34;javascript:alert('Hello!');&#34;&#62;Say Hello&#60;/a&#62; Say Hello 这里由于javascript执行了alert函数，但是其返回的是null。所以a标签没有执行任何动作。 javascript:void(0); void(arg);可以理解为永远返回null的函数，但是其参数不能为空。其参数可以为任意的表达式甚至是函数。 代码： &#60;a href=&#34;javascript:void(name = 'will'); alert('Hello ' + name);&#34;&#62;Say Hello&#60;/a&#62; Say Hello 对IE6运行的猜想 IE6会先运行DOM本身绑定的事件，如onclick；如果没有阻止冒泡，则会顺序执行href属性。而void(0);正是不需要执行任何事件，则IE6告诉浏览器不执行任何事件（覆盖之前的动作），并且终止冒泡相当于return false;于是浏览器没有执行任何动作。 这样只要在onclick事件内阻止冒泡事件即可。 经过改进的代码为： &#60;a onclick=&#34;window.location.href='http://www.google.com' return false;&#34; href=&#34;javascript:void(0);&#34;&#62;google&#60;/a&#62; 这样在IE6下就可以正常运行了。 其他方法 当然可以不使用javascript:void(0);而改使用#也可以避免，href属性内的#本来的意思就是锚点#name所以当不指定任何锚时自然会到页面顶端并在URL后加入Hash symbol。 这里对于锚还有一个比较特殊的用法 当href属性的值是锚点时，但是又找不到该锚点，则相当于返回null，所以可以使用##来代替javascript:void(0); 当然前提是你的页面不要有锚点的名字是#的哟~ Copyright &#169; 2010 by YSlove.net欢迎留言 &#124; 作者: YSjia [...]]]></description>
			<content:encoded><![CDATA[<p>遇到过几次这种问题，现在总结一下。</p>
<p>代码：</p>
<pre> &lt;a onclick=&quot;window.location.href='http://www.google.com'&quot; href=&quot;javascript:void(0);&quot;&gt;google&lt;/a&gt;</pre>
<p>这段代码在主流的浏览器里面都没问题，但是在IE6下就会出现不能跳转的现象。</p>
<p>经过一翻排查，发现绑定的事件都会执行，是由于DOM本身的冒泡事件所以会最后执行href属性内的javascript:void(0);导致的。</p>
<p><strong>a标签</strong></p>
<p>a标签本来就是用来进行页面跳转的标签，其运行机制是告诉浏览器URL地址并且跳转。当然，我们可以在href属中直接执行javascript。</p>
<p>代码：</p>
<pre>&lt;a href=&quot;javascript:alert('Hello!');&quot;&gt;Say Hello&lt;/a&gt;</pre>
<p><a href="javascript:alert('Hello!');">Say Hello</a></p>
<p>这里由于javascript执行了alert函数，但是其返回的是null。所以a标签没有执行任何动作。</p>
<p><strong>javascript:void(0);</strong></p>
<p><code>void(arg);</code>可以理解为永远返回null的函数，但是其参数不能为空。其参数可以为任意的表达式甚至是函数。</p>
<p>代码：</p>
<pre>&lt;a href=&quot;javascript:void(name = 'will'); alert('Hello ' + name);&quot;&gt;Say Hello&lt;/a&gt;</pre>
<p><a href="javascript:void(name = 'will'); alert('Hello ' + name);">Say Hello</a></p>
<p><strong>对IE6运行的猜想</strong></p>
<p>IE6会先运行DOM本身绑定的事件，如onclick；如果没有阻止冒泡，则会顺序执行href属性。而void(0);正是不需要执行任何事件，则IE6告诉浏览器不执行任何事件（覆盖之前的动作），并且终止冒泡相当于return false;于是浏览器没有执行任何动作。</p>
<p>这样只要在onclick事件内阻止冒泡事件即可。</p>
<p>经过改进的代码为：</p>
<pre> &lt;a onclick=&quot;window.location.href='http://www.google.com' return false;&quot; href=&quot;javascript:void(0);&quot;&gt;google&lt;/a&gt;</pre>
<p>这样在IE6下就可以正常运行了。</p>
<p><strong>其他方法</strong></p>
<p>当然可以不使用javascript:void(0);而改使用#也可以避免，href属性内的#本来的意思就是锚点#name所以当不指定任何锚时自然会到页面顶端并在URL后加入Hash symbol。</p>
<p>这里对于锚还有一个比较特殊的用法</p>
<p>当href属性的值是锚点时，但是又找不到该锚点，则相当于返回null，所以可以使用##来代替javascript:void(0);</p>
<p>当然前提是你的页面不要有锚点的名字是#的哟~</p>
<hr /><small>Copyright &copy; 2010 by <a href="http://yslove.net">YSlove.net</a><br /><a href="http://yslove.net/2011/02/ie6-javascriptvoid0/#comments" title="留言">欢迎留言</a> | 作者: <a href="" >YSjia</a> | 原文链接：<a href="http://yslove.net/2011/02/ie6-javascriptvoid0/">http://yslove.net/2011/02/ie6-javascriptvoid0/</a><br /><em>数字指纹 3abf2858e3aa210a1750056317836753 (38.107.179.207) </em></small>]]></content:encoded>
			<wfw:commentRss>http://yslove.net/2011/02/ie6-javascriptvoid0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery UI组件开发</title>
		<link>http://yslove.net/2011/01/jquery-ui-widget-development/</link>
		<comments>http://yslove.net/2011/01/jquery-ui-widget-development/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 03:33:23 +0000</pubDate>
		<dc:creator>YSjia</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[实验室]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jQuery UI]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://yslove.net/2011/01/jquery-ui-widget-development/</guid>
		<description><![CDATA[对于jQuery大家都非常熟悉了，也许大家也早早就认识了jQuery UI，但是因为其可用的控件非常少所以放弃了，但是jQuery UI的设计与构造却是非常不错的。 基于Widget Factory的组件模式 从1.8版本开始jQuery UI把核心分为widget与core并且widget不依赖于core。 这样来讲，所有的组件都是基于Widget Factory所构建的，并且都继承于Widget Factory。 对于开发前端组件来说，需要更多的是一种规范，这种规范是可以让多人来合作的，并且对产出的组件有统一的编码风格与相同的基础方法。 Widget Bridge 如何实现把组件（Widget）与jQuery API相关联呢？ jQuery UI提供了$.widget.bridge方法。 其实如果了解设计模式的话，应该会想到Bridge Pattern&#160;中文详解 概念：【GOF95】在提出桥梁模式的时候指出，桥梁模式的用意是&#34;将抽象化(Abstraction)与实现化(Implementation)脱耦，使得二者可以独立地变化&#34;。这句话有三个关键词，也就是抽象化、实现化和脱耦。 如果细心的话，你可能会发现，$.widget.bridge的源码在处理event其实就是jQuery Plugin的编写建议。 所以jQuery UI就是规范化的jQuery Plugin组合。 详细介绍见其开发指导见 Developer Guide jQuery其实只是冰山一角，在你使用中，会发现有更多东西可以去挖掘也非常值得去深入的挖掘。 也许这些文章您也感兴趣:理解jQuery $.extend与$.fn.extend互动对于新的互联网至关重要Study jQuery in a Simplified Way [转载]记录 &#8211; 三年间为公司做了哪些事关于jQuery 不同选择器的性能比较[翻译][转载]Copyright &#169; 2010 by YSlove.net欢迎留言 &#124; 作者: YSjia &#124; 原文链接：http://yslove.net/2011/01/jquery-ui-widget-development/数字指纹 3abf2858e3aa210a1750056317836753 (38.107.179.207)]]></description>
			<content:encoded><![CDATA[<p>对于jQuery大家都非常熟悉了，也许大家也早早就认识了jQuery UI，但是因为其可用的控件非常少所以放弃了，但是jQuery UI的设计与构造却是非常不错的。</p>
<h3>基于Widget Factory的组件模式</h3>
<p>从1.8版本开始jQuery UI把核心分为widget与core并且widget不依赖于core。</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://gd.yslove.net/jQueryUI_F648/image.png" width="500" height="275" /> </p>
<p>这样来讲，所有的组件都是基于Widget Factory所构建的，并且都继承于Widget Factory。</p>
<p>对于开发前端组件来说，需要更多的是一种规范，这种规范是可以让多人来合作的，并且对产出的组件有统一的编码风格与相同的基础方法。</p>
<h3>Widget Bridge</h3>
<p>如何实现把组件（Widget）与jQuery API相关联呢？</p>
<p>jQuery UI提供了$.widget.bridge方法。</p>
<p>其实如果了解设计模式的话，应该会想到<a href="http://en.wikipedia.org/wiki/Bridge_pattern">Bridge Pattern</a>&#160;<a href="http://www.cnblogs.com/zhenyulu/articles/62720.html">中文详解</a></p>
<blockquote><p><strong>概念：</strong>【GOF95】在提出桥梁模式的时候指出，桥梁模式的用意是&quot;将抽象化(Abstraction)与实现化(Implementation)脱耦，使得二者可以独立地变化&quot;。这句话有三个关键词，也就是抽象化、实现化和脱耦。</p>
</blockquote>
<p>如果细心的话，你可能会发现，$.widget.bridge的源码在处理event其实就是<a href="http://docs.jquery.com/Plugins/Authoring#Events">jQuery Plugin</a>的编写建议。</p>
<p>所以jQuery UI就是规范化的jQuery Plugin组合。</p>
<p>详细介绍见其开发指导见 <a href="http://jqueryui.com/docs/Developer_Guide">Developer Guide</a></p>
<p>jQuery其实只是冰山一角，在你使用中，会发现有更多东西可以去挖掘也非常值得去深入的挖掘。</p>
<hr /><h2>也许这些文章您也感兴趣:</h2><ul><li><a href="http://yslove.net/2010/11/jquery-extend-and-fn-extend/" rel="bookmark" title="Permanent Link: 理解jQuery $.extend与$.fn.extend">理解jQuery $.extend与$.fn.extend</a></li><li><a href="http://yslove.net/2009/05/interaction-vital-to-the-new-internet/" rel="bookmark" title="Permanent Link: 互动对于新的互联网至关重要">互动对于新的互联网至关重要</a></li><li><a href="http://yslove.net/2010/02/study-jquery-in-a-simplified-way/" rel="bookmark" title="Permanent Link: Study jQuery in a Simplified Way [转载]">Study jQuery in a Simplified Way [转载]</a></li><li><a href="http://yslove.net/2011/06/3-years-in-globalmarket/" rel="bookmark" title="Permanent Link: 记录 &#8211; 三年间为公司做了哪些事">记录 &#8211; 三年间为公司做了哪些事</a></li><li><a href="http://yslove.net/2009/11/101-on-jquery-selector-performance/" rel="bookmark" title="Permanent Link: 关于jQuery 不同选择器的性能比较[翻译][转载]">关于jQuery 不同选择器的性能比较[翻译][转载]</a></li></ul><hr /><small>Copyright &copy; 2010 by <a href="http://yslove.net">YSlove.net</a><br /><a href="http://yslove.net/2011/01/jquery-ui-widget-development/#comments" title="留言">欢迎留言</a> | 作者: <a href="" >YSjia</a> | 原文链接：<a href="http://yslove.net/2011/01/jquery-ui-widget-development/">http://yslove.net/2011/01/jquery-ui-widget-development/</a><br /><em>数字指纹 3abf2858e3aa210a1750056317836753 (38.107.179.207) </em></small>]]></content:encoded>
			<wfw:commentRss>http://yslove.net/2011/01/jquery-ui-widget-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>理解jQuery $.extend与$.fn.extend</title>
		<link>http://yslove.net/2010/11/jquery-extend-and-fn-extend/</link>
		<comments>http://yslove.net/2010/11/jquery-extend-and-fn-extend/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 09:47:24 +0000</pubDate>
		<dc:creator>YSjia</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[实验室]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://yslove.net/2010/11/jquery-extend-and-fn-extend/</guid>
		<description><![CDATA[这两个方法一直都觉得挺难理解的，但是今天写程序时发现这两个方法的区别就在于$.extend是作用于一个object的静态方法（static method），而$.fn.extend是在作用于prototype的一个实例方法（instance method）。 构造jQuery时会实例化一个对象 // Define a local copy of jQuery var jQuery = function( selector, context ) { // The jQuery object is actually just the init constructor 'enhanced' return new jQuery.fn.init( selector, context ); }, 对于$.extend相当于对jQuery Object自身进行扩展。查看源码 ... } else if ( copy !== undefined ) { target[ name ] = copy; } [...]]]></description>
			<content:encoded><![CDATA[<p>这两个方法一直都觉得挺难理解的，但是今天写程序时发现这两个方法的区别就在于$.extend是作用于一个object的静态方法（static method），而$.fn.extend是在作用于prototype的一个实例方法（instance method）。</p>
<p>构造jQuery时会实例化一个对象</p>
<pre class="brush:jscript">// Define a local copy of jQuery
var jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context );
},</pre>
<p>对于$.extend相当于对jQuery Object自身进行扩展。<a href="https://github.com/jquery/jquery/blob/master/src/core.js#L368" target="_blank">查看源码</a></p>
<pre class="brush:jscript">...
} else if ( copy !== undefined ) {
target[ name ] = copy;
}
...</pre>
<p>而$.fn.extend相当于对jQuery prototype进行扩展。<a href="https://github.com/jquery/jquery/blob/master/src/core.js#L80" target="_blank">查看源码</a></p>
<pre class="brush:jscript">jQuery.fn = jQuery.prototype = {
...</pre>
<p>所以这样就很清晰了，对jQuery添加全局函数时使用$.extend，而对于插件侧使用$.fn.extend</p>
<hr /><h2>也许这些文章您也感兴趣:</h2><ul><li><a href="http://yslove.net/2010/02/study-jquery-in-a-simplified-way/" rel="bookmark" title="Permanent Link: Study jQuery in a Simplified Way [转载]">Study jQuery in a Simplified Way [转载]</a></li><li><a href="http://yslove.net/2011/04/wordpress-plugin-ys-lazyload/" rel="bookmark" title="Permanent Link: wordpress 插件 images lazyload">wordpress 插件 images lazyload</a></li><li><a href="http://yslove.net/2009/11/101-on-jquery-selector-performance/" rel="bookmark" title="Permanent Link: 关于jQuery 不同选择器的性能比较[翻译][转载]">关于jQuery 不同选择器的性能比较[翻译][转载]</a></li><li><a href="http://yslove.net/2011/01/jquery-ui-widget-development/" rel="bookmark" title="Permanent Link: jQuery UI组件开发">jQuery UI组件开发</a></li><li><a href="http://yslove.net/2009/05/interaction-vital-to-the-new-internet/" rel="bookmark" title="Permanent Link: 互动对于新的互联网至关重要">互动对于新的互联网至关重要</a></li></ul><hr /><small>Copyright &copy; 2010 by <a href="http://yslove.net">YSlove.net</a><br /><a href="http://yslove.net/2010/11/jquery-extend-and-fn-extend/#comments" title="留言">欢迎留言</a> | 作者: <a href="" >YSjia</a> | 原文链接：<a href="http://yslove.net/2010/11/jquery-extend-and-fn-extend/">http://yslove.net/2010/11/jquery-extend-and-fn-extend/</a><br /><em>数字指纹 3abf2858e3aa210a1750056317836753 (38.107.179.207) </em></small>]]></content:encoded>
			<wfw:commentRss>http://yslove.net/2010/11/jquery-extend-and-fn-extend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如何更好的使用jQuery？</title>
		<link>http://yslove.net/2010/11/how-to-better-use-jquery/</link>
		<comments>http://yslove.net/2010/11/how-to-better-use-jquery/#comments</comments>
		<pubDate>Wed, 03 Nov 2010 04:44:12 +0000</pubDate>
		<dc:creator>YSjia</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[实验室]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://yslove.net/2010/11/how-to-better-use-jquery/</guid>
		<description><![CDATA[选择器的优化 如何提高Sizzle选择器的性能? 不同的选择器引擎解析是不同的 测试地址：http://alexsexton.com/selectors/ 我们看到Sizzle的方法与querySelectorAll的方法是一至的 关于querySelectorAll请到MDC查看 下面是我们平常写jQuery时需要注意的： 左轻右重 bad div.grid2col .column better .grid2col td.column 尽量让左边只放一个选择器tag或者Class 如果需要tag.class这种选择器，最好放在右边 ID优先 bad $(&#8216;#item div.column&#8217;) better $(&#8216;#item&#8217;).find(&#8216;div.column&#8217;) 能简则简 bad div.grid2col .content .column better .grid2col .column DOM操作优化 尽量减少DOM操作 bad $.each(array, function(){ &#160;&#160; var li = &#8216;&#60;li&#62;&#8217; + item + &#8216;&#60;/li&#62;&#8217;; &#160;&#160; $(&#8216;#ballers&#8217;).append(li); }); better var frag = document.createDocumentFragment(); $.each(array, function(){ &#160;&#160; [...]]]></description>
			<content:encoded><![CDATA[<h2>选择器的优化</h2>
<p>如何提高Sizzle选择器的性能?</p>
<p>不同的选择器引擎解析是不同的</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="selector" border="0" alt="selector" src="http://gd.yslove.net/jQuery_A1D4/selector_thumb.png" width="524" height="312" /> </p>
<p>测试地址：<a href="http://alexsexton.com/selectors/" target="_blank">http://alexsexton.com/selectors/</a></p>
<p>我们看到Sizzle的方法与querySelectorAll的方法是一至的</p>
<p>关于querySelectorAll请到<a href="https://developer.mozilla.org/En/DOM/Document.querySelectorAll" target="_blank">MDC查看</a></p>
<p>下面是我们平常写jQuery时需要注意的：</p>
<p><strong>左轻右重</strong></p>
<p><strong><em><font color="#00ff80">bad</font></em></strong></p>
<p>div.grid2col .column</p>
<p><strong><em><font color="#00ff80">better</font></em></strong></p>
<p>.grid2col td.column</p>
<p>尽量让左边只放一个选择器tag或者Class</p>
<p>如果需要tag.class这种选择器，最好放在右边</p>
<p><strong>ID优先</strong></p>
<p><strong><em><font color="#00ff80">bad</font></em></strong></p>
<p>$(&#8216;#item div.column&#8217;)</p>
<p><strong><em><font color="#00ff80">better</font></em></strong></p>
<p>$(&#8216;#item&#8217;).find(&#8216;div.column&#8217;)</p>
<p><strong>能简则简</strong></p>
<p><strong><em><font color="#00ff80">bad</font></em></strong></p>
<p>div.grid2col .content .column</p>
<p><strong><em><font color="#00ff80">better</font></em></strong></p>
<p>.grid2col .column</p>
<h2>DOM操作优化</h2>
<p><strong>尽量减少DOM操作</strong></p>
<p><strong><em><font color="#00ff80">bad</font></em></strong></p>
<p>$.each(array, function(){ </p>
<p>&#160;&#160; var li = &#8216;&lt;li&gt;&#8217; + item + &#8216;&lt;/li&gt;&#8217;; </p>
<p>&#160;&#160; $(&#8216;#ballers&#8217;).append(li); </p>
<p>}); </p>
<p><strong><em><font color="#00ff80">better</font></em></strong></p>
<p>var frag = document.createDocumentFragment(); </p>
<p>$.each(array, function(){ </p>
<p>&#160;&#160; var li = &#8216;&lt;li&gt;&#8217; + item + &#8216;&lt;/li&gt;&#8217;; </p>
<p>&#160;&#160; frag.appendChild(li); </p>
<p>}); </p>
<p>$(&#8216;#ballers&#8217;)[0].appendChild(frag); </p>
<blockquote><p><a href="http://yslove.net/2010/04/jquery-html-rebuild/" target="_blank">jQuery自身HTML的方法</a>就很多地方用到<code>createDocumentFragment()</code></p>
</blockquote>
<p><strong><em><font color="#00ff80">or</font></em></strong></p>
<p>var tmphtml = &#8221;; </p>
<p>$.each(array, function(){ </p>
<p>&#160;&#160; tmphtml += &#8216;&lt;li&gt;&#8217; + item + &#8216;&lt;/li&gt;&#8217;; </p>
<p>}); </p>
<p>$(&#8216;#ballers&#8217;).html(tmphtml); </p>
<p><strong>哪里变化封装哪里</strong></p>
<p><strong><em><font color="#00ff80">bad</font></em></strong></p>
<p>if(t1.data(&#8216;active&#8217;) === &#8216;show&#8217;){ </p>
<p>&#160;&#160; t1.hide(); </p>
<p>} </p>
<p>if(t2.data(&#8216;active&#8217;) === &#8216;show&#8217;){ </p>
<p>&#160;&#160; t2.hide(); </p>
<p>} </p>
<p><strong><em><font color="#00ff80">better</font></em></strong></p>
<p>var elems = [t1, t2]; </p>
<p>$.each(elems, function(i, n){ </p>
<p>&#160;&#160; if(n.data(&#8216;active&#8217;) === &#8216;show&#8217;){ </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160; n.hide(); </p>
<p>&#160;&#160; } </p>
<p>}); </p>
<p>注意其中的“<strong>===</strong>”一般情况下都应该使用“<strong>===</strong>”而不是“<strong>==</strong>”。</p>
<p><strong>链式操作</strong></p>
<p><strong><em><font color="#00ff80">bad</font></em></strong></p>
<p>$(&#8216;body&#8217;).append(&#8216;&lt;div class=&#8217;button&#8217;&gt;&lt;/div&gt;&#8217;); </p>
<p>$(&#8216;div.button&#8217;).click(function(){&#8230;}); </p>
<p><strong><em><font color="#00ff80">better</font></em></strong></p>
<p>$(&#8216;div.button&#8217;) </p>
<p>&#160;&#160; .appendTo(&#8216;body&#8217;) </p>
<p>&#160;&#160; .click(function(){&#8230;}); </p>
<p> <strong>当需要大量操作DOM时需要先把它卸载</strong>
<p>var ul = $(&quot;#ul&quot;),</p>
<p>ulparent = ul.parent();</p>
<p>ul.detach();&#160; //<strong>1.4新方法</strong></p>
<p>ul.addLotsLi();</p>
<p>ulparent.append(ul);</p>
<p><strong>对条件判断的新方法</strong></p>
<p><strong><em><font color="#00ff80">通常</font></em></strong></p>
<p>if( type === &#8216;foo&#8217; || type === &#8216;bar&#8217;){}</p>
<p><strong><em><font color="#00ff80">高效</font></em></strong></p>
<p>if(&#160; /^(foo||bar)$/.test(type) ){}</p>
<p>if( ({foo:1,bar:1})[type] ){}</p>
<hr /><h2>也许这些文章您也感兴趣:</h2><ul><li><a href="http://yslove.net/2010/11/jquery-extend-and-fn-extend/" rel="bookmark" title="Permanent Link: 理解jQuery $.extend与$.fn.extend">理解jQuery $.extend与$.fn.extend</a></li><li><a href="http://yslove.net/2010/02/study-jquery-in-a-simplified-way/" rel="bookmark" title="Permanent Link: Study jQuery in a Simplified Way [转载]">Study jQuery in a Simplified Way [转载]</a></li><li><a href="http://yslove.net/2009/11/101-on-jquery-selector-performance/" rel="bookmark" title="Permanent Link: 关于jQuery 不同选择器的性能比较[翻译][转载]">关于jQuery 不同选择器的性能比较[翻译][转载]</a></li><li><a href="http://yslove.net/2011/01/jquery-ui-widget-development/" rel="bookmark" title="Permanent Link: jQuery UI组件开发">jQuery UI组件开发</a></li><li><a href="http://yslove.net/2009/05/interaction-vital-to-the-new-internet/" rel="bookmark" title="Permanent Link: 互动对于新的互联网至关重要">互动对于新的互联网至关重要</a></li></ul><hr /><small>Copyright &copy; 2010 by <a href="http://yslove.net">YSlove.net</a><br /><a href="http://yslove.net/2010/11/how-to-better-use-jquery/#comments" title="留言">欢迎留言</a> | 作者: <a href="" >YSjia</a> | 原文链接：<a href="http://yslove.net/2010/11/how-to-better-use-jquery/">http://yslove.net/2010/11/how-to-better-use-jquery/</a><br /><em>数字指纹 3abf2858e3aa210a1750056317836753 (38.107.179.207) </em></small>]]></content:encoded>
			<wfw:commentRss>http://yslove.net/2010/11/how-to-better-use-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript与SWF交互</title>
		<link>http://yslove.net/2010/07/javascriptyuswfjiaohu/</link>
		<comments>http://yslove.net/2010/07/javascriptyuswfjiaohu/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 08:51:00 +0000</pubDate>
		<dc:creator>YSjia</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[实验室]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://yslove.net/?p=674</guid>
		<description><![CDATA[最近在做Flash与Javascript上传控件，但是发现Flash还真是问题多多，现在总结一下，留备忘，有些是网上找来的，已经不知道作者是谁了&#8230; &#8230; Javascript和swf在网页中交互一般可有以下几种情况： 1.swf和这些调用的javascript在同域 2.swf和这些调用的javascript在不同域，比如加载远程的swf然后call别地方的服务 对于swf跨域call服务的问题，可同过crossdomain.xml配置解决。 但对于加载远程的swf，默认情况下，根本不能将里面的方法成功注册为向javascript公开的方法，一般会报此类错误： a) SecurityError: Error #2060: 安全沙箱冲突:ExternalInterface ,调用者 remote.com/test.swf(所加载的远程swf) 不能访问 127.0.0.1(本机的一个服务) at flash.external::ExternalInterface$/_initJS() at flash.external::ExternalInterface$/addCallback() &#8230; b) 错误： uncaught exception: Error calling method on NPObject! [plugin exception: Error in Actionscript. Use a try/catch block to find error.] 解决办法 对于a错误，是因为远程的swf加载到本地后没有权限去访问当前html文档，对于这个我们只需要在输出swf的时候设置 allowScriptAccess 属性，一般设置为always.即可解决。 对于b错误，是因为默认actionscript中不允许向将方法注册到不同域的 html文档中， 对于这个我们只需要在as中加一下代码即可解决： import flash.system.Security; Security.allowDomain(&#8220;*&#8221;); Security.allowInsecureDomain(&#8220;*&#8221;); Copyright &#169; [...]]]></description>
			<content:encoded><![CDATA[<p>最近在做Flash与Javascript上传控件，但是发现Flash还真是问题多多，现在总结一下，留备忘，有些是网上找来的，已经不知道作者是谁了&#8230; &#8230;</p>
<h3>Javascript和swf在网页中交互一般可有以下几种情况：</h3>
<p>1.swf和这些调用的javascript在同域</p>
<p>2.swf和这些调用的javascript在不同域，比如加载远程的swf然后call别地方的服务</p>
<p><strong>对于swf跨域call服务的问题，可同过crossdomain.xml配置解决。</strong></p>
<p>但对于加载远程的swf，默认情况下，根本不能将里面的方法成功注册为向javascript公开的方法，一般会报此类错误：</p>
<p>a) SecurityError: <strong>Error</strong> #2060: 安全沙箱冲突:ExternalInterface ,调用者 remote.com/test.swf(所加载的远程swf) 不能访问 127.0.0.1(本机的一个服务)</p>
<p>at flash.external::ExternalInterface$/_initJS()<br />
at flash.external::ExternalInterface$/addCallback()</p>
<p>&#8230;</p>
<p>b) 错误： uncaught exception: <strong>Error</strong> <strong>calling</strong> <strong>method</strong> <strong>on</strong> <strong>NPObject</strong>! [plugin exception: <strong>Error</strong> in Actionscript. Use a try/catch block to find <strong>error</strong>.]</p>
<p><strong>解决办法</strong></p>
<p>对于a错误，是因为远程的swf加载到本地后没有权限去访问当前html文档，对于这个我们只需要在输出swf的时候设置 allowScriptAccess 属性，一般设置为always.即可解决。</p>
<p>对于b错误，是因为默认actionscript中不允许向将方法注册到不同域的 html文档中， 对于这个我们只需要在as中加一下代码即可解决：</p>
<p>import flash.system.Security;</p>
<p>Security.allowDomain(&#8220;*&#8221;);<br />
Security.allowInsecureDomain(&#8220;*&#8221;);</p>
<hr /><small>Copyright &copy; 2010 by <a href="http://yslove.net">YSlove.net</a><br /><a href="http://yslove.net/2010/07/javascriptyuswfjiaohu/#comments" title="留言">欢迎留言</a> | 作者: <a href="" >YSjia</a> | 原文链接：<a href="http://yslove.net/2010/07/javascriptyuswfjiaohu/">http://yslove.net/2010/07/javascriptyuswfjiaohu/</a><br /><em>数字指纹 3abf2858e3aa210a1750056317836753 (38.107.179.207) </em></small>]]></content:encoded>
			<wfw:commentRss>http://yslove.net/2010/07/javascriptyuswfjiaohu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  yslove.net/tag/js/feed/ ) in 1.29692 seconds, on Feb 6th, 2012 at 9:53 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 6th, 2012 at 10:53 am UTC -->
