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

<channel>
	<title>风雪之隅 &#187; Js/CSS</title>
	<atom:link href="http://www.laruence.com/category/jscss/feed" rel="self" type="application/rss+xml" />
	<link>http://www.laruence.com</link>
	<description>PHP语言, PHP扩展, Zend引擎相关的研究,技术,新闻分享 - 左手代码 右手诗</description>
	<lastBuildDate>Wed, 08 Feb 2012 05:12:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>HTTP 204和205的应用</title>
		<link>http://www.laruence.com/2011/01/20/1844.html</link>
		<comments>http://www.laruence.com/2011/01/20/1844.html#comments</comments>
		<pubDate>Thu, 20 Jan 2011 04:18:28 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[PHP应用]]></category>
		<category><![CDATA[随笔]]></category>
		<category><![CDATA[204]]></category>
		<category><![CDATA[205]]></category>
		<category><![CDATA[http]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1844</guid>
		<description><![CDATA[之前和人讨论过这个问题,,, 今天感冒在家休息, 就回忆了一下, 整理如下.

    我们很多的应用在使用Ajax的时候, 大多数情况都是询问型操作,  比如提交数据, 则Ajax只是期待服务器返回:
<coolcode lang="javascript" linenum="off">
{status: 0, message:""} //status 0代表成功, 非零的时候, message中包含出错信息.
</coolcode>
]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2011/01/20/1844.html"  title="Permanet Link to HTTP 204和205的应用" >http://www.laruence.com/2011/01/20/1844.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>
    之前和人讨论过这个问题,,, 今天感冒在家休息, 就回忆了一下, 整理如下.</p>
<p>    我们很多的应用在使用Ajax的时候, 大多数情况都是询问型操作,  比如提交数据, 则Ajax只是期待服务器返回:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
{status: 0, message:&quot;&quot;} //status 0代表成功, 非零的时候, message中包含出错信息.
</pre>
<p>   我们知道HTTP的状态码, 2xx都是表示成功, 而HTTP的204(No Content)响应, 就表示执行成功, 但是没有数据, 浏览器不用刷新页面.也不用导向新的页面.</p>
<p>   在HTTP RFC 2616中关于204的描述如下:</p>
<blockquote><p>
If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent’s active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent’s active view.
</p></blockquote>
<p>   类似的还有205 Reset Content, 表示执行成功, 重置页面(Form表单).</p>
<blockquote><p>
The server has fulfilled the request and the user agent SHOULD reset the document view which caused the request to be sent. This response is primarily intended to allow input for actions to take place via user input, followed by a clearing of the form in which the input is given so that the user can easily initiate another input action.
</p></blockquote>
<p>  于是, 当有一些服务, 只是返回成功与否的时候,  可以尝试使用HTTP的状态码来作为返回信息, 而省掉多余的数据传输,  比如REST中的DELETE和如上所述的查询式Ajax请求.</p>
<p>  最后说说205, 205的意思是在接受了浏览器POST请求以后处理成功以后, 告诉浏览器, 执行成功了, 请清空用户填写的Form表单, 方便用户再次填写, </p>
<p>  总的来说, 204适合多次对一个Item进行更新, 而205则适合多次提交一个系列的Item.</p>
<p>  <b>但, 请注意, 目前还没有一个浏览器支持205, 大部分的浏览器, 都会把205当做204或者200同样对待.</b><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2011/01/20/1844.html" >2011/01/20</a>, <a href="http://www.xiaobaiblog.com"  rel="external nofollow"  class="url" >xiaobai</a> writes: 看到最后一句话，咋这么纠结呢……</li><li><a href="http://www.laruence.com/2011/01/20/1844.html" >2011/01/20</a>, <a href="http://jax-work-archive.blogspot.com/"  rel="external nofollow"  class="url" >weskerjax</a> writes: 400,401 也可以用來處理錯誤狀況
並可以用 responseText 來傳送錯誤訊息

對於成功訊息的處理我倒是沒有關注到
感謝你的文章</li><li><a href="http://www.laruence.com/2011/01/20/1844.html" >2011/01/24</a>, <a href="http://www.cnxct.com"  rel="external nofollow"  class="url" >cfc4n</a> writes: 用firebug调试ajax的时候，经常返回200，但firebug里看到的却是“加载源码失败”，不知道是不是跟这个有关。</li><li><a href="http://www.laruence.com/2011/01/20/1844.html" >2011/01/25</a>, <a href="http://blog.iterse.com"  rel="external nofollow"  class="url" >iterse's blog</a> writes: 比较纠结！
能帮我加个友链吗，谢谢！</li><li><a href="http://www.laruence.com/2011/01/20/1844.html" >2011/01/26</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @iterse done</li><li><a href="http://www.laruence.com/2011/01/20/1844.html" >2011/02/02</a>, <a href="http://blog.thinkinlamp.com/?p=672"  rel="external nofollow"  class="url" >Thinking In LAMP Blog &raquo; Blog Archive &raquo; PHP每月通讯（2011年2月）</a> writes: [...] http://www.laruence.com/2011/01/20/1844.html HTTP 204和205的应用 [...]</li><li><a href="http://www.laruence.com/2011/01/20/1844.html" >2011/03/19</a>, <a href="http://www.coridc.com"  rel="external nofollow"  class="url" >贝壳里的海</a> writes: 平时接触这两个状态不多，不是很懂</li><li><a href="http://www.laruence.com/2011/01/20/1844.html" >2011/04/11</a>, wclssdn writes: 不错.. 是不是也可以用其他的码呢? 比如.. 失败了.. 我给他个500- -!! 有空试试~~~</li><li><a href="http://www.laruence.com/2011/01/20/1844.html" >2011/04/12</a>, <a href="http://blog.jiandankuaile.com/archives/538"  rel="external nofollow"  class="url" >HTTP 204和205的应用 - 简单快乐，享受生活</a> writes: [...] 来源：http://www.laruence.com/2011/01/20/1844.html [...]</li><li><a href="http://www.laruence.com/2011/01/20/1844.html" >2011/04/24</a>, <a href="http://touchhappy.com/blog/archives/538"  rel="external nofollow"  class="url" >TouchHappy &raquo; HTTP 204 And 205</a> writes: [...] 来源：http://www.laruence.com/2011/01/20/1844.html  This entry was written by happy , posted on Tuesday April 12 2011at 08:04 pm , filed under Front-End Development, program . Bookmark the  permalink  . Post a comment below or leave a trackback&#058;  Trackback URL.     Leave a Reply  Click here to cancel reply. [...]</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Random Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2008/11/19/625.html"  title="让人无语的139邮箱" >让人无语的139邮箱</a></li><li><a href="http://www.laruence.com/2007/12/11/122.html"  title="Perl的特别之处" >Perl的特别之处</a></li><li><a href="http://www.laruence.com/2011/03/18/1916.html"  title="可序列化单例模式的遗留问题答案" >可序列化单例模式的遗留问题答案</a></li><li><a href="http://www.laruence.com/2011/12/29/2412.html"  title="通过构造Hash冲突实现各种语言的拒绝服务攻击" >通过构造Hash冲突实现各种语言的拒绝服务攻击</a></li><li><a href="http://www.laruence.com/2011/11/05/2262.html"  title="Yaf的性能对比测试" >Yaf的性能对比测试</a></li><li><a href="http://www.laruence.com/2008/07/18/124.html"  title="Dom事件的srcTarget,strElement探幽" >Dom事件的srcTarget,strElement探幽</a></li><li><a href="http://www.laruence.com/2011/07/02/2102.html"  title="Zend Parameters Parser新增类型描述符介绍" >Zend Parameters Parser新增类型描述符介绍</a></li><li><a href="http://www.laruence.com/2011/03/04/1894.html"  title="深入理解PHP内存管理之谁动了我的内存" >深入理解PHP内存管理之谁动了我的内存</a></li><li><a href="http://www.laruence.com/2010/05/13/1462.html"  title="Javascript原型链和原型的一个误区" >Javascript原型链和原型的一个误区</a></li><li><a href="http://www.laruence.com/2008/07/28/210.html"  title="关于JavaScript的执行域,标识符解析,闭包的研究" >关于JavaScript的执行域,标识符解析,闭包的研究</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2011/01/20/1844.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Javascript原型链和原型的一个误区</title>
		<link>http://www.laruence.com/2010/05/13/1462.html</link>
		<comments>http://www.laruence.com/2010/05/13/1462.html#comments</comments>
		<pubDate>Thu, 13 May 2010 15:52:09 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[__proto__]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1462</guid>
		<description><![CDATA[之前我对Javascript的原型链中, 原型继承与标识符查找有些迷惑, 

    如, 如下的代码:
<coolcode lang="javascript" linenum="off">
function Foo() {};
var foo = new Foo();
Foo.prototype.label = "laruence";
alert(foo.label); //output: laruence
alert(Foo.label);//output: undefined
</coolcode>]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2010/05/13/1462.html"  title="Permanet Link to Javascript原型链和原型的一个误区" >http://www.laruence.com/2010/05/13/1462.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>
    之前我对Javascript的原型链中, 原型继承与标识符查找有些迷惑, </p>
<p>    如, 如下的代码:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
function Foo() {};
var foo = new Foo();
Foo.prototype.label = &quot;laruence&quot;;
alert(foo.label); //output: laruence
alert(Foo.label);//output: undefined
</pre>
<p>    今天看到了如下这个图:<br/>
<div id="attachment_1463"  class="wp-caption aligncenter"  style="width: 621px" ><a href="http://laruence-wordpress.stor.sinaapp.com/uploads/javascript_object_layout.jpg" ><img src="http://laruence-wordpress.stor.sinaapp.com/uploads/javascript_object_layout.jpg"  alt="Javascript object layout"  title="javascript_object_layout"  width="611"  height="760"  class="size-full wp-image-1463" /></a><p class="wp-caption-text" >Javascript object layout</p></div></p>
<p>    另外, 在<a href="http://www.mollypages.org/misc/js.mp"  target="_blank" >Javascript Object Hierarchy</a>看到: </p>
<blockquote><p>
   The prototype is only used for properties inherited by objects/instances created by that function. The function itself does not use the associated prototype.
</p></blockquote>
<p>    也就是说, 函数对象的prototype并不作用于原型链查找过程中, </p>
<p>    今天在firefox下发现(因为firefox通过__proto__暴露了[[prototype]]), 真正参与标识符查找的是函数对象的__proto__, </p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
function Foo() {};
var foo = new Foo();
Foo.__proto__.label = &quot;laruence&quot;;
alert(Foo.label); //output: laruence
alert(foo.label);//output: undefined
</pre>
<p>     而, 显然的:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
function Foo() {};
alert(Foo.__proto__ === Foo.prototype); //output: false
</pre>
<p>     另外, 也解释了, </p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
alert(Object.forEach); // undefined

Function.prototype.forEach = function(object, block, context) {
    for (var key in object) {
        if (typeof this.prototype[key] == &quot;undefined&quot;) {
            block.call(context, object[key], key, object);
        }
    }

};

alert(Object.forEach);
alert(Function.forEach);
alert(Object.forEach === Function.forEach); // true
</pre>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/05/13/1462.html" >2010/05/14</a>, <a href="http://www.jaceju.net/blog/?p=1139"  rel="external nofollow"  class="url" >網站製作學習誌 &raquo; [Web] 連結分享</a> writes: [...] Javascript原型链和原型的一个误区 [...]</li><li><a href="http://www.laruence.com/2010/05/13/1462.html" >2010/05/21</a>, 牛 writes: 牛牛牛牛牛</li><li><a href="http://www.laruence.com/2010/05/13/1462.html" >2010/07/02</a>, J writes: 你好，想请教一个问题。


	var A = (window.getSelection)?window.getSelection():document.selection;
	if(!A) {
		return NULL;
	}
	var B = (A.rangeCount&gt;0)?A.getRangeAt(0):A.createRange()
	//alert(A.rangeCount&gt;0);
	obj.currPos = B.duplicate();
	if (obj.currPos) {
		//alert(obj.currPos.htmlText);
		//obj.currPos.text = str
		obj.currPos.htmlText = str //!!!!!!!!!!!!!

	}
	else {obj.innerHTML+=str}//直接把参数str的值添加到对象obj的值后面 


为什么在obj.currPos.htmlText会报doesn't support this action这个错呢？alert()的时候却没有报错。</li><li><a href="http://www.laruence.com/2010/05/13/1462.html" >2010/07/16</a>, <a href="http://dothing"  rel="external nofollow"  class="url" >lake</a> writes: 这图有点乱，我推荐这幅图
http://images.cnblogs.com/cnblogs_com/riccc/js/js_object_model.jpg
出自文章
http://www.cnblogs.com/RicCC/archive/2008/02/15/JavaScript-Object-Model-Execution-Model.html

当年看到这幅图，豁然开朗，希望对你有帮助</li><li><a href="http://www.laruence.com/2010/05/13/1462.html" >2010/10/14</a>, Anonymous writes: f.prototype = obj;
fo = new f;
fo的__proto__链存在obj</li><li><a href="http://www.laruence.com/2010/05/13/1462.html" >2011/01/14</a>, <a href="http://www.skygq.com"  rel="external nofollow"  class="url" >jQuery教程</a> writes: 关于javascript的机制，老兄是相当的了解呀~~
学习了~~
现在我正在慢慢补充这方面的知识~~</li><li><a href="http://www.laruence.com/2010/05/13/1462.html" >2011/03/20</a>, <a href="http://www.w3hacker.com/?p=255"  rel="external nofollow"  class="url" >Javascript原型链和原型的一个误区 | 万维网黑客联盟</a> writes: [...] 本文地址: http://www.laruence.com/2010/05/13/1462.html [...]</li></ul><hr/><h2>Related posts:</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/08/09/1036.html"  rel="bookmark"  title="Permanent Link: 正确使用JS中的正则" >正确使用JS中的正则</a></li><li><a href="http://www.laruence.com/2008/09/01/492.html"  rel="bookmark"  title="Permanent Link: Js处理Json的&#8221;invalid label&#8221;错" >Js处理Json的&#8221;invalid label&#8221;错</a></li><li><a href="http://www.laruence.com/2009/09/08/1076.html"  rel="bookmark"  title="Permanent Link: 深入理解Javascript之this关键字" >深入理解Javascript之this关键字</a></li><li><a href="http://www.laruence.com/2009/05/06/758.html"  rel="bookmark"  title="Permanent Link: 图片上传即时显示缩略图解决方法" >图片上传即时显示缩略图解决方法</a></li><li><a href="http://www.laruence.com/2009/05/28/863.html"  rel="bookmark"  title="Permanent Link: Javascript作用域原理" >Javascript作用域原理</a></li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2012/01/07/2453.html"  title="2012年1月全球www网站技术报告" >2012年1月全球www网站技术报告</a></li><li><a href="http://www.laruence.com/2010/01/21/1254.html"  title="IE下var的重要性的又一佐证" >IE下var的重要性的又一佐证</a></li><li><a href="http://www.laruence.com/2009/09/27/1123.html"  title="关于Javascript的俩个有趣的探讨" >关于Javascript的俩个有趣的探讨</a></li><li><a href="http://www.laruence.com/2009/09/23/1089.html"  title="深入理解JavaScript定时机制" >深入理解JavaScript定时机制</a></li><li><a href="http://www.laruence.com/2009/09/08/1076.html"  title="深入理解Javascript之this关键字" >深入理解Javascript之this关键字</a></li><li><a href="http://www.laruence.com/2009/08/09/1036.html"  title="正确使用JS中的正则" >正确使用JS中的正则</a></li><li><a href="http://www.laruence.com/2009/05/28/863.html"  title="Javascript作用域原理" >Javascript作用域原理</a></li><li><a href="http://www.laruence.com/2009/05/18/809.html"  title="使用JS做文档处理" >使用JS做文档处理</a></li><li><a href="http://www.laruence.com/2009/05/17/815.html"  title="关于事件模拟" >关于事件模拟</a></li><li><a href="http://www.laruence.com/2008/09/01/492.html"  title="Js处理Json的&#8221;invalid label&#8221;错" >Js处理Json的&#8221;invalid label&#8221;错</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2010/05/13/1462.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>IE下var的重要性的又一佐证</title>
		<link>http://www.laruence.com/2010/01/21/1254.html</link>
		<comments>http://www.laruence.com/2010/01/21/1254.html#comments</comments>
		<pubDate>Thu, 21 Jan 2010 04:43:07 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[var]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1254</guid>
		<description><![CDATA[ 一个朋友问了一个js问题, 一段看不出有任何问题的代码, 在ie下报错:"object doesn't support this property or method".
 <coolcode lang="javascript" linenum="off">
function foo(obj) {
   productTree = obj.toString();
   document.getElementById('productTree').innerHTML = productTree;
} 
</coolcode>
</p>]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2010/01/21/1254.html"  title="Permanet Link to IE下var的重要性的又一佐证" >http://www.laruence.com/2010/01/21/1254.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>
   一个朋友问了一个js问题, 一段看不出有任何问题的代码, 在ie下报错:&#8221;object doesn&#8217;t support this property or method&#8221;.</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
function foo(obj) {
   productTree = obj.toString();
   document.getElementById('productTree').innerHTML = productTree;
}
</pre>
<p>    开始, 还以为错误是指obj的toString方法, 绕了半天弯路, 无果..</p>
<p>    后来,注意到变量名是productTree没有用var申明, 加上getElementById(&#8216;productTree&#8217;)说明有个id为productTree的元素, 并且我们知道在IE下可以直接通过id获取DOM元素的引用, so~</p>
<p>    所以啊, 局部变量一定要用var申明, 不仅仅是因为不用var会成全局变量, 更因为在IE下, 有可能会出现这种, 让人很莫名的错误&#8230;.
</p>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/01/21/1254.html" >2010/01/21</a>, rzhome writes: 在IE下就是这样的痛苦，不过加var来声明变量应该规范点。</li><li><a href="http://www.laruence.com/2010/01/21/1254.html" >2010/01/21</a>, yangliang writes: 难道window下的所有变量ie都认为是dom咯，该死的ie</li><li><a href="http://www.laruence.com/2010/01/21/1254.html" >2010/01/22</a>, janpoem writes: 这是ie的老问题了，应该规范使用var声明变量。</li><li><a href="http://www.laruence.com/2010/01/21/1254.html" >2010/12/13</a>, mark35 writes: 据统计各种语言代码中中出现fuc..k词语频率是JS最高。因为IE系列的存在。呵呵。</li><li><a href="http://www.laruence.com/2010/01/21/1254.html" >2011/03/20</a>, <a href="http://www.w3hacker.com/?p=253"  rel="external nofollow"  class="url" >IE下var的重要性的又一佐证 | 万维网黑客联盟</a> writes: [...] 本文地址: http://www.laruence.com/2010/01/21/1254.html [...]</li><li><a href="http://www.laruence.com/2010/01/21/1254.html" >2011/04/25</a>, kgh writes: JavaScript 是一门灵活的语言，但往往越是灵活就越是容易出错！有些东西还是强制规范好些的！</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2008/07/11/108.html"  title="IE下的Javascript调试利器:Companion.js" >IE下的Javascript调试利器:Companion.js</a></li><li><a href="http://www.laruence.com/2012/01/07/2453.html"  title="2012年1月全球www网站技术报告" >2012年1月全球www网站技术报告</a></li><li><a href="http://www.laruence.com/2010/05/13/1462.html"  title="Javascript原型链和原型的一个误区" >Javascript原型链和原型的一个误区</a></li><li><a href="http://www.laruence.com/2010/04/12/1394.html"  title="IE下pre标签的InnerHTML问题" >IE下pre标签的InnerHTML问题</a></li><li><a href="http://www.laruence.com/2009/09/27/1123.html"  title="关于Javascript的俩个有趣的探讨" >关于Javascript的俩个有趣的探讨</a></li><li><a href="http://www.laruence.com/2009/09/23/1089.html"  title="深入理解JavaScript定时机制" >深入理解JavaScript定时机制</a></li><li><a href="http://www.laruence.com/2009/09/08/1076.html"  title="深入理解Javascript之this关键字" >深入理解Javascript之this关键字</a></li><li><a href="http://www.laruence.com/2009/08/09/1036.html"  title="正确使用JS中的正则" >正确使用JS中的正则</a></li><li><a href="http://www.laruence.com/2009/05/28/863.html"  title="Javascript作用域原理" >Javascript作用域原理</a></li><li><a href="http://www.laruence.com/2009/05/18/809.html"  title="使用JS做文档处理" >使用JS做文档处理</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2010/01/21/1254.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>关于Javascript的俩个有趣的探讨</title>
		<link>http://www.laruence.com/2009/09/27/1123.html</link>
		<comments>http://www.laruence.com/2009/09/27/1123.html#comments</comments>
		<pubDate>Sun, 27 Sep 2009 10:54:44 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[事件处理]]></category>
		<category><![CDATA[性能]]></category>
		<category><![CDATA[正则]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1123</guid>
		<description><![CDATA[1. 关于事件处理函数引用的一个佐证

2. Javascript正则的效率问题]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2009/09/27/1123.html"  title="Permanet Link to 关于Javascript的俩个有趣的探讨" >http://www.laruence.com/2009/09/27/1123.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>
  <b> 首先祝贺在经历了几乎一天的等待以后. 我的空间商终于把服务器迁到了电信机房, 外加网通CDN加速. </b></p>
<h3>关于事件处理函数引用的一个佐证</h3>
<p>   之前, 我在分析Javascript的This关键字的时候, 说过, 当使用inline的方式写dom元素的事件处理函数的时候, 采用的是引用的方式. 刚好nullbyte童鞋给我提供了一个很有意思的Case:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;img id=&quot;foo&quot; src=&quot;xxx&quot; onerror=&quot; alert('error');
    } function foobar() {
          alert('www.laruence.com'); &quot; /&gt;
&lt;script&gt;
alert(document.getElementById(&quot;foo&quot;).onerror);
&lt;/script&gt;
</pre>
<p>    在IE下试试看..</p>
<p>    不过, FF和Chrome下都不行, 应该是FF和Chrome都会验证html代码的合法性.
</p>
<p><h3>Javascript正则的效率</h3>
<p>   如果你看到有人写Javascript的trim的时候采用了循环的方式,而不是正则的方式, 请不要笑. 人家这可是经验所致, 考虑如下代码的执行时间会是多少?</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
var matchs = /^(a+)+$/.exec(&quot;aaaaaaaaaaaaaaaaaaaaaaaaaaaX&quot;);
alert(matchs);
</pre>
<p>   告诉你吧&#8230;. 注:以下结果来自看手表估测, 但不影响时间的长度性&#8230;另外jsmore的stauren同学也验证了这一结论:</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
IE8: 30秒
FF3: 28秒
号称目前最快的采用V8引擎的Chrome: 8秒.
</pre>
<p>   这个结果,,,是多么的不可接受啊? 具体原因的分析, 在master regular expression里面有提到过.</p>
<blockquote><p>
NFA和DFA的引擎是有区别的。js/perl/php/java/.net都是NFA引擎。<br/>
而DFA与NFA机制上的不同带来5个影响：<br/>
1. DFA对于文本串里的每一个字符只需扫描一次，比较快，但特性较少；NFA要翻来覆去吃字符、吐字符，速度慢，但是特性丰富，所以反而应用广泛，当今主要的正则表达式引擎，如Perl、Ruby、Python的re模块、Java和.NET的regex库，都是NFA的。<br/>
2. 只有NFA才支持lazy和backreference（后向引用）等特性；<br/>
3. NFA急于邀功请赏，所以最左子正则式优先匹配成功，因此偶尔会错过最佳匹配结果；DFA则是“最长的左子正则式优先匹配成功”。<br/>
4. NFA缺省采用greedy量词(就是对于/.*/、/\w+/这样的“重复n”次的模式，以贪婪方式进行，尽可能匹配更多字符，直到不得以罢手为止)，NFA会优先匹配量词。<br/>
5. NFA可能会陷入递归调用的陷阱而表现得性能极差。</p>
<p>backtracking（回朔）<br/>
当NFA发现自己吃多了，一个一个往回吐，边吐边找匹配，这个过程叫做backtracking。由于存在这个过程，在NFA匹配过程中，特别是在编写不合理的正则式匹配过程中，文本被反复扫描，效率损失是不小的。明白这个道理，对于写出高效的正则表达式很有帮助。
</p></blockquote>
<p>而对于Javascript中的正则来说, 应该是优先匹配量词, 导致了很深的递归, 形成了性能问题&#8230;
</p>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/09/27/1123.html" >2009/09/27</a>, <a href="http://www.phpfans.org"  rel="external nofollow"  class="url" >深空</a> writes: 没看明白要匹配什么？应该也是尽可能多的匹配a，但是因为最后一个是X，所以打印出null，厄，直接写a+不就行了，在PHP里很快，呵呵。</li><li><a href="http://www.laruence.com/2009/09/27/1123.html" >2009/09/28</a>, cjj writes: 呵呵 好的正则 才能让正则有好的性能</li><li><a href="http://www.laruence.com/2009/09/27/1123.html" >2009/09/28</a>, yuehei writes: 测试了一下，果然很慢。。以后少用正则，
可是为什么测试的正则要有两个+号呢
 /^(a+)$/.exec("aaaaaaaaaaaaaaaaaaaaaaaaaaaX");

一个加号倒是很快。。</li><li><a href="http://www.laruence.com/2009/09/27/1123.html" >2009/09/28</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @cjj 有理, 正则也是一门独立的艺术.</li><li><a href="http://www.laruence.com/2009/09/27/1123.html" >2009/10/01</a>, <a href="www.phppan.com"  rel="external nofollow"  class="url" >phppan</a> writes: 首先，恭喜
然后，国庆快乐
最后，虽然把精通正则表达式看过了，但是对此的了解依然不够。学习了</li><li><a href="http://www.laruence.com/2009/09/27/1123.html" >2009/10/12</a>, toms writes: 求求大侠能不能帮我看个js问题啊，问题如下

有两个页面a, b 其中a为表单页面b为数据接收页面

a中的数据表单使用onsubmit事件验证客户端数据有效性， 但如果我在服务器（页面b）上检测到提交上来的数据不符合要求， 我使用history.go(-1), 返回前一个页面后， 在页面a数据表单无法提交（没有报任何js错误）， 在表单内回车和点“submit”均无法提交表单， 经检查发现在b页面history.go(-1)回到a页面后， onsubmit事件无法响应， 此问题仅在firefox下出现， 并且firebug和错误控制台均未报出任何js错误，第一次提交的时候所有js都正常运行了的</li><li><a href="http://www.laruence.com/2009/09/27/1123.html" >2009/10/12</a>, toms writes: b页面history.go(-1)后， a页面onsubmit事件里的任何东西都无法执行， 排除了验证函数错误</li><li><a href="http://www.laruence.com/2009/09/27/1123.html" >2009/10/13</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @toms sorry, 我没有重现出来, 你能把你的代码mail到我的yahoo邮箱么?</li><li><a href="http://www.laruence.com/2009/09/27/1123.html" >2009/10/16</a>, <a href="http://www.xidea.org"  rel="external nofollow"  class="url" >jindw</a> writes: 够诡异，够专业。</li><li><a href="http://www.laruence.com/2009/09/27/1123.html" >2009/10/26</a>, <a href="http://www.pigblog.net"  rel="external nofollow"  class="url" >Cherry</a> writes: 你的JS也是如此的牛啊</li><li><a href="http://www.laruence.com/2009/09/27/1123.html" >2011/03/20</a>, <a href="http://www.w3hacker.com/?p=260"  rel="external nofollow"  class="url" >关于Javascript的俩个有趣的探讨 | 万维网黑客联盟</a> writes: [...] 本文地址: http://www.laruence.com/2009/09/27/1123.html [...]</li><li><a href="http://www.laruence.com/2009/09/27/1123.html" >2011/04/17</a>, piapai writes: 第二段代码，我自己在火狐4.0和chrome10的版本中测试了一下，ff会报错，错误如下：regular expression too complex</li><li><a href="http://www.laruence.com/2009/09/27/1123.html" >2011/10/20</a>, sking7 writes: 特别想知道ie和火狐，chome对那句正则如何进行匹配的，算法是怎样的？</li></ul><hr/><h2>Related posts:</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2008/07/28/210.html"  rel="bookmark"  title="Permanent Link: 关于JavaScript的执行域,标识符解析,闭包的研究" >关于JavaScript的执行域,标识符解析,闭包的研究</a></li><li><a href="http://www.laruence.com/2009/04/09/674.html"  rel="bookmark"  title="Permanent Link: 关于Javascript的作用域链的几句话" >关于Javascript的作用域链的几句话</a></li><li><a href="http://www.laruence.com/2007/11/15/10.html"  rel="bookmark"  title="Permanent Link: 一个误区（关于javascript的字符串拼接)" >一个误区（关于javascript的字符串拼接)</a></li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/08/09/1036.html"  title="正确使用JS中的正则" >正确使用JS中的正则</a></li><li><a href="http://www.laruence.com/2012/01/07/2453.html"  title="2012年1月全球www网站技术报告" >2012年1月全球www网站技术报告</a></li><li><a href="http://www.laruence.com/2011/12/30/2435.html"  title="PHP数组的Hash冲突实例" >PHP数组的Hash冲突实例</a></li><li><a href="http://www.laruence.com/2011/09/30/2179.html"  title="PHP正则之递归匹配" >PHP正则之递归匹配</a></li><li><a href="http://www.laruence.com/2010/05/13/1462.html"  title="Javascript原型链和原型的一个误区" >Javascript原型链和原型的一个误区</a></li><li><a href="http://www.laruence.com/2010/01/21/1254.html"  title="IE下var的重要性的又一佐证" >IE下var的重要性的又一佐证</a></li><li><a href="http://www.laruence.com/2009/10/15/1131.html"  title="提升PHP性能之改变Zend引擎分发方式" >提升PHP性能之改变Zend引擎分发方式</a></li><li><a href="http://www.laruence.com/2009/09/23/1089.html"  title="深入理解JavaScript定时机制" >深入理解JavaScript定时机制</a></li><li><a href="http://www.laruence.com/2009/09/08/1076.html"  title="深入理解Javascript之this关键字" >深入理解Javascript之this关键字</a></li><li><a href="http://www.laruence.com/2009/05/28/863.html"  title="Javascript作用域原理" >Javascript作用域原理</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/09/27/1123.html/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>深入理解JavaScript定时机制</title>
		<link>http://www.laruence.com/2009/09/23/1089.html</link>
		<comments>http://www.laruence.com/2009/09/23/1089.html#comments</comments>
		<pubDate>Wed, 23 Sep 2009 07:18:28 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[转载]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[setinterval]]></category>
		<category><![CDATA[settimeout]]></category>
		<category><![CDATA[单线程]]></category>
		<category><![CDATA[原理]]></category>
		<category><![CDATA[定时器]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1089</guid>
		<description><![CDATA[<pre class="sh_javascript">
setTimeout(function() {
    alert('你好!');
}, 0);
setInterval(callbackFunction, 100);
</pre>

认为setTimeout中的问候方法会立即被执行,因为这并不是凭空而说,而是JavaScript API文档明确定义第二个参数意义为隔多少毫秒后,回调方法就会被执行. 这里设成0毫秒,理所当然就立即被执行了.
同理对setInterval的callbackFunction方法每间隔100毫秒就立即被执行深信不疑!

但随着JavaScript应用开发经验不断的增加和丰富,有一天你发现了一段怪异的代码而百思不得其解.....]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>本文地址: <a href="http://www.laruence.com/2009/09/23/1089.html"  title="Permanet Link to 深入理解JavaScript定时机制" >http://www.laruence.com/2009/09/23/1089.html</a></li>
<li>转载文章</li>
</ul></div>
<p>转帖地址:<a href="http://www.9demo.com/archives/341" >http://www.9demo.com/archives/341</a></p>
<p>容易欺骗别人感情的JavaScript定时器</p>
<p>JavaScript的setTimeout与setInterval是两个很容易欺骗别人感情的方法,因为我们开始常常以为调用了就会按既定的方式执行, 我想不少人都深有同感, 例如</p>
<pre class="sh_javascript"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
setTimeout(function() {
    alert('你好!');
}, 0);
setInterval(callbackFunction, 100);
</pre>
<p>认为setTimeout中的问候方法会立即被执行,因为这并不是凭空而说,而是JavaScript API文档明确定义第二个参数意义为隔多少毫秒后,回调方法就会被执行. 这里设成0毫秒,理所当然就立即被执行了.<br/>
同理对setInterval的callbackFunction方法每间隔100毫秒就立即被执行深信不疑!</p>
<p>但随着JavaScript应用开发经验不断的增加和丰富,有一天你发现了一段怪异的代码而百思不得其解:</p>
<pre class="sh_javascript"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
div.onclick = function(){
        setTimeout(function() {
                document.getElementById('inputField').focus();
        }, 0);
};
</pre>
<p>既然是0毫秒后执行,那么还用setTimeout干什么, 此刻, 坚定的信念已开始动摇.</p>
<p>直到最后某一天 , 你不小心写了一段糟糕的代码:</p>
<pre class="sh_javascript"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
setTimeout(function() {
        while (true) {
        }
}, 100);
setTimeout(function() {
        alert('你好!');
}, 200);
setInterval(callbackFunction, 200);
</pre>
<p>第一行代码进入了死循环,但不久你就会发现,第二,第三行并不是预料中的事情,alert问候未见出现,callbacKFunction也杳无音讯!</p>
<p>这时你彻底迷惘了,这种情景是难以接受的,因为改变长久以来既定的认知去接受新思想的过程是痛苦的,但情事实摆在眼前,对JavaScript真理的探求并不会因为痛苦而停止,下面让我们来展开JavaScript线程和定时器探索之旅!</p>
<p>拔开云雾见月明</p>
<p>出现上面所有误区的最主要一个原因是:潜意识中认为,JavaScript引擎有多个线程在执行,JavaScript的定时器回调函数是异步执行的.</p>
<p>而事实上的,JavaScript使用了障眼法,在多数时候骗过了我们的眼睛,这里背光得澄清一个事实:</p>
<p>JavaScript引擎是单线程运行的,浏览器无论在什么时候都只且只有一个线程在运行JavaScript程序.</p>
<p>JavaScript引擎用单线程运行也是有意义的,单线程不必理会线程同步这些复杂的问题,问题得到简化.</p>
<p>那么单线程的JavaScript引擎是怎么配合浏览器内核处理这些定时器和响应浏览器事件的呢?<br/>
下面结合浏览器内核处理方式简单说明.</p>
<p>浏览器内核实现允许多个线程异步执行,这些线程在内核制控下相互配合以保持同步.假如某一浏览器内核的实现至少有三个常驻线程:javascript引擎线程,界面渲染线程,浏览器事件触发线程,除些以外,也有一些执行完就终止的线程,如Http请求线程,这些异步线程都会产生不同的异步事件,下面通过一个图来阐明单线程的JavaScript引擎与另外那些线程是怎样互动通信的.虽然每个浏览器内核实现细节不同,但这其中的调用原理都是大同小异.</p>
<div id="attachment_1090"  class="wp-caption aligncenter"  style="width: 510px" ><a href="http://laruence-wordpress.stor.sinaapp.com/uploads/jstimer.jpg" ><img src="http://laruence-wordpress.stor.sinaapp.com/uploads/jstimer.jpg"  alt="Js线程图示"  title="jstimer"  width="500"  height="272"  class="size-full wp-image-1090" /></a><p class="wp-caption-text" >Js线程图示</p></div>
<p>由图可看出,浏览器中的JavaScript引擎是基于事件驱动的,这里的事件可看作是浏览器派给它的各种任务,这些任务可以源自JavaScript引擎当前执行的代码块,如调用setTimeout添加一个任务,也可来自浏览器内核的其它线程,如界面元素鼠标点击事件,定时触发器时间到达通知,异步请求状态变更通知等.从代码角度看来任务实体就是各种回调函数,JavaScript引擎一直等待着任务队列中任务的到来.由于单线程关系,这些任务得进行排队,一个接着一个被引擎处理.</p>
<p>上图t1-t2..tn表示不同的时间点,tn下面对应的小方块代表该时间点的任务,假设现在是t1时刻,引擎运行在t1对应的任务方块代码内,在这个时间点内,我们来描述一下浏览器内核其它线程的状态.</p>
<p>t1时刻:</p>
<p>GUI渲染线程:</p>
<p>该线程负责渲染浏览器界面HTML元素,当界面需要重绘(Repaint)或由于某种操作引发回流(reflow)时,该线程就会执行.本文虽然重点解释JavaScript定时机制,但这时有必要说说渲染线程,因为该线程与JavaScript引擎线程是互斥的,这容易理解,因为JavaScript脚本是可操纵DOM元素,在修改这些元素属性同时渲染界面,那么渲染线程前后获得的元素数据就可能不一致了.</p>
<p>在JavaScript引擎运行脚本期间,浏览器渲染线程都是处于挂起状态的,也就是说被”冻结”了.</p>
<p>所以,在脚本中执行对界面进行更新操作,如添加结点,删除结点或改变结点的外观等更新并不会立即体现出来,这些操作将保存在一个队列中,待JavaScript引擎空闲时才有机会渲染出来.</p>
<p>GUI事件触发线程:</p>
<p>JavaScript脚本的执行不影响html元素事件的触发,在t1时间段内,首先是用户点击了一个鼠标键,点击被浏览器事件触发线程捕捉后形成一个鼠标点击事件,由图可知,对于JavaScript引擎线程来说,这事件是由其它线程异步传到任务队列尾的,由于引擎正在处理t1时的任务,这个鼠标点击事件正在等待处理.</p>
<p>定时触发线程:</p>
<p>注意这里的浏览器模型定时计数器并不是由JavaScript引擎计数的,因为JavaScript引擎是单线程的,如果处于阻塞线程状态就计不了时,它必须依赖外部来计时并触发定时,所以队列中的定时事件也是异步事件.</p>
<p>由图可知,在这t1的时间段内,继鼠标点击事件触发后,先前已设置的setTimeout定时也到达了,此刻对JavaScript引擎来说,定时触发线程产生了一个异步定时事件并放到任务队列中, 该事件被排到点击事件回调之后,等待处理.<br/>
同理, 还是在t1时间段内,接下来某个setInterval定时器也被添加了,由于是间隔定时,在t1段内连续被触发了两次,这两个事件被排到队尾等待处理.</p>
<p>可见,假如时间段t1非常长,远大于setInterval的定时间隔,那么定时触发线程就会源源不断的产生异步定时事件并放到任务队列尾而不管它们是否已被处理,但一旦t1和最先的定时事件前面的任务已处理完,这些排列中的定时事件就依次不间断的被执行,这是因为,对于JavaScript引擎来说,在处理队列中的各任务处理方式都是一样的,只是处理的次序不同而已.</p>
<p>t1过后,也就是说当前处理的任务已返回,JavaScript引擎会检查任务队列,发现当前队列非空,就取出t2下面对应的任务执行,其它时间依此类推,由此看来:</p>
<p>如果队列非空,引擎就从队列头取出一个任务,直到该任务处理完,即返回后引擎接着运行下一个任务,在任务没返回前队列中的其它任务是没法被执行的.</p>
<p>相信您现在已经很清楚JavaScript是否可多线程,也了解理解JavaScript定时器运行机制了,下面我们来对一些案例进行分析:</p>
<p>案例1:setTimeout与setInterval</p>
<pre class="sh_javascript"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
setTimeout(function() {
        /* 代码块... */
        setTimeout(arguments.callee, 10);
}, 10);

setInterval(function(){
        /*代码块... */
}, 10);
</pre>
<p>这两段代码看一起效果一样,其实非也,第一段中回调函数内的setTimeout是JavaScript引擎执行后再设置新的setTimeout定时, 假定上一个回调处理完到下一个回调开始处理为一个时间间隔,理论两个setTimeout回调执行时间间隔>=10ms .第二段自setInterval设置定时后,定时触发线程就会源源不断的每隔十秒产生异步定时事件并放到任务队列尾,理论上两个setInterval回调执行时间间隔<=10.</p>
<p>案例2:ajax异步请求是否真的异步?</p>
<p>很多同学朋友搞不清楚,既然说JavaScript是单线程运行的,那么XMLHttpRequest在连接后是否真的异步?<br/>
其实请求确实是异步的,不过这请求是由浏览器新开一个线程请求(参见上图),当请求的状态变更时,如果先前已设置回调,这异步线程就产生状态变更事件放到JavaScript引擎的处理队列中等待处理,当任务被处理时,JavaScript引擎始终是单线程运行回调函数,具体点即还是单线程运行onreadystatechange所设置的函数.<script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/09/23/1089.html" >2009/09/23</a>, <a href="http://hqlong.com"  rel="external nofollow"  class="url" >hqlong</a> writes: 分析问题很有深度，似乎是你的风格。</li><li><a href="http://www.laruence.com/2009/09/23/1089.html" >2009/09/24</a>, silasoni writes: 博主分析问题很有深度是没错
不过这篇是转贴的呀</li><li><a href="http://www.laruence.com/2009/09/23/1089.html" >2009/09/29</a>, aaaaaa writes: 很多是转载的，不过博主整理知识还是很认真的</li><li><a href="http://www.laruence.com/2009/09/23/1089.html" >2009/09/29</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: :), 
如果遇到好的文章, 我会认真读完以后, 如果觉得很有保留价值, 我会转载, 转载会注明转载, 划在转载分类中. 表明转载地址. 
没有以上的, 都是原创..</li><li><a href="http://www.laruence.com/2009/09/23/1089.html" >2010/09/07</a>, 小豪_Scorpio writes: 不错，问题讲的有深度。俺就从你这里转了。</li><li><a href="http://www.laruence.com/2009/09/23/1089.html" >2011/01/05</a>, <a href="http://www.skygq.com"  rel="external nofollow"  class="url" >Jquery教程</a> writes: 博主很厉害呀~从两个javascript函数就可以分析出来这么多道理来~~佩服呀~~</li><li><a href="http://www.laruence.com/2009/09/23/1089.html" >2011/02/18</a>, <a href="http://idamag.com/blog"  rel="external nofollow"  class="url" >idamag</a> writes: 分析的很深刻！</li><li><a href="http://www.laruence.com/2009/09/23/1089.html" >2011/03/28</a>, winting writes: div.onclick = function(){
        setTimeout(function() {
             document.getElementById('inputField').focus();
        }, 0);
};

大侠你好， 请教一下。
 document.getElementById('inputField').focus();
这个会不会产生一个GUI事件触发线程，写到某个时间段。
（对于JavaScript引擎线程来说,这事件是由其它线程异步传到任务队列尾的,由于引擎正在处理t1时的任务,这个鼠标点击事件正在等待处理。）
是的话，就不用setTimeout。
有点迷糊。</li><li><a href="http://www.laruence.com/2009/09/23/1089.html" >2011/06/01</a>, 周某某4 writes: 这个是不是可以这样理解，setTimeout是在整个脚本执行完后，再执行回调函数</li></ul><hr/><h2>Related posts:</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/09/08/1076.html"  rel="bookmark"  title="Permanent Link: 深入理解Javascript之this关键字" >深入理解Javascript之this关键字</a></li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2012/01/07/2453.html"  title="2012年1月全球www网站技术报告" >2012年1月全球www网站技术报告</a></li><li><a href="http://www.laruence.com/2011/03/29/1949.html"  title="深入理解PHP原理之Session Gc的一个小概率Notice" >深入理解PHP原理之Session Gc的一个小概率Notice</a></li><li><a href="http://www.laruence.com/2010/05/18/1482.html"  title="深入理解PHP原理之对象(一)" >深入理解PHP原理之对象(一)</a></li><li><a href="http://www.laruence.com/2010/05/13/1462.html"  title="Javascript原型链和原型的一个误区" >Javascript原型链和原型的一个误区</a></li><li><a href="http://www.laruence.com/2010/01/21/1254.html"  title="IE下var的重要性的又一佐证" >IE下var的重要性的又一佐证</a></li><li><a href="http://www.laruence.com/2009/09/27/1123.html"  title="关于Javascript的俩个有趣的探讨" >关于Javascript的俩个有趣的探讨</a></li><li><a href="http://www.laruence.com/2009/09/08/1076.html"  title="深入理解Javascript之this关键字" >深入理解Javascript之this关键字</a></li><li><a href="http://www.laruence.com/2009/08/09/1036.html"  title="正确使用JS中的正则" >正确使用JS中的正则</a></li><li><a href="http://www.laruence.com/2009/05/28/863.html"  title="Javascript作用域原理" >Javascript作用域原理</a></li><li><a href="http://www.laruence.com/2009/05/18/809.html"  title="使用JS做文档处理" >使用JS做文档处理</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/09/23/1089.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>CSS让你的IE浏览器崩溃(Crash your IE)</title>
		<link>http://www.laruence.com/2009/09/14/1081.html</link>
		<comments>http://www.laruence.com/2009/09/14/1081.html#comments</comments>
		<pubDate>Mon, 14 Sep 2009 09:41:07 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[转载]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1081</guid>
		<description><![CDATA[ <p>严格来说不单是CSS就能令IE浏览器崩溃(crash)，而要配合相应的XHTML架构。到现时为止发现有两种正常写法及一种错误结构分别导致会IE6、IE7崩溃(crash)，至于原因我尝试寻找过答案但至今还没找到…如你有这方面的认识或更详细的资料很希望你能分享！
</p>]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>本文地址: <a href="http://www.laruence.com/2009/09/14/1081.html"  title="Permanet Link to CSS让你的IE浏览器崩溃(Crash your IE)" >http://www.laruence.com/2009/09/14/1081.html</a></li>
<li>转载文章</li>
</ul></div>
<p>严格来说不单是CSS就能令IE浏览器崩溃(crash)，而要配合相应的XHTML架构。到现时为止发现有两种正常写法及一种错误结构分别导致会IE6、IE7崩溃(crash)，至于原因我尝试寻找过答案但至今还没找到…如你有这方面的认识或更详细的资料很希望你能分享！
</p>
<h3>1 crash IE6 code</h3>
<p>Demo:<a href="http://blog.gulu77.com/demo/200808/crash_ie6.html"  target="_blank" >http://blog.gulu77.com/demo/200808/crash_ie6.html</a></p>
<p>此BUG只存在IE6中,当伪类为 a:active 时同样会遇到此问题</p>
<pre class="sh_css"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
a{position:relative;}
a:hover{float:left;}
</pre>
<p><strong>解决方案：</strong>为 &lt;a&gt; 添加 zoom:1; 令其触发haslayout </p>
<pre name="code"  class="sh_css"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
a{position:relative;zoom:1;}
a:hover{float:left;}
</pre>
<h3>2 crash IE6 code</h3>
<p>这是HTML结构错误而导致IE6的崩溃,在&lt;col width=&#8221;100&#8243;/&gt;前或后添加任何字符均会导致IE6 Crash</p>
<p>Demo:<a href="http://blog.gulu77.com/demo/200808/HTML_errors_crash_ie6.html"  target="_blank" >http://blog.gulu77.com/demo/200808/HTML_errors_crash_ie6.html</a></p>
<pre name="code"  class="sh_css"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;table style=&quot;table-layout:fixed;&quot;&gt;
&lt;colgroup&gt;
&lt;col width=&quot;100&quot;/&gt;Crash IE6
&lt;/colgroup&gt;
&lt;/table&gt;
</pre>
<h3>3 crash IE7 code</h3>
<p>Demo:<a href="http://blog.gulu77.com/demo/200808/crash_ie7.html"  target="_blank" >http://blog.gulu77.com/demo/200808/crash_ie7.html</a></p>
<p>Bug from <a href="http://www.tommyfan.com"  title="TommyFan" >偷米饭</a>，此bug只存在IE7中据估计是处理省略字的时候导致IE7崩溃.</p>
<pre name="code"  class="sh_css"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">&lt;style type=&quot;text/css&quot;&gt;
div{float:left;width:175px;}
ul{overflow:hidden;white-space:nowrap;text-overflow:ellipsis;}
li{position:relative;}
&lt;/style&gt;

&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;崩溃崩溃崩溃崩溃崩溃crash ie7&lt;/li&gt;
&lt;li&gt;崩溃崩溃崩溃崩溃崩溃crash ie7&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</pre>
<p><strong>解决方案：</strong>为
<li> 添加 zoom:1; 令其触发haslayout</p>
<pre name="code"  class="sh_css"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">&lt;style type=&quot;text/css&quot;&gt;
div{float:left;width:175px;}
ul{overflow:hidden;white-space:nowrap;text-overflow:ellipsis;}
li{position:relative;zoom:1;}
&lt;/style&gt;</pre>
<h3>4 crash IE6 code</h3>
<p>Demo:<a href="http://blog.gulu77.com/demo/200808/crash_ie6_test1.html"  target="_blank" >http://blog.gulu77.com/demo/200808/crash_ie6_test1.html</a></p>
<p>当再次改变定位时浏览器崩溃，但似乎也需要N个帮凶才会导致崩溃的代码中CSS table的相属性都缺一不可。</p>
<pre name="code"  class="sh_html"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
  	&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
  	&lt;head&gt;
  	&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
  	&lt;title&gt;CRASH-IE,CSS让你的IE浏览器崩溃&lt;/title&gt;
	&lt;style type=&quot;text/css&quot;&gt;
  	html, body {overflow: hidden;scrollbar-base-color: #330066;}
  	.crash {position:absolute;left:200px;top:200px;width:200px;}
	&lt;/style&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
  	function galgenfrist() {
  	window.setTimeout('crashIE();',1000);
  	}

 function crashIE() {
  	var moveNode = document.getElementById(&quot;move&quot;);
  	if(moveNode) {
  	moveNode.style.top = &quot;100px&quot;;
  	moveNode.style.left = &quot;200px&quot;;
  	}
  	}
	&lt;/script&gt;
	&lt;/head&gt;

&lt;body onload=&quot;galgenfrist();&quot;&gt;
	&lt;h1&gt;CRASH-IE&lt;/h1&gt;
	&lt;div id=&quot;move&quot; class=&quot;crash&quot;&gt;
	&lt;table&gt;
	&lt;tbody&gt;
	&lt;tr&gt;
	&lt;td&gt;
	&lt;textarea&gt;&lt;/textarea&gt;
	&lt;/td&gt;
	&lt;/tr&gt;
	&lt;/tbody&gt;
	&lt;/table&gt;
	&lt;/div&gt;
	&lt;/body&gt;
&lt;/html&gt;
</pre>
<h3>5 crash IE6 code</h3>
<p>Demo:<a href="http://blog.gulu77.com/demo/200808/crash_ie6_test2.html"  target="_blank" >http://blog.gulu77.com/demo/200808/crash_ie6_test2.html</a></p>
<p>具体引起的原因暂时无法解析，但在兼容性和执行效率来看一般不会采取这样的写法。</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;script&gt;
	for (x in document.write) {
		document.write(x);}
&lt;/script&gt;
</pre>
<h3>6 crash IE6 code</h3>
<p>Demo:<a href="http://blog.gulu77.com/demo/200808/crash_ie6_test3.html"  target="_blank" >http://blog.gulu77.com/demo/200808/crash_ie6_test3.html</a></p>
<p>传说是一名日本人发现的，table中直接放置内容，在IE6会引起Mshtml.all模块损坏而关闭浏览器，非IE6则安全无恙。</p>
<pre name="code"  class="sh_css"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;style&gt;
	* {position:relative}
&lt;/style&gt;
&lt;table&gt;
	&lt;input&gt;
&lt;/table&gt;
</pre>
<h3>7 crash IE6 code</h3>
<p>Demo:<a href="http://blog.gulu77.com/demo/200808/crash_ie6_test4.html"  target="_blank" >http://blog.gulu77.com/demo/200808/crash_ie6_test4.html</a></p>
<pre name="code"  class="sh_css"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;body onLoad=”window()”&gt;
</pre>
<h3>8 crash IE6 code</h3>
<p>Demo:<a href="http://blog.gulu77.com/demo/200808/crash_ie6_test5.html"  target="_blank" >http://blog.gulu77.com/demo/200808/crash_ie6_test5.html</a></p>
<p>CSS中出现@+任意字符+/* 立即崩溃。</p>
<pre name="code"  class="sh_css"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;style&gt;
	@;/*
&lt;/style&gt;
</pre>
<p> 原文地址:<a href="http://blog.gulu77.com/?p=59" >http://blog.gulu77.com/?p=59</p>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_css.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_css.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_css.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_css.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_css.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_html.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_css.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_css.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_css.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/09/14/1081.html" >2009/09/14</a>, Edward writes: IE7以前的浏览器是有好多的问题～而且IE有自己的一套标准，根本不去理会什么W3C。

但是IE8好多了哦～

但是悲剧的是，还有绝大部分的用户在使用IE6.应为windows内置的就是IE6.而且大家除了浏览网页以外，基本上没所有什么其他的需求。所以，很少有人去更换自己的浏览器，对web开发来说，这个也算是让人小小头痛的事情吧！</li><li><a href="http://www.laruence.com/2009/09/14/1081.html" >2009/09/16</a>, 5455 writes: 您好：
   PHP Pallas CMS的数据库 我找不到在哪里？ 想学习学习php。可以发数据库给我吗？
      谢谢</li><li><a href="http://www.laruence.com/2009/09/14/1081.html" >2009/09/16</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: sql文件在包里有.pscms_admin/tables.sql</li><li><a href="http://www.laruence.com/2009/09/14/1081.html" >2009/09/18</a>, <a href="http://www.xidea.org"  rel="external nofollow"  class="url" >jindw</a> writes: 不错，呵呵。</li><li><a href="http://www.laruence.com/2009/09/14/1081.html" >2009/09/19</a>, toms writes: 大侠能不能说下这个是怎么回事阿

class base
{
    public function run($module, $params)
    {
        $this-&gt;{$module}($params);
    }
}

class sub extends base
{
    public functin show()
    {
        $this-&gt;run('module_news', $params);
    }
    
    public function module_news($params)
    {
    }
}

我看见joomla里的代码有这样的写法， 但joomla是php4的写法， 为什么module_news为public的时候才能被调用呢？</li><li><a href="http://www.laruence.com/2009/09/14/1081.html" >2009/09/25</a>, fybird writes: 赞！</li><li><a href="http://www.laruence.com/2009/09/14/1081.html" >2009/10/09</a>, berger writes: 以前也遇到过一次css crash，让人郁闷了快一天，当时遇到的问题是，编码写的太不规范，自觉着，要是规范点使用标签，会好点</li><li><a href="http://www.laruence.com/2009/09/14/1081.html" >2009/11/26</a>, <a href="http://www.sn00py.cn"  rel="external nofollow"  class="url" >samuel</a> writes: 全都是IE的，还是FIREFOX好啊</li><li><a href="http://www.laruence.com/2009/09/14/1081.html" >2010/03/18</a>, <a href="http://www.lowest-rate-loans.com"  rel="external nofollow"  class="url" >SAUNDERSSANDY</a> writes: When you are in not good state and have no money to go out from that, you would require to take the <a href="http://lowest-rate-loans.com/topics/personal-loans"  rel="nofollow" >personal loans</a>. Just because that should aid you unquestionably. I take bank loan every single year and feel myself fine because of this.</li><li><a href="http://www.laruence.com/2009/09/14/1081.html" >2010/05/26</a>, <a href="http://www.js4j.com"  rel="external nofollow"  class="url" >技术门户网站</a> writes: windows7内置的是IE8</li><li><a href="http://www.laruence.com/2009/09/14/1081.html" >2011/08/19</a>, <a href="http://hiheng.com/blog"  rel="external nofollow"  class="url" >hiheng</a> writes: 真是万能的zoom:1,哈哈。</li><li><a href="http://www.laruence.com/2009/09/14/1081.html" >2011/11/14</a>, <a href="http://qitiancom.com"  rel="external nofollow"  class="url" >朱宝祥</a> writes: 真实神奇的bug。学习了，标记一下，以后学耍酷来这里。哈</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Random Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/05/14/803.html"  title="浏览器的结构" >浏览器的结构</a></li><li><a href="http://www.laruence.com/2010/08/18/1718.html"  title="将PHP Manual融入(g)Vim" >将PHP Manual融入(g)Vim</a></li><li><a href="http://www.laruence.com/2010/12/08/1716.html"  title="如何获取一个变量的名字" >如何获取一个变量的名字</a></li><li><a href="http://www.laruence.com/2009/05/28/863.html"  title="Javascript作用域原理" >Javascript作用域原理</a></li><li><a href="http://www.laruence.com/2010/04/21/1442.html"  title="Le Putty &#8211; Putty with Zmodem" >Le Putty &#8211; Putty with Zmodem</a></li><li><a href="http://www.laruence.com/2010/08/03/1697.html"  title="深入理解PHP原理之异常机制" >深入理解PHP原理之异常机制</a></li><li><a href="http://www.laruence.com/2009/04/21/680.html"  title="phpDocumentor" >phpDocumentor</a></li><li><a href="http://www.laruence.com/2012/01/24/2494.html"  title="大家新年好~" >大家新年好~</a></li><li><a href="http://www.laruence.com/2011/03/04/1894.html"  title="深入理解PHP内存管理之谁动了我的内存" >深入理解PHP内存管理之谁动了我的内存</a></li><li><a href="http://www.laruence.com/2008/09/20/523.html"  title="PHP5.3 α2初体验" >PHP5.3 α2初体验</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/09/14/1081.html/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>深入理解Javascript之this关键字</title>
		<link>http://www.laruence.com/2009/09/08/1076.html</link>
		<comments>http://www.laruence.com/2009/09/08/1076.html#comments</comments>
		<pubDate>Tue, 08 Sep 2009 05:13:44 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[this]]></category>
		<category><![CDATA[this关键字]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1076</guid>
		<description><![CDATA[Javascript是一种很灵活的语言, 而This关键字又是灵活中的灵活, 但是因为它的灵活, 也注定了它的难用.

以前我用this的时候, 都会觉得不踏实, 老是担心它不知道怎么地就会指到另外的什么地方. 

其实, 这都是因为,  我们对它的不了解.

刚好最近再给百度学院做《Javascript高级-作用域/原型链》的ppt, 而swit1983网友也刚好提这个问题, 索性就把这部分内容独立总结出来, 与大家分享.]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2009/09/08/1076.html"  title="Permanet Link to 深入理解Javascript之this关键字" >http://www.laruence.com/2009/09/08/1076.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>
Javascript是一种很灵活的语言, 而This关键字又是灵活中的灵活, 但是因为它的灵活, 也注定了它的难用.</p>
<p>以前我用this的时候, 都会觉得不踏实, 老是担心它不知道怎么地就会指到另外的什么地方. </p>
<p>其实, 这都是因为,  我们对它的不了解.</p>
<p>刚好最近再给百度学院做《Javascript高级-作用域/原型链》的ppt, 而swit1983网友也刚好提这个问题, 索性就把这部分内容独立总结出来, 与大家分享.
</p>
<p>
首先, 我先抛出一个定论:&#8221;在Javascript中,This关键字永远都指向函数(方法)的所有者&#8221;.</p>
<h3>函数</h3>
<p>首先,让我们看看&#8221;函数&#8221;:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
function introduce() {
	alert(&quot;Hello, I am Laruence\r\n&quot;);
}
</pre>
<p>对于,这个函数, this关键字指向谁呢?</p>
<p>如我之前的文章所述(<a href="http://www.laruence.com/2009/05/28/863.html"  target="_blank" >Javascript作用域</a>), 定义在全局的函数, 函数的所有者就是当前页面, 也就是window对象. </p>
<p>这也就是为什么, 我把函数用引号引起来. 因为定义在全局的函数, 其实也就是window对象的一个方法.</p>
<p>所以,我们即可用通过函数名直接调用, 也可用通过window.方法名来调用, 这个时候, 方法中的this关键字指向它的所有者:window对象.</p>
<p>如果, 我们查看window的introduce属性, 就会得到:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
var name = &quot;I am Laruence&quot;;
function introduce() {
	alert(this.name);
}
alert(window.introduce);
/**
* output:
* function introduce() {
* alert(this.name);
* }
*/
</pre>
<p>看了上面的代码, 也许你就会想到既然, 全局函数是window对象的方法, 全局变量是window对象的属性(Javasript作用域中已有述及), 那么,在全局函数中就可用通过this关键字来访问全局变量吧?</p>
<p>答案是肯定的, 如果调用introduce函数, 你就会认识我是Laruence.</p>
<h3>事件处理函数</h3>
<p>也许, 对于this关键字的迷惑, 绝大部分原因是来自把函数(方法)用在事件处理的时候.</p>
<pre name="code"  class="sh_html"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;input id=&quot;name&quot; type=&quot;text&quot;  name=&quot;name&quot; value=&quot;Laruence&quot; /&gt;
</pre>
<p>比如, 我们现在需要在点击&#8221;name&#8221;输入框的时候, 显示出name输入框的value. 那么, 可用写下如下代码:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
function showValue() {
	alert(this.value);
}
document.getElementById('name').onclick = showValue;
</pre>
<p>上面的代码, 运行正常, 但是why? 不是说函数的this指针永远指向函数所有者么? 不是说全局变量的所有者是window对象么?</p>
<p>呵呵, 如果你能想到这个问题, 那说明你在认真的看我的文章, 否则,,我建议你从头看起, 否则看完了,你还是迷糊~</p>
<p>恩, 对, 对于上面的代码, showValue是定义在了全局对象, 那么看来问题只能发生在onclick事件绑定的时候了.</p>
<p>我们知道, 在Js中一切都是对象, 函数和方法也都是对象的属性, 只不过函数有可执行的内部属性. 所以, 对于上面的代码, 在对onclick绑定处理器的时候, 其实是对id为name的输入框Dom对象的onclick属性赋值.</p>
<p>也就是说, 我们把函数showValue Copy 给了name输入框对象的onclick属性. 如果我们查看此时的onclick:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
function showValue() {
	alert(this.value);
}
document.getElementById('name').onclick = showValue;
alert(document.getElementById('name').onclick);
/**
* output
* function showValue() {
* alert(this.value);
* }
*/
</pre>
<p>所以, 当事件触发的时候, 就会去调用name输入框的onclick方法, 这个时候,this关键字自然就指向的是name输入框了.</p>
<p>但是, 迷惑的事情就来了, 比如下面这种写法:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
function showValue() {
	alert(this.value);
}
&lt;input id=&quot;name&quot; type=&quot;text&quot;  name=&quot;name&quot; value=&quot;Laruence&quot;  onclick=&quot;showValue()&quot;/&gt;
</pre>
<p>就无法正常运行, 这又是为什么呢?</p>
<p>恩, 因为这个时候, 并不是赋值, 而是引用.</p>
<p>如果我们注意俩种onclick的写法, 你会发现, 对于之前的方法, 我们使用的是:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
dom.onclick = showvalue; //没有调用符
</pre>
<p>而对于刚才的方法:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
onclick = &quot;showvalue()&quot; //有调用符
</pre>
<p>这个也能侧面的反映出俩者的区别:对于前者,是赋值, 而对于后者是引用.  如果我们这个时候查看输入框的onclick属性,我们得到:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
alert(dom.onclick);
/**
* output:
* function onclick() {
*    showValue();
* }
*/
</pre>
<p>看到区别了么?  也就懂得为什么了吧?</p>
<p>讲到这里, 有一个很有趣的例子 ,大家可以在IE下试试:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;img src=&quot;xxx&quot; onerror=&quot;alert(1);} function hi() { alert(2); &quot; /&gt;
</pre>
<h3>改变this的指向</h3>
<p>那, 既然我们已经知道为什么了, 那怎么才能让this指向我们想要指的地方呢?</p>
<p>对于上面的事件处理函数来说, 我们可以有如下几种写法:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
dom.onclick = showValue();
dom.onclick = function() { alert(this.value) ;}
&lt;input onclick=&quot;alert(this.value);&quot; /&gt; //想想刚才我们的引用,是如何把这句嵌入的.
dom.addEventListener(dom, showValue, false); //ff only
</pre>
<p>而对于不是事件处理函数的场合, 我们可以使用apply, 或者call, 来改变this关键字的指向.</p>
<p>比如:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
var laruence = {
	name : 'laruence',
	age  : 26,
	position : 'Senior PHP Engineer',
	company : 'Baidu.inc'
};

function introduce() {
	alert(this.name);
}

introduce.call(laruence);
</pre>
</p>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_html.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/09/08/1076.html" >2009/09/08</a>, 烂叶 writes: 鸟哥。
太棒了！</li><li><a href="http://www.laruence.com/2009/09/08/1076.html" >2009/09/14</a>, iceshi writes: onclick = "showvalue()" 
用在inline里的时候这里的onclick是函数的body部分，
相当于
onclick = function anounymous(){
    showvalue();
}

这里就能看出要使用this才能得到input对象

这样比较好理解一点吧。</li><li><a href="http://www.laruence.com/2009/09/08/1076.html" >2009/09/14</a>, Edward writes: 不错不错，”在Javascript中,This关键字永远都指向函数(方法)的所有者”。这句话精辟。

还有，apply和call是能够改变上述定论的手段。
introduce.call(laruence)

introduce里面所有的this就都指向laruence了吧！</li><li><a href="http://www.laruence.com/2009/09/08/1076.html" >2009/09/17</a>, jimmy writes: 不得了，我这次理解了一半内容...</li><li><a href="http://www.laruence.com/2009/09/08/1076.html" >2009/09/22</a>, zhangyufeng writes: 学习……</li><li><a href="http://www.laruence.com/2009/09/08/1076.html" >2009/09/22</a>, 玉米疯收(zhangyufeng) writes: 新代码高亮很酷……不过……较长的行还是换个行啊……</li><li><a href="http://www.laruence.com/2009/09/08/1076.html" >2009/10/21</a>, Anonymous writes: function showValue() {
	alert(this.value);
}

运行结果---------------------------
Microsoft Internet Explorer
---------------------------
undefined
---------------------------
确定   
---------------------------</li><li><a href="http://www.laruence.com/2009/09/08/1076.html" >2009/11/21</a>, steven writes: 顶。好文章。又学了点东西。</li><li><a href="http://www.laruence.com/2009/09/08/1076.html" >2011/01/05</a>, <a href="http://www.skygq.com"  rel="external nofollow"  class="url" >Jquery教程</a> writes: 鸟哥？呵呵~~厉害呀~~你的这篇文章让我鄙时就对javascript中的this关键词有了深刻的理解呀~
求友链~~
我的博客地址：http://www.skygq.com
博客名字：Jquery教程
博客描述：梦三秋|jquery学习-Jquery教程-php学习

像鸟哥这样的对javascript了解这么深刻的人，应该去玩玩jquery和其他的js框架呢~~

如果您有兴趣和我换下友链的话，还请告知我你的博客要什么名字和描述·
谢谢~~
您的博客文章我是太喜欢了呀~~
您的这篇我转走了哦·~</li><li><a href="http://www.laruence.com/2009/09/08/1076.html" >2011/03/20</a>, <a href="http://www.w3hacker.com/?p=262"  rel="external nofollow"  class="url" >深入理解Javascript之this关键字 | 万维网黑客联盟</a> writes: [...] 本文地址: http://www.laruence.com/2009/09/08/1076.html [...]</li><li><a href="http://www.laruence.com/2009/09/08/1076.html" >2011/03/29</a>, 小哥 writes: 这篇很精彩。</li><li><a href="http://www.laruence.com/2009/09/08/1076.html" >2011/04/17</a>, paipai writes: 在Javascript中,This关键字永远都指向函数(方法)的所有者
很受用,学习了</li><li><a href="http://www.laruence.com/2009/09/08/1076.html" >2011/07/08</a>, 小哥 writes: 我发现一个有趣的现象，在IE，FF下，
dom.onblur = fun1;和都符合文章里面的分析，但是如果使用attachEvent或者addEventListener的话，alert(dom.onblur);的结果ie是null，ff是undefined，而且两个浏览器对this的处理也不一样，ie下和一样，ff下和dom.onblur=func1一样，不知道为什么。。。悲剧了。</li><li><a href="http://www.laruence.com/2009/09/08/1076.html" >2011/07/08</a>, 小哥 writes: 我用jquery测试了一下，发现他处理了这个兼容性问题，看来要找个时间研究下jquery代码，看看他是怎么处理的。

随带牢骚下，鸟哥的评论列表太简陋鸟。。</li><li><a href="http://www.laruence.com/2009/09/08/1076.html" >2011/10/22</a>, <a href="http://www.js8.in"  rel="external nofollow"  class="url" >前端开发</a> writes: dom.addEventListener(dom, showValue, false); //ff only
 这个地方错了，第一个参数应该是click</li><li><a href="http://www.laruence.com/2009/09/08/1076.html" >2012/01/10</a>, 小哥 writes: 
中的hi() 怎么调用？</li></ul><hr/><h2>Related posts:</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/09/23/1089.html"  rel="bookmark"  title="Permanent Link: 深入理解JavaScript定时机制" >深入理解JavaScript定时机制</a></li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2012/01/07/2453.html"  title="2012年1月全球www网站技术报告" >2012年1月全球www网站技术报告</a></li><li><a href="http://www.laruence.com/2010/05/13/1462.html"  title="Javascript原型链和原型的一个误区" >Javascript原型链和原型的一个误区</a></li><li><a href="http://www.laruence.com/2010/01/21/1254.html"  title="IE下var的重要性的又一佐证" >IE下var的重要性的又一佐证</a></li><li><a href="http://www.laruence.com/2009/09/27/1123.html"  title="关于Javascript的俩个有趣的探讨" >关于Javascript的俩个有趣的探讨</a></li><li><a href="http://www.laruence.com/2009/09/23/1089.html"  title="深入理解JavaScript定时机制" >深入理解JavaScript定时机制</a></li><li><a href="http://www.laruence.com/2009/08/09/1036.html"  title="正确使用JS中的正则" >正确使用JS中的正则</a></li><li><a href="http://www.laruence.com/2009/06/01/905.html"  title="开心网偷菜外挂" >开心网偷菜外挂</a></li><li><a href="http://www.laruence.com/2009/05/28/863.html"  title="Javascript作用域原理" >Javascript作用域原理</a></li><li><a href="http://www.laruence.com/2009/05/21/829.html"  title="JS文件装载器(Eve Js Loader)" >JS文件装载器(Eve Js Loader)</a></li><li><a href="http://www.laruence.com/2009/05/18/809.html"  title="使用JS做文档处理" >使用JS做文档处理</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/09/08/1076.html/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>纯属娱乐(彩蛋)</title>
		<link>http://www.laruence.com/2009/08/31/1072.html</link>
		<comments>http://www.laruence.com/2009/08/31/1072.html#comments</comments>
		<pubDate>Mon, 31 Aug 2009 10:26:02 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[随笔]]></category>
		<category><![CDATA[easter egg]]></category>
		<category><![CDATA[js效果]]></category>
		<category><![CDATA[彩蛋]]></category>
		<category><![CDATA[隐藏]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1072</guid>
		<description><![CDATA[ 现在, 请依次按下:"上上下下左右左右BA"~, ;)]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2009/08/31/1072.html"  title="Permanet Link to 纯属娱乐(彩蛋)" >http://www.laruence.com/2009/08/31/1072.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>
   现在, 请依次按下:&#8221;上上下下左右左右BA&#8221;~, <img src="http://www.laruence.com/wp-includes/images/smilies/icon_wink.gif"  alt=";)"  class="wp-smiley" /></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2009/08/31</a>, 嘛都没有 writes: 嘛都没有</li><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2009/09/01</a>, airwin writes: 看到猫叔了
还没仔细看 米了~

ps:我被这验证码折磨死了</li><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2009/09/01</a>, sky writes: 这不是魂斗罗调30人吗</li><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2009/09/01</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @airwin 唉, spam太多了...不得已之举啊</li><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2009/09/01</a>, N writes: 。。</li><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2009/09/03</a>, <a href="http://movoin.com"  rel="external nofollow"  class="url" >allen</a> writes: 挺好玩~~~我也想要~~~</li><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2009/09/08</a>, <a href="www.phppan.com"  rel="external nofollow"  class="url" >phppan</a> writes: 没有看到效果。WHY？</li><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2009/09/08</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @phppan 好像有些杀毒软件会把我使用的雅虎统计的js认为成是有风险的代码.....</li><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2009/09/08</a>, <a href="www.phppan.com"  rel="external nofollow"  class="url" >phppan</a> writes: 换个操作系统后，看到了，
嘿嘿！</li><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2009/09/12</a>, guest writes: /*easteregg*/ 
(function(){ 
	var _E = function(o, e, f) { 
		if (o.attachEvent) { 
			o.attachEvent('on' + e, f); 
		} else { 
			o.addEventListener(e, f, false); 
		} 
	}; 
	_E(window, 'load', function(e) { 
		var _m = document.createElement('img'); 
		_m.src = '/images/profile.png'; 
		_m.style.display = 'none'; 
		_m.style.position = 'fixed'; 
		_m.style.left = (document.body.clientWidth - 320)/2 + 'px'; 
		_m.style.top = (document.body.clientHeight - 150)/2 + 'px'; 
		document.body.appendChild(_m); 
		var _egg={
			_ss:[38,38,40,40,37,39,37,39,66,65],
			_s:0,
			_p:0,
			bind:function(e){ 
				var _e= e||window.event; 
				(_e.keyCode==_egg._ss[_egg._s])?(_egg._s==9?_egg._got():++_egg._s):(_egg._s=0); 
				return true; 
			},
			_got:function(){ 
				_egg._s = 0; 
				_m.style.display = 'block'; 
				setTimeout(function(){
					_m.style.display = 'none'
				}, 5000); }
			}; 
		_E(document, 'keydown', _egg.bind); 
	}) 
})();</li><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2009/09/14</a>, Edward writes: 哈哈，这个是用js实现的吗？在土豆网里面，打开一个视频的播放页面，也按顺寻按下这几个键，你会看到~~~~~~~~</li><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2010/05/12</a>, Anonymous writes: 毛都没有</li><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2010/05/12</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 诶, 还是有的,,,,,,, 仔细的按下?</li><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2010/10/20</a>, luchuan writes: 鸟哥，难道你是原创？</li><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2011/02/16</a>, fengchuan writes: 在谷歌浏览器里什么都没有</li><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2011/02/16</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @fengchuan 你多试几次? 呵呵, 我也用chrome,, :)</li><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2011/04/19</a>, feng writes: 可以的
上上下下左右左右ba
就行了</li><li><a href="http://www.laruence.com/2009/08/31/1072.html" >2012/01/26</a>, 荆棘 writes: 还以为会满屏彩蛋，结果冒出个猫叔，位置放上面点就好发现了</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Random Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2008/10/28/567.html"  title="一个巧妙的分页方法" >一个巧妙的分页方法</a></li><li><a href="http://www.laruence.com/2010/05/24/1515.html"  title="shell下发推脚本" >shell下发推脚本</a></li><li><a href="http://www.laruence.com/2010/12/14/1816.html"  title="Compilation failed: support for \P, \p, and \X has not been compiled" >Compilation failed: support for \P, \p, and \X has not been compiled</a></li><li><a href="http://www.laruence.com/2008/11/07/581.html"  title="PHP的GET/POST等大变量生成过程" >PHP的GET/POST等大变量生成过程</a></li><li><a href="http://www.laruence.com/2011/12/29/2412.html"  title="通过构造Hash冲突实现各种语言的拒绝服务攻击" >通过构造Hash冲突实现各种语言的拒绝服务攻击</a></li><li><a href="http://www.laruence.com/2007/11/06/9.html"  title="授人渔而非鱼" >授人渔而非鱼</a></li><li><a href="http://www.laruence.com/2011/01/27/1854.html"  title="深入理解PHP内存管理之一个低概率Core的分析" >深入理解PHP内存管理之一个低概率Core的分析</a></li><li><a href="http://www.laruence.com/2009/05/17/815.html"  title="关于事件模拟" >关于事件模拟</a></li><li><a href="http://www.laruence.com/2008/04/16/19.html"  title="编写提供对象给PHP使用的Module" >编写提供对象给PHP使用的Module</a></li><li><a href="http://www.laruence.com/2009/06/14/945.html"  title="深入理解PHP原理之扩展载入过程" >深入理解PHP原理之扩展载入过程</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/08/31/1072.html/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>正确使用JS中的正则</title>
		<link>http://www.laruence.com/2009/08/09/1036.html</link>
		<comments>http://www.laruence.com/2009/08/09/1036.html#comments</comments>
		<pubDate>Sun, 09 Aug 2009 03:23:29 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[lastIndex]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[正则]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1036</guid>
		<description><![CDATA[yuchen网友发来一个问题, 大体意思就是在JS中, 同样的正则, 同样的字符串, 循环匹配结果却不一样 ,

<coolcode lang="javascript" linenum="off">
<script type='text/javascript'>
var reTest = /^aid=(.*)/ig;

var aData = [ 'aid=^$', 'aid=^$', 'aid=^$', 'aid=^$' ]; 

for (var i=0, l=aData.length; i<l; i++) {
	alert(reTest.test(aData[i]));
}
</script>
</coolcode>

结果却是:

<coolcode lang="javascript" linenum="off">
true
false
true
false
</coolcode>

为什么会这样呢? ]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2009/08/09/1036.html"  title="Permanet Link to 正确使用JS中的正则" >http://www.laruence.com/2009/08/09/1036.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>
yuchen网友发来一个问题, 大体意思就是在JS中, 同样的正则, 同样的字符串, 循环匹配结果却不一样 ,</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;script type='text/javascript'&gt;
var reTest = /^aid=(.*)/ig;

var aData = [ 'aid=^$', 'aid=^$', 'aid=^$', 'aid=^$' ]; 

for (var i=0, l=aData.length; i&lt;l; i++) {
	alert(reTest.test(aData[i]));
}
&lt;/script&gt;
</pre>
<p>结果却是:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
true
false
true
false
</pre>
<p>为什么会这样呢? 这个就和JS中正则对象的lastIndex属性有关了.</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
定义和用法

lastIndex 属性用于规定下次匹配的起始位置。
语法

Js代码
RegExpObject.lastIndex  

说明

该属性存放一个整数，它声明的是上一次匹配文本之后的第一个字符的位置。
上次匹配的结果是由方法 RegExp.exec() 和 RegExp.test() 找到的，它们都以 lastIndex 属性所指的位置作为下次检索的起始点。这样，就可以通过反复调用这两个方法来遍历一个字符串中的所有匹配文本。
该属性是可读可写的。只要目标字符串的下一次搜索开始，就可以对它进行设置。当方法 exec() 或 test() 再也找不到可以匹配的文本时，它们会自动把 lastIndex 属性重置为 0。

提示和注释

重要事项：不具有标志 g 和不表示全局模式的 RegExp 对象不能使用 lastIndex 属性。
提示：如果在成功地匹配了某个字符串之后就开始检索另一个新的字符串，需要手动地把这个属性设置为 0。
</pre>
<p>So, 原因很明显, 解决方法也很明了了.</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;script type='text/javascript'&gt;
var reTest = /^aid=(.*)/ig;

var aData = [ 'aid=^$', 'aid=^$', 'aid=^$', 'aid=^$' ]; 

for (var i=0, l=aData.length; i&lt;l; i++) {
        reTest.lastIndex = 0;
	alert(reTest.test(aData[i]));
}
&lt;/script&gt;
</pre>
<p>这样, 结果就对了~, 当然</p>
<p>另外, moxie同学说的方法其实更有效, 既然你不需要g, 那何必设置g呢?</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;script type='text/javascript'&gt;
var reTest = /^aid=(.*)/i;

var aData = [ 'aid=^$', 'aid=^$', 'aid=^$', 'aid=^$' ]; 

for (var i=0, l=aData.length; i&lt;l; i++) {
	alert(reTest.test(aData[i]));
}
&lt;/script&gt;
</pre>
<p>this works well too~
</p>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/08/09/1036.html" >2009/08/09</a>, N writes: 阅</li><li><a href="http://www.laruence.com/2009/08/09/1036.html" >2009/08/10</a>, <a href="http://xinple.org"  rel="external nofollow"  class="url" >阿辛</a> writes: 不错</li><li><a href="http://www.laruence.com/2009/08/09/1036.html" >2009/08/11</a>, toms writes: 很抱歉在这里问问题哈， 就是我的在线编辑器需要一个这样的功能，它需要能在ie和firefox中控制编辑器中的某张图片是不可缩放的，这个怎么弄啊？</li><li><a href="http://www.laruence.com/2009/08/09/1036.html" >2009/08/12</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @toms img对象有onresizestart/onresizeend俩个事件, 你可以在这俩个事件入手么.</li><li><a href="http://www.laruence.com/2009/08/09/1036.html" >2009/08/13</a>, zhangyufeng writes: 最近正在正则，学习……</li><li><a href="http://www.laruence.com/2009/08/09/1036.html" >2009/08/15</a>, <a href="http://www.kh505.cn"  rel="external nofollow"  class="url" >商业创业实验室</a> writes: moxie同学有成为好程序员的潜质~~~~</li><li><a href="http://www.laruence.com/2009/08/09/1036.html" >2009/08/17</a>, <a href="http://www.zoeey.org/"  rel="external nofollow"  class="url" >MoXie</a> writes: 呃～竟然被人夸了-_-#
-----邪恶的分割线-----
@toms
关键词： img resize disable

Firefox - designMode: disable image resizing handles

http://stackoverflow.com/questions/289433/firefox-designmode-disable-image-resizing-handles

Disabling image resize in RadEditor Classic and Prometheus 

http://www.telerik.com/support/kb/aspnet-ajax/editor/disabling-image-resize-in-radeditor-classic-and-prometheus.aspx</li><li><a href="http://www.laruence.com/2009/08/09/1036.html" >2009/08/17</a>, <a href="http://faryang.cn"  rel="external nofollow"  class="url" >fy</a> writes: lastIndex
This property is an integer that specifies the index at which to start the next match, but is only set if the regular expression uses the 'g' flag to specify a global search.

---
这个解释开起来爽点·</li><li><a href="http://www.laruence.com/2009/08/09/1036.html" >2011/10/26</a>, sking7 writes: 在火狐测试好像没有问题。。。。</li></ul><hr/><h2>Related posts:</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/05/21/829.html"  rel="bookmark"  title="Permanent Link: JS文件装载器(Eve Js Loader)" >JS文件装载器(Eve Js Loader)</a></li><li><a href="http://www.laruence.com/2009/05/18/809.html"  rel="bookmark"  title="Permanent Link: 使用JS做文档处理" >使用JS做文档处理</a></li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/09/27/1123.html"  title="关于Javascript的俩个有趣的探讨" >关于Javascript的俩个有趣的探讨</a></li><li><a href="http://www.laruence.com/2012/01/07/2453.html"  title="2012年1月全球www网站技术报告" >2012年1月全球www网站技术报告</a></li><li><a href="http://www.laruence.com/2011/09/30/2179.html"  title="PHP正则之递归匹配" >PHP正则之递归匹配</a></li><li><a href="http://www.laruence.com/2010/05/13/1462.html"  title="Javascript原型链和原型的一个误区" >Javascript原型链和原型的一个误区</a></li><li><a href="http://www.laruence.com/2010/01/21/1254.html"  title="IE下var的重要性的又一佐证" >IE下var的重要性的又一佐证</a></li><li><a href="http://www.laruence.com/2009/09/23/1089.html"  title="深入理解JavaScript定时机制" >深入理解JavaScript定时机制</a></li><li><a href="http://www.laruence.com/2009/09/08/1076.html"  title="深入理解Javascript之this关键字" >深入理解Javascript之this关键字</a></li><li><a href="http://www.laruence.com/2009/05/28/863.html"  title="Javascript作用域原理" >Javascript作用域原理</a></li><li><a href="http://www.laruence.com/2009/05/18/809.html"  title="使用JS做文档处理" >使用JS做文档处理</a></li><li><a href="http://www.laruence.com/2009/05/17/815.html"  title="关于事件模拟" >关于事件模拟</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/08/09/1036.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>开心网偷菜外挂</title>
		<link>http://www.laruence.com/2009/06/01/905.html</link>
		<comments>http://www.laruence.com/2009/06/01/905.html#comments</comments>
		<pubDate>Mon, 01 Jun 2009 09:33:26 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[偷菜]]></category>
		<category><![CDATA[外挂]]></category>
		<category><![CDATA[开心网]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=905</guid>
		<description><![CDATA[  一个基于greaseMonkey的开心网(kaixin001)牧场偷菜外挂.

  这个版本:

      1. 修整了一个问题应付最近的开心网调整. 

      2. 使用OOP重写
    
      3. 应对了开心网2009.06.09的接口调整

  如果不知道怎么使用,请google"greaseMonkey".
  
  基于Gxd(<a href='http://onemouse.cn/i/608' target='_blank'>onmouse.cn</a>)的version 0.0.1重写]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2009/06/01/905.html"  title="Permanet Link to 开心网偷菜外挂" >http://www.laruence.com/2009/06/01/905.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>  一个基于greaseMonkey的开心网(kaixin001)偷菜外挂.</p>
<p>  这个版本:</p>
<p>      1. 修整了一个问题应付最近的开心网调整. </p>
<p>      2. 使用OOP重写</p>
<p>  如果不知道怎么使用,请google&#8221;greaseMonkey&#8221;.</p>
<p>  changelog:<br/>
  version 1.0.2:开心网调整了URL, 已经调整相应策略. 2009.06.09</p>
<p>  基于Gxd(<a href="http://onemouse.cn/i/608"  target="_blank" >onmouse.cn</a>)的version 0.0.1重写
</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
// ==UserScript==
// @name           kaixin.app.garden
// @namespace      Kaixin.app.garden
// @description    Garden for kaixin001.com
// @version 	   1.0.3
// @author		   laruence based on Gxd(onemouse.cn) version 1.0.0
// @include        http://www.kaixin001.com/!house/garden/index.php*
// ==/UserScript==

var Ganov = function() {
	/**
	 * various url we need to post/get
	 */
	var conf_url = 'http://www.kaixin001.com/!house/!garden/getconf.php';
	var friend_url = 'http://www.kaixin001.com/interface/suggestfriend.php?type=all';
	var havest_url = 'http://www.kaixin001.com/!house/!garden/havest.php';
	var mature_url = 'http://www.kaixin001.com/!house/!garden/getfriendmature.php';
	var water_url = 'http://www.kaixin001.com/!house/!garden/water.php';

	/**
	 * refer to the host function
	 */
	var verify = unsafeWindow.g_verify;

	/**
	 * running state relative variables
	 */
	var _self = this;

	var msgDiv = 0;
	var btn  = null;
	var flag = false;

	var friends = [];

	var links = [];
	var cursor = 0;
	var done = 1;
	var running = 0;

	if ( !Ganov.__intialized__ ) {
		Ganov.prototype.ownerInfo = function(name, uid){
			var xurl = conf_url + '?fuid=' + uid + '&amp;r=' + Math.random() + '&amp;verify=' + verify;
			GM_xmlhttpRequest( {
				method : &quot;GET&quot;,
				url : xurl,
				onload : function(o) {
					var txt = o.responseText;
					// 没有安装该应用
					if(txt.substr(0, 5).replace(/(\s*)/,&quot;&quot;) != &quot;&lt;conf&quot;) {
						return;
					}
					// 去掉某些不可见字符。
					txt = txt.replace(/&lt;steal&gt;(.*)&lt;\/steal&gt;/,&quot;&quot;);
					var docParser = new DOMParser();
					try {
						var doc = docParser.parseFromString(txt, &quot;application/xml&quot;);

						var xml = xml2array(doc);
						var items = xml.conf.garden.item;
						var name = xml.conf.account.name
					        for(var i in items) {
							var farmNum = items[i].farmnum;

							//0 非爱心田， 1 爱心田
							var shared = items[i].shared;
							if(shared == 1) {
								//GM_log(&quot; shared go&quot;);
								continue;
							}

							var status = items[i].status;
							if(status  &lt; 1) {
								//GM_log(&quot; status go &quot;);
								continue;
							}
							/*
							var cropsid = items[i].cropsid;
							if(cropsid &lt; 1) {
								continue;
							}
							*/
							//cropsStatus = 1 , 未成熟，2 成熟, -1 偷完了。
							var cropsStatus = items[i].cropsstatus;

							if(cropsStatus != 2) {
								continue;
							}
							/*
							var water = items[i].water;
							GM_log(water);
							if(water &lt; 5) {
								// XXX to water
								_self.water(uid, farmNum);
							}
							*/
							var crops = items[i].crops;
							if(crops.indexOf(&quot;已偷&quot;) &lt; 1) {
								links.push({'name' : name, 'farmNum' : farmNum, 'fuid' : uid});
								_self.beginSteal();
							} else {
								_self.log(&quot;已经偷过 &quot; + name + &quot; &quot; + '的第' + farmNum + &quot;块地的菜了&quot;);
							}
						}

					} catch(e) {
						_self.log(e);
						_self.log(txt);
					}
				}
			});
		}

		Ganov.prototype.beginSteal = function(){
			if( !running ) {
				_self.doSteal();
				running = 1;
			}
		}

		Ganov.prototype.doSteal = function(){
			if ( done ) {
				done = 0;
				if(cursor &lt; links.length) {
					var curData = links[cursor];
					var murl = (havest_url + '?farmnum=' + curData.farmNum + '&amp;verify=' + verify + '&amp;seedid=0&amp;r=' + Math.random() + '&amp;fuid=' + curData.fuid);
					GM_xmlhttpRequest({
						method : 'GET',
						url : murl,
						onload : function(o) {
							var xml = o.responseText;
							var parser = new DOMParser();
							var doc = parser.parseFromString(xml, &quot;application/xml&quot;);
							var d = xml2array(doc);

							if(d.data.ret &amp;&amp; d.data.ret == 'fail') {
								_self.log(&quot;偷 &quot; + curData.name + &quot; 失败，原因: &quot; + d.data.reason);
							} else if(d.data.ret &amp;&amp; d.data.ret == 'succ'){
								_self.log(&quot;您偷了&quot; + curData.name + &quot;　&quot; + d.data.stealnum + ' 个 '　+　d.data.seedname);
							} else {
								_self.log(&quot;Some error occur when steal &quot; + curData.name + &quot;:&quot;　+ murl);
							}
							done = 1;
						}
					});
					cursor ++;
				}
			}
			setTimeout(_self.doSteal, 3000);
		}

		Ganov.prototype.start = function(){
			var murl = mature_url + '?verify=' + verify + '&amp;r=' + Math.random();
			GM_xmlhttpRequest(
			{
				method : 'GET',
				url : murl,
				onload : function (o) {
					var txt = o.responseText;
					var ret = [];
					try {
						eval(&quot;ret = &quot; + txt + &quot;;&quot;);
					} catch(e) {
						GM_log(&quot;get data error &quot; + murl);
						GM_log(&quot;return is &quot; + txt);
					}

					ret.friend.forEach(function(user){
						_self.ownerInfo(user.realname, user.uid);
					});
				}
			}
			);
		}

		Ganov.prototype.init = function(){
			if(!btn) {
				var x = document.createElement(&quot;div&quot;);
				x.id = &quot;m-btn-o&quot;;
				x.innerHTML = &quot;&lt;style&gt;#m-btn-o{border:solid 2px red;background-color:#ccc;left:740px;top:110px;position:absolute;}&lt;/style&gt;&quot;;
				x.innerHTML += &quot;&lt;button id='m-btn'&gt;Begin to Steal&lt;/button&gt;&quot;;
				document.body.appendChild(x);
				btn = document.getElementById(&quot;m-btn&quot;);
				btn.addEventListener(&quot;click&quot;, _self.start, false);
			}
		}

		Ganov.prototype.log = function(msg){
			if(!msgDiv) {
				var c = document.createElement(&quot;div&quot;);
				c.id = &quot;m-msg-o&quot;;
				c.innerHTML = &quot;&lt;style&gt;#m-msg{border:solid 2px red;background-color:#ccc;position:absolute;left:10px;top:100px;}&lt;/style&gt;&quot;;
				c.innerHTML += &quot;&lt;div class='title'&gt;&lt;/div&gt;&lt;div class='body' id='m-msg'&gt;&lt;/div&gt;&lt;div class='footer'&gt;&lt;/div&gt;&quot;;
				document.body.appendChild(c);
				msgDiv = document.getElementById(&quot;m-msg&quot;);
				msgDiv.innerHTML = &quot;结果:&lt;br/&gt;&quot;;
			}
			msgDiv.innerHTML += msg + &quot;&lt;br/&gt;&quot;;
		}

		Ganov.prototype.water = function(fuid, farmNum){
			GM_xmlhttpRequest({
				method : 'GET',
				url : water_url + '?fuid=' + fuid + '&amp;verify' + verify + '&amp;seedid=0&amp;farmnum=' +farmNum + '&amp;r=' + Math.random(),
				onload:function(o){GM_log(&quot;done&quot;);},
				onfaiure : function(o){GM_log(&quot;fail&quot;);}
			});
		}
		Ganov.__intialized__ = true;
	}
}

//copy from http://www.openjs.com/scripts/xml_parser/xml2array.js
var not_whitespace = new RegExp(/[^\s]/);
//This can be given inside the funciton - I made it a global variable to make the scipt a little bit faster.
var parent_count;

function xml2array(xmlDoc, parent_count){
	var arr;
	var parent = &quot;&quot;;
	parent_count = parent_count || new Object;

	var attribute_inside = 0; /*:CONFIG: Value - 1 or 0
							   *	If 1, Value and Attribute will be shown inside the tag - like this...
							   *	For the XML string...
							   *	&lt;guid isPermaLink=&quot;true&quot;&gt;http://www.bin-co.com/&lt;/guid&gt;
							   *	The resulting array will be...
							   *	array['guid']['value'] = &quot;http://www.bin-co.com/&quot;;
							   *	array['guid']['attribute_isPermaLink'] = &quot;true&quot;;
							   *
							   *	If 0, the value will be inside the tag but the attribute will be outside - like this...
							   *	For the same XML String the resulting array will be...
							   *	array['guid'] = &quot;http://www.bin-co.com/&quot;;
							   *	array['attribute_guid_isPermaLink'] = &quot;true&quot;;
							   */

	if(xmlDoc.nodeName &amp;&amp; xmlDoc.nodeName.charAt(0) != &quot;#&quot;) {
		if(xmlDoc.childNodes.length &gt; 1) { //If its a parent
			arr = new Object;
			parent = xmlDoc.nodeName;

		}
	}
	var value = xmlDoc.nodeValue;
	if(xmlDoc.parentNode &amp;&amp; xmlDoc.parentNode.nodeName &amp;&amp; value) {
		if(not_whitespace.test(value)) {//If its a child
			arr = new Object;
			arr[xmlDoc.parentNode.nodeName] = value;
		}
	}

	if(xmlDoc.childNodes.length) {
		if(xmlDoc.childNodes.length == 1) { //Just one item in this tag.
			arr = xml2array(xmlDoc.childNodes[0],parent_count); //:RECURSION:
		} else { //If there is more than one childNodes, go thru them one by one and get their results.
			var index = 0;

			for(var i=0; i&lt;xmlDoc.childNodes.length; i++) {//Go thru all the child nodes.
				var temp = xml2array(xmlDoc.childNodes[i],parent_count); //:RECURSION:
				if(temp) {
					var assoc = false;
					var arr_count = 0;
					for(key in temp) {
						if(isNaN(key)) assoc = true;
						arr_count++;
						if(arr_count&gt;2) break;//We just need to know wether it is a single value array or not
					}

					if(assoc &amp;&amp; arr_count == 1) {
						if(arr[key]) { 	//If another element exists with the same tag name before,
							//		put it in a numeric array.
							//Find out how many time this parent made its appearance
							if(!parent_count || !parent_count[key]) {
								parent_count[key] = 0;

								var temp_arr = arr[key];
								arr[key] = new Object;
								arr[key][0] = temp_arr;
							}
							parent_count[key]++;
							arr[key][parent_count[key]] = temp[key]; //Members of of a numeric array
						} else {
							parent_count[key] = 0;
							arr[key] = temp[key];
							if(xmlDoc.childNodes[i].attributes &amp;&amp; xmlDoc.childNodes[i].attributes.length) {
								for(var j=0; j&lt;xmlDoc.childNodes[i].attributes.length; j++) {
									var nname = xmlDoc.childNodes[i].attributes[j].nodeName;
									if(nname) {
										/* Value and Attribute inside the tag */
										if(attribute_inside) {
											var temp_arr = arr[key];
											arr[key] = new Object;
											arr[key]['value'] = temp_arr;
											arr[key]['attribute_'+nname] = xmlDoc.childNodes[i].attributes[j].nodeValue;
										} else {
											/* Value in the tag and Attribute otside the tag(in parent) */
											arr['attribute_' + key + '_' + nname] = xmlDoc.childNodes[i].attributes[j].nodeValue;
										}
									}
								} //End of 'for(var j=0; j&lt;xmlDoc. ...'
							} //End of 'if(xmlDoc.childNodes[i] ...'
						}
					} else {
						arr[index] = temp;
						index++;
					}
				} //End of 'if(temp) {'
			} //End of 'for(var i=0; i&lt;xmlDoc. ...'
			}
		}
		if(parent &amp;&amp; arr) {
			var temp = arr;
			arr = new Object;

			arr[parent] = temp;
		}
		return arr;
}
var ganov = new Ganov();
ganov.init();
</pre>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/06/01</a>, <a href="http://onemouse.cn"  rel="external nofollow"  class="url" >anders</a> writes: 我已经决定不玩了这个东西了，本来我以为，我可以买所有的菜以后，我就不玩了，没有想到他又出来一个养动物的，太麻烦了，所以就戒了!</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/06/01</a>, laruence writes: 恩, 我是拿来练练手, 最近研究JS的一些机制</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/06/01</a>, <a href="http://www.neatcn.com"  rel="external nofollow"  class="url" >膘叔</a> writes: 想不到。。。用JS来完成这些操作，很意外。。
不过没测试过</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/06/03</a>, anders writes: 一样的名字么？</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/06/05</a>, toms writes: 不好意思， 我又来了，我怎么在在父框架调用iframe里的函数啊</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/06/05</a>, laruence writes: 可以通过iframe.contentWindow来获取iframe的window对象</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/06/07</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 开心网最近搞了个"花园精灵",类似图片验证码之类的, 导致这个脚本运行的时候可能会不作用, 这个时候需要手动输入下那个验证就可以继续使用了</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/06/09</a>, eve writes: 忠实用户觉得最好把爱心地也能自动收获了，最好把自己田里的也收获了</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2009/12/17</a>, <a href="http://www.mreporter.net/page/24/"  rel="external nofollow"  class="url" >Тамара</a> writes: Кажется, это подойдет.</li><li><a href="http://www.laruence.com/2009/06/01/905.html" >2010/05/05</a>, apple writes: 好，不错</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/09/08/1076.html"  title="深入理解Javascript之this关键字" >深入理解Javascript之this关键字</a></li><li><a href="http://www.laruence.com/2009/05/21/829.html"  title="JS文件装载器(Eve Js Loader)" >JS文件装载器(Eve Js Loader)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/06/01/905.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Javascript作用域原理</title>
		<link>http://www.laruence.com/2009/05/28/863.html</link>
		<comments>http://www.laruence.com/2009/05/28/863.html#comments</comments>
		<pubDate>Thu, 28 May 2009 09:11:31 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[javascript预编译]]></category>
		<category><![CDATA[scope chain]]></category>
		<category><![CDATA[作用域]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=863</guid>
		<description><![CDATA[	首先看一个例子:
	<coolcode lang="javascript" linenum="off">
var name = 'laruence';
function echo() {
	alert(name);
	var name = 'eve';
	alert(name);
	alert(age);
}

echo();
	</coolcode>
	运行结果是什么呢? ]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2009/05/28/863.html"  title="Permanet Link to Javascript作用域原理" >http://www.laruence.com/2009/05/28/863.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p><h2>问题的提出</h2>
<p>	首先看一个例子:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
var name = 'laruence';
function echo() {
	alert(name);
	var name = 'eve';
	alert(name);
	alert(age);
}

echo();
</pre>
<p>	运行结果是什么呢?
</p>
<p>
	上面的问题, 我相信会有很多人会认为是:</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
laruence
eve
[脚本出错]
</pre>
<p>	因为会以为在echo中, 第一次alert的时候, 会取到全局变量name的值, 而第二次值被局部变量name覆盖, 所以第二次alert是&#8217;eve&#8217;. 而age属性没有定义, 所以脚本会出错.</p>
<p>	但其实, 运行结果应该是:</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
undefined
eve
[脚本出错]
</pre>
<p>	为什么呢? </p>
<h2>JavaScript的作用域链</h2>
<p>	首先让让我们来看看Javasript(简称JS, 不完全代表JScript)的作用域的原理: JS权威指南中有一句很精辟的描述:　&#8221;JavaScript中的函数运行在它们被定义的作用域里,而不是它们被执行的作用域里.&#8221;　</p>
<p>	为了接下来的知识, 你能顺利理解, 我再提醒一下, 在JS中:&#8221;一切皆是对象, 函数也是&#8221;.</p>
<p>	在JS中，作用域的概念和其他语言差不多， 在每次调用一个函数的时候 ，就会进入一个函数内的作用域，当从函数返回以后，就返回调用前的作用域.</p>
<p>	JS的语法风格和C/C++类似, 但作用域的实现却和C/C++不同，并非用“堆栈”方式，而是使用列表，具体过程如下(ECMA262中所述):<br/>
	 任何执行上下文时刻的作用域, 都是由作用域链(scope chain, 后面介绍)来实现.<br/>
	 在一个函数被定义的时候, 会将它定义时刻的scope chain链接到这个函数对象的[[scope]]属性.<br/>
	 在一个函数对象被调用的时候，会创建一个活动对象(也就是一个对象), 然后对于每一个函数的形参，都命名为该活动对象的命名属性, 然后将这个活动对象做为此时的作用域链(scope chain)最前端, 并将这个函数对象的[[scope]]加入到scope chain中.</p>
<p>     看个例子:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
	var func = function(lps, rps){
		var name = 'laruence';
		........
	}
	func();
</pre>
<p>    在执行func的定义语句的时候, 会创建一个这个函数对象的[[scope]]属性(内部属性,只有JS引擎可以访问, 但FireFox的几个引擎(SpiderMonkey和Rhino)提供了私有属性__parent__来访问它), 并将这个[[scope]]属性, 链接到定义它的作用域链上(后面会详细介绍), 此时因为func定义在全局环境, 所以此时的[[scope]]只是指向全局活动对象window active object.</p>
<p>	在调用func的时候, 会创建一个活动对象(假设为aObj, 由JS引擎预编译时刻创建, 后面会介绍)，并创建arguments属性, 然后会给这个对象添加俩个命名属性aObj.lps, aObj.rps; 对于每一个在这个函数中申明的局部变量和函数定义, 都作为该活动对象的同名命名属性.</p>
<p>	然后将调用参数赋值给形参数，对于缺少的调用参数，赋值为undefined。 </p>
<p>	然后将这个活动对象做为scope chain的最前端, 并将func的[[scope]]属性所指向的,定义func时候的顶级活动对象, 加入到scope chain.</p>
<p>	有了上面的作用域链, 在发生标识符解析的时候, 就会逆向查询当前scope chain列表的每一个活动对象的属性，如果找到同名的就返回。找不到，那就是这个标识符没有被定义。</p>
<p>	注意到, 因为函数对象的[[scope]]属性是在定义一个函数的时候决定的, 而非调用的时候, 所以如下面的例子:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
	var name = 'laruence';
	function echo() {
		alert(name);
	}

	function env() {
		var name = 'eve';
		echo();
	}

	env();
</pre>
<p>	运行结果是:</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
laruence
</pre>
<p>	结合上面的知识, 我们来看看下面这个例子:</p>
<pre name="code"  class="sh_php"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
function factory() {
	var name = 'laruence';
	var intro = function(){
		alert('I am ' + name);
	}
	return intro;
}

function app(para){
	var name = para;
	var func = factory();
	func();
}

app('eve');
</pre>
<p>    当调用app的时候, scope chain是由: {window活动对象(全局)}->{app的活动对象} 组成. </p>
<p>	在刚进入app函数体时, app的活动对象有一个arguments属性, 俩个值为undefined的属性: name和func. 和一个值为&#8217;eve&#8217;的属性para;</p>
<p>	此时的scope chain如下:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
[[scope chain]] = [
{
	para : 'eve',
	name : undefined,
	func : undefined,
	arguments : []
}, {
	window call object
}
]
</pre>
<p>	当调用进入factory的函数体的时候, 此时的factory的scope chain为:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
[[scope chain]] = [
{
	name : undefined,
	intor : undefined
}, {
	window call object
}
]
</pre>
<p>	注意到, 此时的作用域链中, 并不包含app的活动对象.</p>
<p>	在定义intro函数的时候, intro函数的[[scope]]为:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
[[scope chain]] = [
{
	name : 'laruence',
	intor : undefined
}, {
	window call object
}
]
</pre>
<p>	从factory函数返回以后,在app体内调用intor的时候, 发生了标识符解析, 而此时的sope chain是:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
[[scope chain]] = [
{
	intro call object
}, {
	name : 'laruence',
	intor : undefined
}, {
	window call object
}
]
</pre>
<p>    因为scope chain中,并不包含factory活动对象. 所以, name标识符解析的结果应该是factory活动对象中的name属性, 也就是&#8217;laruence&#8217;.</p>
<p>	所以运行结果是:</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
I am laruence
</pre>
<p>	现在, 大家对&#8221;JavaScript中的函数运行在它们被定义的作用域里,而不是它们被执行的作用域里.&#8221;这句话, 应该有了个全面的认识了吧?
</p>
<p><h2>Javascript的预编译</h2>
<p>	我们都知道,JS是一种脚本语言, JS的执行过程, 是一种翻译执行的过程.<br/>
	那么JS的执行中, 有没有类似编译的过程呢?</p>
<p>	首先, 我们来看一个例子:</p>
<pre name="code"  class="sh_php"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
	&lt;script&gt;
	alert(typeof eve); //function
		function eve() {
			alert('I am Laruence');
		};
	&lt;/script&gt;
</pre>
<p>	诶? 在alert的时候, eve不是应该还是未定义的么? 怎么eve的类型还是function呢?</p>
<p>	恩, 对, 在JS中, 是有预编译的过程的, JS在执行每一段JS代码之前, 都会首先处理var关键字和function定义式(函数定义式和函数表达式).<br/>
	如上文所说, 在调用函数执行之前, 会首先创建一个活动对象, 然后搜寻这个函数中的局部变量定义,和函数定义, 将变量名和函数名都做为这个活动对象的同名属性, 对于局部变量定义,变量的值会在真正执行的时候才计算, 此时只是简单的赋为undefined. </p>
<p>	而对于函数的定义,是一个要注意的地方: </p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;script&gt;
	alert(typeof eve); //结果:function
	alert(typeof walle); //结果:undefined
	function eve() { //函数定义式
		alert('I am Laruence');
	};
	var walle = function() { //函数表达式
	}
	alert(typeof walle); //结果:function
&lt;/script&gt;
</pre>
<p>	这就是函数定义式和函数表达式的不同, 对于函数定义式, 会将函数定义提前. 而函数表达式, 会在执行过程中才计算.</p>
<p>	说到这里, 顺便说一个问题 :</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
	var name = 'laruence';
	age = 26;
</pre>
<p>	我们都知道不使用var关键字定义的变量, 相当于是全局变量, 联系到我们刚才的知识:</p>
<p>	在对age做标识符解析的时候, 因为是写操作, 所以当找到到全局的window活动对象的时候都没有找到这个标识符的时候, 会在window活动对象的基础上, 返回一个值为undefined的age属性.</p>
<p>	也就是说, age会被定义在顶级作用域中.</p>
<p>	现在, 也许你注意到了我刚才说的: JS在执行<b>每一段JS代码</b>..<br/>
	对, 让我们看看下面的例子:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;script&gt;
	alert(typeof eve); //结果:undefined
&lt;/script&gt;
&lt;script&gt;
	function eve() {
		alert('I am Laruence');
	}
&lt;/script&gt;
</pre>
<p>	明白了么? 也就是JS的预编译是以段为处理单元的&#8230;
</p>
<p><h2>揭开谜底</h2>
<p>	现在让我们回到我们的第一个问题:</p>
<p>	当echo函数被调用的时候, echo的活动对象已经被预编译过程创建, 此时echo的活动对象为:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
[callObj] = {
name : undefined
}
</pre>
<p>	当第一次alert的时候, 发生了标识符解析, 在echo的活动对象中找到了name属性, 所以这个name属性, 完全的遮挡了全局活动对象中的name属性.</p>
<p>	现在你明白了吧?
</p>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_php.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_php.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/05/25</a>, <a href="http://fdream.net"  rel="external nofollow"  class="url" >Fdream</a> writes: 从变量和函数的预解析方面来讲可能会容易理解一点～</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/05/25</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 受教了, 看到一些很新的东西, 谢谢~</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/05/26</a>, <a href="http://54chen.com"  rel="external nofollow"  class="url" >cc0cc</a> writes: yahoo克军对这个搞得比较透彻，js的原型链，听他搞过tech talk</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/05/26</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 克军可是大牛啊..当初我们一起封闭开发的时候, 就已经领略到他的深厚功底了..</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/05/27</a>, shankka writes: "而当b()在内部调用a()的时候，a()的[[scope]]由:全局活动对象-&gt;b的活动对象-&gt;a的活动对象组成。"
这句貌似是有问题的，比如下面这个例子

var name = 'shankka';

var myEchoName = function () {
	document.writeln(name);
};

var myEchoCaller = function () {
	var name = 'cc';
	myEchoName();
};

myEchoCaller();

运行结果是shankka而不是cc。

用“当函数被另一个函数调用的时候，this被绑定到全局变量中，而不是被绑定到外部函数的this上”才能解释通

（没有找到你blog的引用地址，就在评论里写了）</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/05/27</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 恩,恩,这句是有问题, 这句是我原来的那篇里面直接扣过来的. sorry</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/05/28</a>, <a href="http://www.laruence.com/2008/07/28/210.html"  rel="external nofollow"  class="url" >关于JavaScript的执行域,标识符解析,闭包的研究 | 风雪之隅</a> writes: [...] 请以:Javascript作用域原理为准. [...]</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/05/28</a>, toms writes: 

结果为1//1

php这是咋的啦?

请原谅我在这里贴这个问题， 因为我估计你很少看留言板 sorry</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/05/28</a>, toms writes: 代码是
echo 'a'==0,'/';
echo 'a'==false,'/';
echo 0==false;</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/05/28</a>, toms writes: 突然看倒答案了，不用大搅了， 谢谢</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/05/28</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: ;) ~~~</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/05/29</a>, sky writes: 函数的表达式和定义式准确地区别是什么呢？难道只要填充任意一个语句就是定义式?</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/06/05</a>, hiwi writes: 学习了，http://blog.360.yahoo.com/blog-sOW1QOA9crUyOdXFxOeK4xc-?cq=1&amp;l=171&amp;u=175&amp;mx=191&amp;lmt=5这个是克军的blog吗？</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/06/05</a>, laruence writes: 是啊.....</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/09/05</a>, <a href="http://www.jiuaita.com/?p=59"  rel="external nofollow"  class="url" >分享一个好网站 &raquo; 每天好心情</a> writes: [...] http://www.laruence.com/2009/05/28/863.html [...]</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/09/07</a>, swit1983 writes: 怎么将活动对象加入到作用域链中啊？比如：

  function thisTest(){
  alert(this.value); // 弹出undefined, this在这里指向??
}



第2种正确



  function thisTest(){
  alert(this.value); 
}
document.getElementById("btnTest").onclick=thisTest; //给button的onclick事件注册一个函数

像这样的注册方式可以将window 变成了 button</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/09/07</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 谁调用,谁就是this, 监听时间是被被监听对象所调用的.</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/09/08</a>, swit1983 writes: 你不是说过this指向当前的活动对象吗？那这样呢
function thisTest()
{
   this.userName= 'outer userName';
   function innerThisTest(){
     var userName="inner userName";
     alert(userName); //inner userName
     alert(this.userName); //outer userName
     }
     return innerThisTest;
}

var a = thisTest();
//我的理解作用域链thisTest-&gt;window
a();
//作用域链innerThisTest-&gt;thisTest-&gt;window

而且我将var 改成 this 会有很大的区别，为什么this里面没有取到var所定义的参数?是应为你说的预编译的时候对标示符解析的原因吗？</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/09/08</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @swit1983 啊? 我在哪里说的? 如果有, 那就是我说顺口, 说错了.....sorry, 你可以参看我的最新博文.</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/09/08</a>, swit1983 writes: 你4月9号说的，为什么我的this.userName 不是得到 innerThis中的 var userName 而是 thisTest里面的啊，如果我将innerThis中的 var 改成this又可以了</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/09/08</a>, <a href="http://www.xidea.org"  rel="external nofollow"  class="url" >jindw</a> writes: 还有更多看起来很离谱的事情呢。
比如：

function test(xxx){
   alert(xxx)
   var xxx = 123;
   function xxx(){
   }
   alert(xxx)
}
test(444);

输出的是 function,123

函数调用的时候，scope关系好像是这样的：

enter argumentMap;
enter functionMap;
enter varMap;
apply();
exitScope();



function 编译的时候，首先被声明，他升值</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/09/08</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @jindw 这个是因为var和function定义在预编译的时候被提前. 而var提前只是占位,计算留在后面执行的过程.
所以第一次xxx是function, 到第二个的时候, xxx被var  xxx=123给改写成了123.</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/10/19</a>, Anonymous writes: 好文</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2009/11/10</a>, <a href="http://www.longlinfeng.com"  rel="external nofollow"  class="url" >马克龙</a> writes: ：）受教了</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2010/05/03</a>, palgerrard writes: 研究的很深入！非常感谢你的分享~</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2010/09/21</a>, Wxl writes: 受教了
顺道请教个问题
怎么访问私有的 活动变量？
比如
函数内的活动变量   应该存放在一个集合里吧

function a(){
    
    
    var test = 'test';
    
    function _get(name){
        return name;
    }
    
    return function(){
        
        _get("test");
    }
}()</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2010/09/29</a>, <a href="http://www.narcostyle.com"  rel="external nofollow"  class="url" >narco</a> writes: 拜读^_^</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2011/03/03</a>, <a href="http://www.skygq.com/2011/03/03/javascipt-this/"  rel="external nofollow"  class="url" >（经典）关于Javascript之this关键字(转) | 梦三秋</a> writes: [...] 如我之前的文章所述(Javascript作用域), 定义在全局的函数, 函数的所有者就是当前页面, 也就是window对象. [...]</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2011/03/08</a>, <a href="http://www.qijichao.com/index.php/classic-of-this-keyword-on-javascript.html"  rel="external nofollow"  class="url" >（经典）关于Javascript之this关键字 &#8211; 爱网络,爱前端</a> writes: [...] 如我之前的文章所述(Javascript作用域), 定义在全局的函数, 函数的所有者就是当前页面, 也就是window对象. [...]</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2011/03/09</a>, <a href="http://zhidao.123doing.com/165778.html"  rel="external nofollow"  class="url" >作用域内的似有成员 都存放在哪？ - Web开发常见问题 - [标签:tags] - 开源网 | 123Doing</a> writes: [...] http://www.laruence.com/2009/05/28/863.html [...]</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2011/03/24</a>, <a href="http://jikey.cnblogs.com"  rel="external nofollow"  class="url" >豪情</a> writes: 帅哥，你的变量名也就罢了，方法名太不容易理解了。
app,echo，让不熟悉php的朋友很难记住。
为何不用简单的sayName and sayHello 来实例呢？</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2011/03/29</a>, 小哥 writes: 鸟哥，看了5、6遍，有些地方不明白，不知道能不能帮我解答下。

function t1(){
   function t2(){
     
   }
}

像这样形式的函数,定义t2函数的时候是在函数t1里面，那是不是t1的[[scope]]是连接到t1的作用域里面？如果不是，那是连接到window下？</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2011/03/30</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @小哥 没明白你的问题, 你是问t2的作用域和t1的作用域连的关系?</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2011/07/29</a>, henry writes: 并将func的[[scope]]属性所指向的,定义func时候的顶级活动对象, 加入到scope china.

一个小拼写错误：scope china 应该是 scope chain</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2011/07/29</a>, raintree writes: 要是能用普通的定义和解释方式多好啊</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2011/08/28</a>, 小哥 writes: 请问一下，那这个执行函数才会创建的活动对象是不是就是指 ‘上下文’？</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2011/10/22</a>, 袖之欢 writes: 想请问一下,为什么从factory函数返回以后,仍然是"intro:undefined"呢~~</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2011/10/23</a>, <a href="http://www.xudafeng.com/"  rel="external nofollow"  class="url" >xdf</a> writes: factory函数返回undefined</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2011/10/24</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @henry fixed, thanks :)</li><li><a href="http://www.laruence.com/2009/05/28/863.html" >2011/11/19</a>, wkylin writes: __parent__你确定是这个吗？？</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2012/01/07/2453.html"  title="2012年1月全球www网站技术报告" >2012年1月全球www网站技术报告</a></li><li><a href="http://www.laruence.com/2010/12/08/1716.html"  title="如何获取一个变量的名字" >如何获取一个变量的名字</a></li><li><a href="http://www.laruence.com/2010/05/13/1462.html"  title="Javascript原型链和原型的一个误区" >Javascript原型链和原型的一个误区</a></li><li><a href="http://www.laruence.com/2010/01/21/1254.html"  title="IE下var的重要性的又一佐证" >IE下var的重要性的又一佐证</a></li><li><a href="http://www.laruence.com/2009/09/27/1123.html"  title="关于Javascript的俩个有趣的探讨" >关于Javascript的俩个有趣的探讨</a></li><li><a href="http://www.laruence.com/2009/09/23/1089.html"  title="深入理解JavaScript定时机制" >深入理解JavaScript定时机制</a></li><li><a href="http://www.laruence.com/2009/09/08/1076.html"  title="深入理解Javascript之this关键字" >深入理解Javascript之this关键字</a></li><li><a href="http://www.laruence.com/2009/08/09/1036.html"  title="正确使用JS中的正则" >正确使用JS中的正则</a></li><li><a href="http://www.laruence.com/2009/05/18/809.html"  title="使用JS做文档处理" >使用JS做文档处理</a></li><li><a href="http://www.laruence.com/2009/05/17/815.html"  title="关于事件模拟" >关于事件模拟</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/05/28/863.html/feed</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>JS文件装载器(Eve Js Loader)</title>
		<link>http://www.laruence.com/2009/05/21/829.html</link>
		<comments>http://www.laruence.com/2009/05/21/829.html#comments</comments>
		<pubDate>Thu, 21 May 2009 07:57:50 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[javascript loader]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[js loader]]></category>
		<category><![CDATA[js 装载器]]></category>
		<category><![CDATA[loader]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=829</guid>
		<description><![CDATA[  最近的项目中,需要对于不同的用户角色分别读取不同的的JS文件簇, 从而避免一次载入全部JS文件,  于是就写了一个简单的JS Loader.
  
  这个loader, 每次载入一个js文件, 在前一个文件完全载入后, 才继续载入下一个文件. 

  Loader提供了俩个事件:
  		1. onLoad  每当一个单独的js文件被载入完成后, 就会调用这个事件函数.
		2. onReady 当全部载入完成后, 会调用OnReady事件处理函数

一个完整的实例, 看这里: <a href='/wp-content/uploads/jsloader.html' target='_blank'> Eve Js loader</a>]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2009/05/21/829.html"  title="Permanet Link to JS文件装载器(Eve Js Loader)" >http://www.laruence.com/2009/05/21/829.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>
  最近的项目中,需要对于不同的用户角色分别读取不同的的JS文件簇, 从而避免一次载入全部JS文件,  于是就写了一个简单的JS Loader.</p>
<p>  这个loader, 每次载入一个js文件, 在前一个文件完全载入后, 才继续载入下一个文件. </p>
<p>  Loader提供了俩个事件:</p>
<li> onLoad  每当一个单独的js文件被载入完成后, 就会调用这个事件函数.</li>
<li> onReady 当全部载入完成后, 会调用OnReady事件处理函数. </li>
<p> <br/><br/>
 <b> 一个完整的实例, 看这里: <a href="/wp-content/uploads/jsloader.html"  target="_blank" > Eve Js loader</a></b></p>
<p>  例子:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
  var loader = Loader;
  loader.onReady = function(){
     alert('全部载入完成');
  }

  loader.on('onLoad', function(name) {
      alert(name + '载入完成');
  });
  loader.load([
  	'http://www.laruence.com/1.js',
  	'http://www.laruence.com/test.js',
  	'http://www.laruence.com/main.js'
	]
</pre>
<p>  Loader.js</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
/**
 * Eve Js Loader
 * @version 1.0.1
 * @author laruence&lt;laruence at yahoo.com.cn&gt;
 * @copyright (c) 2009 www.laruence.com
 */ 

/**
 * a global object instance, you can easily change to a class definition
 */
var Loader = {
	/**
	 * @var onLoad  when load a individual file completed ,
	 * this event will be fired * @param string name  loaded script file name
	 */
    onLoad : function(name){},
	/**
	 * @var onReady when all scripts loaded, this event will be fired
	 */
    onReady : function(){},
	/**
	 * a empty constructor
	 */
    init : function(container) {
    },
	/**
	 * a empty error handler
	 */
    handlerError : function(e) {
        alert(e);
    },
	/**
	 * event register
	 * @param string evt  event name
	 * @param function handler
	 */
    on : function(evt, handler) {
        switch ( evt.toLowerCase() ) {
            case 'load' :
                this.onLoad = handler;
            break;
            case 'ready' :
                this.onReady = handler;
            break;
            default :
            break;
        }
        return true;
     },
	/**
	 * private method
	 */
    _load : function(path, callback) {
        try {
            var script = document.createElement('script');
            script.src = path;
            script.type = &quot;text/javascript&quot;;
            document.getElementsByTagName(&quot;head&quot;)[0].appendChild(script);
            if( script.addEventListener ) {
                script.addEventListener(&quot;load&quot;, callback, false);
            } else if(script.attachEvent) {
                script.attachEvent(&quot;onreadystatechange&quot;, function(){
                        if(script.readyState == 4
                            || script.readyState == 'complete'
                            || script.readyState == 'loaded') {
                            callback();
                        }
                });
            }
        } catch(e) {
            this.handlerError(e);
			callback();
        }
    },
	/**
	 * start loding process
	 * @param array scripts  files want to be loaded
	 */
    load : function(scripts) {
        var total = scripts.length;
        var _self  = this;
        var indicator = arguments[1] || 0;
        if ( indicator &gt;= total ) {
            _self.onReady();
            return true;
		}

        var callee = arguments.callee;
        var script = scripts[indicator];
        this._load(script, function() {
            _self.onLoad(script);
            callee.apply(_self, [scripts, ++indicator]);
        });
        return true;
    }
}
</pre>
</p>
<p>
   备忘:  http://code.google.com/p/evejsloader/
</p>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/05/21/829.html" >2009/05/23</a>, toms writes: 在你这个blog上我学到了很多东西，记得你有此在某篇文章里提到php编译执行，你为什么不写一个出来了， 我第一个愿意用~——~</li><li><a href="http://www.laruence.com/2009/05/21/829.html" >2009/05/23</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 呵呵, 这个只是个设想, 目前来讲,APC已经可以实现了.....</li><li><a href="http://www.laruence.com/2009/05/21/829.html" >2009/08/13</a>, <a href="http://www.longlinfeng.com"  rel="external nofollow"  class="url" >longlinfeng</a> writes: loader.on('onLoad', function(name) {
      alert(name + '载入完成');
  });
----------应该是？----------
loader.on('load', function(name) {
      alert(name + '载入完成');
  });</li><li><a href="http://www.laruence.com/2009/05/21/829.html" >2009/08/13</a>, <a href="http://www.longlinfeng.com"  rel="external nofollow"  class="url" >longlinfeng</a> writes: laruence，附加一个问题：Eve Js Loader只能在页面加载完成（形成DOM树）后才开始工作，如果用户在页面加载完成后立即操作，这时候该如何给用户反馈？

当然，可以采用loading进度条的方式，提前提醒用户等待。</li><li><a href="http://www.laruence.com/2009/05/21/829.html" >2009/08/13</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 恩, loader的初衷是为了按需加载. 当项目的js文件很大的时候,会有帮助. 
当,要使用的对象不存在, 则去load相应的js文件, 回调函数中继续执行.</li><li><a href="http://www.laruence.com/2009/05/21/829.html" >2009/08/14</a>, <a href="http://www.longlinfeng.com"  rel="external nofollow"  class="url" >longlinfeng</a> writes: 当要使用的对象不存在, 则去load相应的js文件, 回调函数中继续执行？？

恩。

那Js能不能实现PHP中auto_load()的效果呢，对象不存在时自动去加载？</li></ul><hr/><h2>Related posts:</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/08/09/1036.html"  rel="bookmark"  title="Permanent Link: 正确使用JS中的正则" >正确使用JS中的正则</a></li><li><a href="http://www.laruence.com/2009/05/18/809.html"  rel="bookmark"  title="Permanent Link: 使用JS做文档处理" >使用JS做文档处理</a></li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/09/08/1076.html"  title="深入理解Javascript之this关键字" >深入理解Javascript之this关键字</a></li><li><a href="http://www.laruence.com/2009/06/01/905.html"  title="开心网偷菜外挂" >开心网偷菜外挂</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/05/21/829.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>使用JS做文档处理</title>
		<link>http://www.laruence.com/2009/05/18/809.html</link>
		<comments>http://www.laruence.com/2009/05/18/809.html#comments</comments>
		<pubDate>Mon, 18 May 2009 02:48:46 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[fso]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[利用Javascript编写ActiveX控件]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=809</guid>
		<description><![CDATA[  最近应友人邀请, 要帮忙写个文档处理脚本,  考虑到如果使用PHP或者Perl需要在友人的机器上,搭建一个运行环境,比较复杂, 使用起来也不友好, 本着以人为本的信念, 决定采用hta实现.
  
   本文就使用js来实现文档处理, 和使用js编写ActiveX做一个简单介绍
  ....]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2009/05/18/809.html"  title="Permanet Link to 使用JS做文档处理" >http://www.laruence.com/2009/05/18/809.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>    最近应友人邀请, 要帮忙写个文档处理脚本,  考虑到如果使用PHP或者Perl需要在友人的机器上,搭建一个运行环境,比较复杂, 使用起来也不友好, 本着以人为本的信念, 决定采用hta实现.</p>
<p>    其实, 在Windows平台上, js可以调用很多Windows提供的ActivexObject, 在这个意义上来说, 用js写HTA时, js已经不再是传统意义上的Web客户端脚本了, 它已经有些类似于VB了.</p>
<p>    本文就使用js来实现文档处理, 和使用js编写ActiveX做一个简单介绍.</p>
<p>    言归正传, 友人的需求是: 把一个文件夹下的所有文件内容都读出来, 并且每个文件做为一个Excel的Sheet, 写入一个固定Excel中.</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
    难点 :
　　　　1. 读取文件
              我们知道， js本身并没有读写文件的API。
          2. 写入Excel
              写入Excel，并且有多个Sheet是个难点。
</pre>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
    解决方案：
          1. 采用FileSystemObject ActiveX Object 来实现文件读取，文件夹遍历
          2. 采用Excel Application ActiveX Object 来实现写Excel
</pre>
<p>    采用FSO遍历文件夹：</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
                var path = 'C:\\folder\\';
		var fso  = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;); //创建一个FSO实例
		var dir = fso.GetFolder(path);
		var fc = new Enumerator(dir.files); //构建可枚举实例
                var file = {};
		for(; !fc.atEnd(); fc.moveNext()) {
			file = fc.item(); //包含文件名
		        alert(file);
		}
</pre>
<p>   写Excel:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
		// var files  包含了所有要文件路径的数组， 由上面的逻辑提供
		var fso  = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;);
		try {
			var excelApp  = new ActiveXObject(&quot;Excel.Application&quot;);
		} catch (e) {
			alert(&quot;请确保您安装了 MS-EXCEL &quot;);
			return;
		}
		var excelBook = excelApp.Workbooks.Add();
		var excelSheet;
		var current = 1;
		for ( var file  in files ) {
			excelBook.Worksheets.Add();
			excelSheet = excelBook.WorkSheets(current++);
			excelSheet.name = file; //命名sheet
			//开始读取文件
			var fh = fso.OpenTextFile(file, 1/*reading*/);
			var content = '';
			while ( !fh.AtEndOfStream ) {
				  content += fh.ReadLine();
			}
			fh.close()

			excelSheet.Cells(1, 1).Value = content + '\t'; //写入
		}
		excelApp.ActiveWorkbook.SaveAs(&quot;C:\\TEST.XLS&quot;); //保存Excel文件
		excelSheet.Application.Quit();
  </pre>
<p>  用js来实现， 觉得最爽的就是调用ActiveX Obj，  完全不用我考虑太多~~ , 爽~
</p>
<p><strong>附录, 转载一个有趣的文章</strong>:<br/>
<strong>WSC脚本部件技术：利用Javascript编写ActiveX控件</strong></p>
<p>一个简单的例子：<br/>
将如下代码另存为.wsc文件，并右键“注册”（卸载时右键“不注册”）。</p>
<pre name="code"  class="sh_xml"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;Component&gt;
&lt;registration ProgId=hello.world /&gt;
&lt;public&gt;
        &lt;property name=testStr /&gt;
        &lt;method name=add&gt;
                &lt;parameter name=x /&gt;
                &lt;parameter name=y /&gt;
        &lt;/method&gt;
&lt;/public&gt;
&lt;script&gt;
var testStr=&quot;默认值&quot;;
function add(x, y)
{
        return x+&quot; + &quot;+y+&quot; = &quot;+(x+y);
}
&lt;/script&gt;
&lt;/Component&gt;
</pre>
<p>然后可以通过new ActiveXObject(&#8220;hello.world&#8221;)的方法来调用该控件。<br/>
例如：（另存为.js后双击运行。）</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
var com=new ActiveXObject(&quot;hello.world&quot;);
WSH.Echo(com.testStr);
WSH.Echo(com.add(84,25));
</pre>
<p>这样就可以将javascript代码嵌入到其他编程语言中。</p>
<p>另外，不注册也可以调用该控件，例如：（另存为.js后双击运行。）</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
var com=GetObject(&quot;script:http://www.zope.org/Members/Rimifon/ZopeTest/Sample.wsc&quot;);
WSH.Echo(com.testStr);
WSH.Echo(com.add(84,25));
</pre>
<p>注意的是，JS的GetObject方法因为安全限制，在IE下可能是不能运行的。</p>
<p>另外 还可以使用<br/>
regsvr32 http://www.zope.org/Members/Rimifon/ZopeTest/Sample.wsc<br/>
指令对远程脚本部件进行本地注册，也可以使用：<br/>
regsvr32 http://www.zope.org/Members/Rimifon/ZopeTest/Sample.wsc /u<br/>
进行卸载
</p>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_xml.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/05/18/809.html" >2009/05/18</a>, <a href="http://54chen.com"  rel="external nofollow"  class="url" >cc0cc</a> writes: 没被当木马干掉？
哈哈
还是perl才是王道</li><li><a href="http://www.laruence.com/2009/05/18/809.html" >2009/05/18</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: perl是王道,,,只是windows下,友人还是女孩,要考虑实际情况么....</li><li><a href="http://www.laruence.com/2009/05/18/809.html" >2009/05/18</a>, ttplay writes: 学习了. 感觉与vbs没多大区别</li><li><a href="http://www.laruence.com/2009/05/18/809.html" >2009/06/10</a>, daniel writes: It's a little jealous about your js ability...^_^</li><li><a href="http://www.laruence.com/2009/05/18/809.html" >2009/07/16</a>, <a href="http://www.324hour.cn"  rel="external nofollow"  class="url" >出国打工</a> writes: 这样挺好的，很喜欢</li><li><a href="http://www.laruence.com/2009/05/18/809.html" >2009/09/05</a>, pchao writes: 看不是很懂啊,新手,以后会长来学习</li><li><a href="http://www.laruence.com/2009/05/18/809.html" >2010/09/10</a>, <a href="http://www.cheapclshoes.com"  rel="external nofollow"  class="url" >christian louboutin</a> writes: 呵呵 代码很强大啊！perl才是天道</li></ul><hr/><h2>Related posts:</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/08/09/1036.html"  rel="bookmark"  title="Permanent Link: 正确使用JS中的正则" >正确使用JS中的正则</a></li><li><a href="http://www.laruence.com/2009/05/21/829.html"  rel="bookmark"  title="Permanent Link: JS文件装载器(Eve Js Loader)" >JS文件装载器(Eve Js Loader)</a></li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2012/01/07/2453.html"  title="2012年1月全球www网站技术报告" >2012年1月全球www网站技术报告</a></li><li><a href="http://www.laruence.com/2010/05/13/1462.html"  title="Javascript原型链和原型的一个误区" >Javascript原型链和原型的一个误区</a></li><li><a href="http://www.laruence.com/2010/01/21/1254.html"  title="IE下var的重要性的又一佐证" >IE下var的重要性的又一佐证</a></li><li><a href="http://www.laruence.com/2009/09/27/1123.html"  title="关于Javascript的俩个有趣的探讨" >关于Javascript的俩个有趣的探讨</a></li><li><a href="http://www.laruence.com/2009/09/23/1089.html"  title="深入理解JavaScript定时机制" >深入理解JavaScript定时机制</a></li><li><a href="http://www.laruence.com/2009/09/08/1076.html"  title="深入理解Javascript之this关键字" >深入理解Javascript之this关键字</a></li><li><a href="http://www.laruence.com/2009/08/09/1036.html"  title="正确使用JS中的正则" >正确使用JS中的正则</a></li><li><a href="http://www.laruence.com/2009/05/28/863.html"  title="Javascript作用域原理" >Javascript作用域原理</a></li><li><a href="http://www.laruence.com/2009/05/17/815.html"  title="关于事件模拟" >关于事件模拟</a></li><li><a href="http://www.laruence.com/2008/09/01/492.html"  title="Js处理Json的&#8221;invalid label&#8221;错" >Js处理Json的&#8221;invalid label&#8221;错</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/05/18/809.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>关于事件模拟</title>
		<link>http://www.laruence.com/2009/05/17/815.html</link>
		<comments>http://www.laruence.com/2009/05/17/815.html#comments</comments>
		<pubDate>Sun, 17 May 2009 03:29:13 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[随笔]]></category>
		<category><![CDATA[createEvent]]></category>
		<category><![CDATA[CreateEventObj]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[事件模拟]]></category>
		<category><![CDATA[自动化]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=815</guid>
		<description><![CDATA[<p>
	如果用greaseMonkey编写脚本来做一些Web自动化的事情, 最关键的点会是哪里呢?
	"模拟浏览器事件",
	
	试想, 如果一定按钮, 点击以后, 触发了一系列的动作, 
	如果使用脚本去实现自动化, 那么我们必须去寻找这一系列的动作, 然后找到切入点函数, 模拟参数, 调用. 这会是个很复杂的过程...

	但是, 如果我们采用"模拟浏览器事件"的方式, 只要简单的模拟下点击动作, 那些一系列的动作, 我们都可以不关心, 那不是很高效, 也很简单么?

</p>]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2009/05/17/815.html"  title="Permanet Link to 关于事件模拟" >http://www.laruence.com/2009/05/17/815.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>
	如果用greaseMonkey编写脚本来做一些Web自动化的事情, 最关键的点会是哪里呢?<br/>
	&#8220;模拟浏览器事件&#8221;,</p>
<p>	试想, 如果一定按钮, 点击以后, 触发了一系列的动作,<br/>
	如果使用脚本去实现自动化, 那么我们必须去寻找这一系列的动作, 然后找到切入点函数, 模拟参数, 调用. 这会是个很复杂的过程&#8230;</p>
<p>	但是, 如果我们采用&#8221;模拟浏览器事件&#8221;的方式, 只要简单的模拟下点击动作, 那些一系列的动作, 我们都可以不关心, 那不是很高效, 也很简单么?</p>
<p>
	对于IE来讲, 模拟动作有俩套方式:<br/>
	1. 是IHTMLELEMENT2 提供的事件方法, 比如 click(), blur().<br/>
	2. 是IHTMLELEMENT3 提供的fireEvent, 事件现场可以使用IHTMLDocument4::createEventObject来模拟</p>
<p>	对于FF来讲, 则可以使用Gecko DOM中的createEvent, dispatchEvent.</p>
<p>	对于IE来讲, 使用事件方法(以下简称A)和fireEvent(以下简称B)的区别主要有:<br/>
		1. 使用B的话, 只是发出事件, 不会模拟发送事件之前的浏览器动作, 比如对于focus():<br/>
		   使用A会讲焦点送到事件调用对象上, 而使用B并不会真正的讲焦点送到事件发送对象上.<br/>
		(其他的待补充).</p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/05/17/815.html" >2009/09/13</a>, guest writes: by Fatal error: Maximum execution time of 60 seconds exceeded in d:\clientweb\laruence\wwwroot\wp-includes\feed-rss2.php on line 37

from google reader.</li><li><a href="http://www.laruence.com/2009/05/17/815.html" >2009/09/14</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @guest thanks, roger~</li><li><a href="http://www.laruence.com/2009/05/17/815.html" >2011/08/29</a>, <a href="http://blog.iterse.com"  rel="external nofollow"  class="url" >iterse's blog</a> writes: 学习了，不怎么理解，顶一下！</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2012/01/07/2453.html"  title="2012年1月全球www网站技术报告" >2012年1月全球www网站技术报告</a></li><li><a href="http://www.laruence.com/2010/05/13/1462.html"  title="Javascript原型链和原型的一个误区" >Javascript原型链和原型的一个误区</a></li><li><a href="http://www.laruence.com/2010/01/21/1254.html"  title="IE下var的重要性的又一佐证" >IE下var的重要性的又一佐证</a></li><li><a href="http://www.laruence.com/2009/09/27/1123.html"  title="关于Javascript的俩个有趣的探讨" >关于Javascript的俩个有趣的探讨</a></li><li><a href="http://www.laruence.com/2009/09/23/1089.html"  title="深入理解JavaScript定时机制" >深入理解JavaScript定时机制</a></li><li><a href="http://www.laruence.com/2009/09/08/1076.html"  title="深入理解Javascript之this关键字" >深入理解Javascript之this关键字</a></li><li><a href="http://www.laruence.com/2009/08/09/1036.html"  title="正确使用JS中的正则" >正确使用JS中的正则</a></li><li><a href="http://www.laruence.com/2009/05/28/863.html"  title="Javascript作用域原理" >Javascript作用域原理</a></li><li><a href="http://www.laruence.com/2009/05/18/809.html"  title="使用JS做文档处理" >使用JS做文档处理</a></li><li><a href="http://www.laruence.com/2008/09/01/492.html"  title="Js处理Json的&#8221;invalid label&#8221;错" >Js处理Json的&#8221;invalid label&#8221;错</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/05/17/815.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>东方时尚约车脚本(greaseMoney)</title>
		<link>http://www.laruence.com/2009/05/10/786.html</link>
		<comments>http://www.laruence.com/2009/05/10/786.html#comments</comments>
		<pubDate>Sun, 10 May 2009 02:34:50 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[随笔]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=786</guid>
		<description><![CDATA[<b>因为东方时尚改版, 这个脚本不能用了, sorry</b>

约车辛苦啊， 不停的刷新。。。
刚看到有车, 一点又没了,,, 

愤怒之下, 写了个自动刷新脚本, 自动帮你约车.
可以定义多个需要预订的时段~~

脚本可以无人值守...]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2009/05/10/786.html"  title="Permanet Link to 东方时尚约车脚本(greaseMoney)" >http://www.laruence.com/2009/05/10/786.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p><b>因为东方时尚改版, 请参看<a href="http://www.laruence.com/2010/03/31/1377.html" >约车脚本2.0</a></b></p>
<p>约车辛苦啊， 不停的刷新。。。<br/>
刚看到有车, 一点又没了,,, </p>
<p>愤怒之下, 写了个自动刷新脚本, 自动帮你约车.<br/>
可以定义多个需要预订的时段~~</p>
<p>脚本可以无人值守&#8230;</p>
<p>享受吧~~ 呵呵</p>
<p><b>安装地址: <a href="/wp-content/uploads/dffs_booking_script.user.js" >dffs booking script</a></b></p>
<p>代码如下:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
// ==UserScript==
// @name           dffs_booking_script
// @namespace      dffs.booking
// @include        http://yueche.dfss.cn/web/cmp/yc.aspx?StudentID=0942978
// @version		   1.0.3
// @author		   laruence&lt;laruence at yahoo.com.cn&gt;
// @copyright	   Copyright (c) 2009  laruence , All rights Reserved
// ==/UserScript==
//

/**
 * monday = 1, sunday = 0
 * 7:00-9:00 = 1, 19:00-21:00 = 5 ,
 * [ [5, 5], [6, 1] ] 的意思是, 我要预约星期5晚上19点到21点,
 * 和星期六7点到9点，
 * 修改这个为你想要的时段吧
 */
var expect_period = [
[6, 1], [6, 2],
[0, 1], [0, 2], [0, 3], [0, 4],[0, 5]
];	 

//每次请求之间的延迟， 不用太短， 机器会郁闷的。
var delay = 10; //5秒
//

var START = true;
var delegate = function(expect_period) {
	var day_map 	= ['日', '一', '二', '三', '四', '五', '六'];
	var period_map	= ['7-9', '9-13', '13-17', '17-19', '19-21'];
	var url			= window.location.href;
	var book_day 	= [];
	var book_period = [];
	var self		= this;
	var time		= new Date();
	var today		= time.getDay();

	for ( var key in expect_period ) {
		book_day[key]  	  = day_map[expect_period[key][0]];
		book_period[key]  = period_map[expect_period[key][1] -1];
	}

	if( typeof delegate.__initilized__ == 'undefined' ) {
		delegate.prototype.init  = function(flag) {
			var x = document.createElement(&quot;div&quot;);
			var btn = null;
			x.id = &quot;m-btn-o&quot;;
			x.innerHTML = &quot;&lt;style&gt;#m-btn-o{border:solid 2px red;background-color:#ccc;left:740px;top:110px;position:absolute;}&lt;/style&gt;&quot;;
			document.body.appendChild(x);
			if ( flag ) {
				x.innerHTML += &quot;&lt;button id='m-btn'&gt;开始约车&lt;/button&gt;&quot;;
				btn = document.getElementById(&quot;m-btn&quot;);
				btn.addEventListener(&quot;click&quot;, function() {
						window.location.replace(url + '&amp;automatic_booking=1');
				}, false);
			} else {
				x.innerHTML += &quot;&lt;button id='m-btn'&gt;停止&lt;/button&gt;&quot;;
				btn = document.getElementById(&quot;m-btn&quot;);
				btn.addEventListener('click', function() {
							window.location.replace(url.replace('&amp;automatic_booking=1', ''));
						}, false);
				setTimeout( function() {
					self.start();
				},  2000);
			}
		}

		delegate.prototype.start = function() {
			/*
			GM_xmlhttpRequest( {
				method : &quot;GET&quot;,
				url : url,
				onload : function(o) {
					var text = o.responseText;
					self.isAvailable(text);
				},
				onerror : function(e) {
					GM_log(&quot;Error occurred&quot;);
				}
			});
			*/
			var text = document.getElementById('gridgrid_div').innerHTML;
			self.isAvailable(text);
		}
		delegate.prototype.isAvailable = function(text){
			for ( var i=0, l=expect_period.length; i&lt;l; i++ ) {
					var expect_day	= expect_period[i][0];
					expect_day		= ((expect_day - today) + 7) % 7;
					var id = &quot;grid_grid_ci_0_&quot; + expect_period[i][1] + &quot;_&quot; + expect_day	+ &quot;_imgButton&quot;;
					var input = null;
					if( (input = document.getElementById(id) )
							&amp;&amp; input.src.indexOf('02.gif') != -1 ) {
						/**
						 * igtbl functions
						 * defined in ig_WebGrid.js line 2477
						 */
						var grid = unsafeWindow.igtbl_getGridById('gridgrid');
						var cellId = &quot;gridgridrc_&quot; + expect_day + &quot;_&quot; + expect_period[i][1];
						var cell   = unsafeWindow.igtbl_getCellById(cellId);
 						grid.setActiveCell(cell); // important
						var evt = document.createEvent(&quot;MouseEvents&quot;);
						evt.initEvent(&quot;click&quot;, true, true);
						input.dispatchEvent(evt);
						return true;
					}
				}
				url	+= (url.indexOf(&quot;automatic_booking&quot;) != -1) ?  '' : '&amp;automatic_booking=1';
				window.location.replace(url);
		}
		delegate.__initilized__ = true;
	}
}

window.addEventListener('load',  function() {
	var agent = new delegate(expect_period);
	if ( window.location.href.indexOf('automatic_booking=1') != -1 ) {
		agent.init(!START);
	} else {
		agent.init(START);
	}
}, false);
</pre>
<p>使用方法， 使用firefox， 并且安装greaseMonkey插件。 对这个不明白， 可以问问google， 他知道.<script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/05/10/786.html" >2009/05/11</a>, <a href="http://blog.zol.com.cn/email4u/"  rel="external nofollow"  class="url" >晓易</a> writes: 这个不错。不过电话预约早7点就开始了，网络预约是9点后，好时间段基本已经约满。只能寄希望于有人取消预约。</li><li><a href="http://www.laruence.com/2009/05/10/786.html" >2009/05/12</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 现在学成的人太多了`</li><li><a href="http://www.laruence.com/2009/05/10/786.html" >2009/05/12</a>, toms writes: 雪大侠：我问个东西

就是一个sns站， 它的用户首页有好友列表，好友生日， 用户群组等东西， 其中有一部分很少变动（都在同一个页面）的部分我打算生成局部静态html页面，每隔一段时间更新或由用户动作触发更新，以用户首页来说如果有三个页面模块需要静态化， 那么就要生成3个静态文件，如果有40w用户，基本上就有40，0000*3个静态页面, 这么多文件在文件系统中如何处理， 如果采用hash路径， 那么一个目录下的子文件数（不知道子文件中的文件数对访问当前文件夹下的文件有没有速度影响）不超过多少才不会影响文件系统访问速度？

第二种方法就是用memcache缓存数据查询结果，然后直接在视图中使用mem缓存结果而也不用查询数据库，哪个快点啊？

谢谢！</li><li><a href="http://www.laruence.com/2009/05/10/786.html" >2009/05/12</a>, toms writes: 而且也不光用户首页部分，站点还有很多地方都会使用</li><li><a href="http://www.laruence.com/2009/05/10/786.html" >2009/05/12</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 我觉得用cache会比较好一些, 第一种方式也许我没太看懂, 直观上觉得,这么多文件, 是比较费力的.</li><li><a href="http://www.laruence.com/2009/05/10/786.html" >2009/05/12</a>, toms writes: 第一种方式就是，在用户首页有很多模块：最近访问，好友列表，我加入的群组，个人基本信息。。。

， 其中“我的好友”， “我加入的群组”是很少更新的那么在被访问了一次之后生成：myfriends.html, mygroup.html, 以后访问用户首页的时候对于“我的好友”和“我的群组”就直接读上面的生成的静态文件， 但由于每个用户的好友列表和群组是不一样的， 所以就要为不同的用户生成不同的html， 这样如果有10w用户数，那么缓存的静态文件就可能是10, 0000*3个，这么多文件怎么处理，我按用户id md5出3级目录存放它们有没有效率上的问题，就是会不会由于文件数太多反而访问缓存文件的速度还不如访问数据库
----------------------------------
谢谢</li><li><a href="http://www.laruence.com/2009/05/10/786.html" >2009/05/12</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 首先, 你这样的静态化的思路出发点就不对, 一般来说, 静态化应该是说对于所有的用户(起码不会每个用户都一份)都一样的部分静态化.

我个人更支持你使用缓存. 由用户更新来促使缓存失效. 这个速度会快于你管理如此大的文件数目的速度.</li><li><a href="http://www.laruence.com/2009/05/10/786.html" >2009/05/12</a>, toms writes: 嗯好的，谢谢啊。。。。</li><li><a href="http://www.laruence.com/2009/05/10/786.html" >2009/05/13</a>, Anonymous writes: 能写个自动打电话的吗</li><li><a href="http://www.laruence.com/2009/05/10/786.html" >2009/07/16</a>, <a href="http://www.54xsy.cn"  rel="external nofollow"  class="url" >工作计划</a> writes: 主题漂亮</li><li><a href="http://www.laruence.com/2009/05/10/786.html" >2009/07/16</a>, <a href="http://www.9iwj.cn"  rel="external nofollow"  class="url" >儿童游戏</a> writes: 路过，顺便顶下</li><li><a href="http://www.laruence.com/2009/05/10/786.html" >2009/07/28</a>, Fisher writes: 老大？为啥我测试了2.0-3.0-3.5三个版本的FF，始终没有见到过其自动刷新的效果呢？多谢，敬请指教：）

yuningilike@163.com</li><li><a href="http://www.laruence.com/2009/05/10/786.html" >2009/11/26</a>, tangtang writes: 怎么我用了也没效果呢？还请赐教呀！！</li><li><a href="http://www.laruence.com/2009/05/10/786.html" >2009/11/27</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @tangtang dfsf改版了,,我也没有账户可以测试修改... 所以不能用了.</li><li><a href="http://www.laruence.com/2009/05/10/786.html" >2009/11/28</a>, 雷恩 writes: 看到大哥的贴子相当兴奋，心想总算看到了约车的希望了。可是俺是新手，不会玩这么高的技术，能不能送佛送到西，再详尽一点？我已经装了插件，也安装了脚本（点击了您提供的地址），接着应该是要改代码了吧？就这一步不会...</li><li><a href="http://www.laruence.com/2009/05/10/786.html" >2010/03/31</a>, <a href="http://www.laruence.com/2010/03/31/1377.html"  rel="external nofollow"  class="url" >东方时尚约车脚本(greaseMoney)V2.0 | 风雪之隅</a> writes: [...] 原来的脚本不能用了. 马上有人要报名了, [...]</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Random Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/04/09/674.html"  title="关于Javascript的作用域链的几句话" >关于Javascript的作用域链的几句话</a></li><li><a href="http://www.laruence.com/2011/09/22/2152.html"  title="回答下在bugs.php上的一个问题" >回答下在bugs.php上的一个问题</a></li><li><a href="http://www.laruence.com/2011/11/04/2258.html"  title="三元式(ternary)性能优化" >三元式(ternary)性能优化</a></li><li><a href="http://www.laruence.com/2010/07/16/1648.html"  title="定制自己的PHP语法-在PHP中实现unless" >定制自己的PHP语法-在PHP中实现unless</a></li><li><a href="http://www.laruence.com/2010/05/18/1482.html"  title="深入理解PHP原理之对象(一)" >深入理解PHP原理之对象(一)</a></li><li><a href="http://www.laruence.com/2010/04/12/1396.html"  title="深入理解SET NAMES和mysql(i)_set_charset的区别" >深入理解SET NAMES和mysql(i)_set_charset的区别</a></li><li><a href="http://www.laruence.com/2008/04/01/116.html"  title="关于调用约定(cdecl、fastcall、stcall、thiscall) 的一点知识" >关于调用约定(cdecl、fastcall、stcall、thiscall) 的一点知识</a></li><li><a href="http://www.laruence.com/2008/04/04/17.html"  title="在PHP Module中获取$_GET/$_POST/$_COOKIE的方法研究" >在PHP Module中获取$_GET/$_POST/$_COOKIE的方法研究</a></li><li><a href="http://www.laruence.com/2008/08/24/427.html"  title="PHP5多层继承顺序的bug" >PHP5多层继承顺序的bug</a></li><li><a href="http://www.laruence.com/2009/10/15/1131.html"  title="提升PHP性能之改变Zend引擎分发方式" >提升PHP性能之改变Zend引擎分发方式</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/05/10/786.html/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>图片上传即时显示缩略图解决方法</title>
		<link>http://www.laruence.com/2009/05/06/758.html</link>
		<comments>http://www.laruence.com/2009/05/06/758.html#comments</comments>
		<pubDate>Wed, 06 May 2009 05:02:08 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[js缩略图]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=758</guid>
		<description><![CDATA[   做互联网, 就一定要多用新的互联网产品, 遇到好玩的, 要主动去思考如何实现, 这样才能一直保证你自己的良好的互联网应用的sense. 嘿嘿, 题外话一句.
   
   昨天玩开心网的图片上传, 不得不说, 开心网的细节做的很好. 
   
   之前在前公司的时候, 高管干扰UE, 干涉产品的设计细节, 出来的产品, 一个比一个难看, 一个比一个土鳖. 搞得开发都不想做, 以至于一段时间, 我们开发工程师会去修缮UE设计的细节.

   真不明白, 没有一点互联网应用美感和sense的"猪头"高管, 怎么会对自己的"审美"那么的自信.... 玩死自己没关系 , 玩死了公司, 你内疚不?  唉, 题外话二..  细节决定成败!

   恩, 回到正题, 看到了开心网的, 本地客户端检测图片格式, 和即时显示缩略图功能, 发现在chrome, firefox3, IE8下都不能显示缩略图, 可是我可爱的Eve一直坚持是可以的, 经过研究测试, 找到了在firefox3 , IE8下可以使用的方法.]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2009/05/06/758.html"  title="Permanet Link to 图片上传即时显示缩略图解决方法" >http://www.laruence.com/2009/05/06/758.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p><script type="text/javascript"  src="http://laruence-wordpress.stor.sinaapp.com/uploads/PicPreview.js" ></script><br/>
<script language="javascript"  type="text/javascript" >
	 var allowExt = ['jpg', 'gif', 'bmp', 'png', 'jpeg'];
	 var preivew = function(file, container){
		 try{
			var pic =  new Picture(file, container);
		 }catch(e){
			 alert(e);
		 }
	 }
</script></p>
<p>
   做互联网, 就一定要多用新的互联网产品, 遇到好玩的, 要主动去思考如何实现, 这样才能一直保证你自己的良好的互联网应用的sense. 嘿嘿, 题外话一句.</p>
<p>   昨天玩开心网的图片上传, 不得不说, 开心网的细节做的很好. </p>
<p>   之前在前公司的时候, 高管干扰UE, 干涉产品的设计细节, 出来的产品, 一个比一个难看, 一个比一个土鳖. 搞得开发都不想做, 以至于一段时间, 我们开发工程师会去修缮UE设计的细节.</p>
<p>   真不明白, 没有一点互联网应用美感和sense的&#8221;猪头&#8221;高管, 怎么会对自己的&#8221;审美&#8221;那么的自信&#8230;. 玩死自己没关系 , 玩死了公司, 你内疚不?  唉, 题外话二..  细节决定成败!</p>
<p>   恩, 回到正题, 看到了开心网的, 本地客户端检测图片格式, 和即时显示缩略图功能, 发现在chrome, firefox3, IE8下都不能显示缩略图, 可是我可爱的Eve一直坚持是可以的, 经过研究测试, 找到了在firefox3 , IE8下可以使用的方法.</p>
<p>   效果如下:
   </p>
<div class="previewDemo" >
<input id="file"  type="file"  onchange="preivew(this, document.getElementById('img'));" />
	<img id="img"  style="visibility:hidden"  height="100px"  width="100px" />
</div>
</p>
<p>     一个独立的例子,看<a href="/wp-content/uploads/previewDemo.html"  target="_blank" >这里</a></p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
   PS: chrome是webkit核心, 如果大家谁知道对于Webkit核心的浏览器, 如何获得file input的full path的方法, 一定告诉我.

   另外, IE8还和一个安全设置有关系&quot;文件上传的时候是否告诉服务器文件路径&quot;, 如果大家有更好的办法, 也一并告诉我.
</pre>
</p>
<p>
   Firefox3不支持通过value来获取文件全路径, FireFox3中引入了一个新的接口用来解决这个问题，那就是nsIDOMFile，它专门被用来从客户端的input type=&#8221;file&#8221;的控件中获取文件数据，这样就可以将本地的文件保存到服务器上。这是一个非常好的解决办法，以至于我们在FireFox3中开发这样的应用程序时比先前简单获取value值然后再通过服务器端代码上传文件要简单许多，</p>
<p>   具体可以参看这里: <a href="https://developer.mozilla.org/en/nsIDOMFile"  target="_blank" >nsiDOMFile</a>
</p>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/06</a>, <a href="http://willko.javaeye.com"  rel="external nofollow"  class="url" >Willko</a> writes: 真是及时雨啊。。。
不知道有没有兼容性更强的呢？</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/06</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: chrome是webkit核心的,,目前还没有找到方法怎么获取文件全路径.
另外,IE8还和安全级别设置有关系..</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/06</a>, <a href="http://www.coudou.com"  rel="external nofollow"  class="url" >dyh1919</a> writes: 记得支付宝里有一个上传身份证的看缩略图，估计兼容性是做到的了，可以试着扣出来</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/06</a>, <a href="http://onemouse.cn"  rel="external nofollow"  class="url" >Anders</a> writes: some code is invalid.
 widht  = container.widht;


恩，不错。

支付宝的,我猜可能是控件。</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/06</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 哦,手误,
恩, 用activeX来专门处理IE series, 那是肯定可以的.</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/06</a>, <a href="http://www.sysbus.com/?p=183"  rel="external nofollow"  class="url" >图片上传即时显示缩略图解决方法(支持firefox3和ie8) 网站系统架构网摘 - 系统 架构 服务器 优化 网站</a> writes: [...] from：http://www.laruence.com/2009/05/06/758.html  Facebook 如何管理150亿张照片 [...]</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/06</a>, <a href="http://www.zendstudio.net/"  rel="external nofollow"  class="url" >gently</a> writes: 老外们讨论的结果似乎是通过flash桥接来解决兼容问题。一如Gmail的实时提示附件太大。</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/07</a>, <a href="http://...."  rel="external nofollow"  class="url" >...</a> writes: http://www.cnblogs.com/jaxu/archive/2009/04/21/1439016.html</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/07</a>, <a href="http://willko.javaeye.com"  rel="external nofollow"  class="url" >WIllko</a> writes: 我把兼容ie6/7系列的代码写在了这http://willko.javaeye.com/admin/blogs/381684

希望继续探讨</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/07</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 也就是IE8麻烦...</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/08</a>, <a href="http://www.sysbus.com"  rel="external nofollow"  class="url" >就天鹰</a> writes: 不错，一直找不到支持ff的方法
转载一下，不反对吧，谢谢</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/10</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 不反对，点都不反对。。。呵呵</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/12</a>, weimade writes: 以前我们公司弄了一个好玩的办法..

当用户选择图片之后,直接用JS就把图片给传到服务器上了.
然后就不管他什么浏览器了.

所谓的预览,就成功了.</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/12</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 恩, 这个方法比较狠..</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/14</a>, flykobe writes: 原来用的是data url！ 
以前一直看图片预览，都没弄明白！多谢多谢！</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/18</a>, <a href="http://www.skiyo.cn"  rel="external nofollow"  class="url" >Jessica</a> writes: 汗..说了这么多不就是一句
document.getElementById('file').value</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/18</a>, <a href="http://www.skiyo.cn"  rel="external nofollow"  class="url" >Jessica</a> writes: 像我这种用户点完预览就就提交了..不知道你JS给服务器提交到一半怎么处理..我想的只有加重服务器负担.</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/18</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 你再仔细看看? 呵呵</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/21</a>, Anonymous writes: IE7下图片只显示路径，不显示图片</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/05/22</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 恩,IE下有个安全选项问题...</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/08/13</a>, zhj writes: 额的神啊~~该怎么感谢你啊~~</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/08/13</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 你可以选择请我吃饭, 或者请我喝酒, 嘿嘿</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/08/14</a>, zhj writes: 那我拜你为师吧~~以后有机会一定请你喝酒~~二锅头</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2009/12/02</a>, <a href="http://www.ayang23.com"  rel="external nofollow"  class="url" >Anonymous</a> writes: 佩服，现学现用了，希望作者不要介意。</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2010/07/26</a>, wclssdn writes: 我是IE8 ... 难道不支持ie8? 

我也实现过类似的.. 不过也是上传后.. 返回地址.. 显示缩略图的... 

但是不会存在垃圾文件..  我存了个标志在session中.. 呵呵..  

希望早日找到更更好的办法..</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2010/12/10</a>, Channel Magnets writes: 悬吊<a href="http://www.sensmag.com/products_27_Channel Magnets.html"  rel="nofollow" >Channel Magnets</a>地球仪 眼界超越局限尽在掌握,悬吊磁铁地球仪,仅仅是材质的变化,<a href="http://www.sensmag.com/products_33_Sensors Magnets.html"  rel="nofollow" >Sensors Magnets</a>就把地球仪的呆板一扫而空;深灰的金属色,富有时尚触觉。 <a href="http://www.sensmag.com/products_28_Other Magnetic Assembly.html"  rel="nofollow" >Other Magnetic Assembly</a>它可以通过磁铁吸附,挂在墙上成为立体的球型壁画,悬吊在天花板上作为装饰,或者只是简单摆放在桌上。<a href="http://www.shendayumei.cn"  rel="nofollow" >美白</a>重要的是,无论何时何地;桃皮绒销量不减 ,寒意日渐袭人,这一季适用于制作成夹克衫、<a href="http://www.intrade55.com"  rel="nofollow" >Nike air max</a>、休闲装的面料在市场上销量一直是相当不错,商家忙碌着向工厂下订单、<a href="http://www.intrade55.com"  rel="nofollow" >puma shoes</a>做货样、催出货。<a href="http://www.intrade55.com"  rel="nofollow" >cheap handbags</a>无论是内销订单,还是外贸订货,<a href="http://www.shendayumei.cn"  rel="nofollow" >护肤</a>桃皮绒在近期的盛泽市场上有其一定的地位,尤其深受东欧地区的客商喜欢。</li><li><a href="http://www.laruence.com/2009/05/06/758.html" >2011/03/24</a>, 雷神 writes: 经过验证此文章中的代码在chrome 10.0.648.6版本中失效。chrome这点比其他浏览器安全点</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Random Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/02/25/1324.html"  title="NCR与HTML Entities" >NCR与HTML Entities</a></li><li><a href="http://www.laruence.com/2008/11/11/606.html"  title="图解aclocal、autoconf、automake、autoheader、configure" >图解aclocal、autoconf、automake、autoheader、configure</a></li><li><a href="http://www.laruence.com/2010/04/12/1396.html"  title="深入理解SET NAMES和mysql(i)_set_charset的区别" >深入理解SET NAMES和mysql(i)_set_charset的区别</a></li><li><a href="http://www.laruence.com/2009/07/27/1020.html"  title="深入理解PHP原理之错误抑制与内嵌HTML" >深入理解PHP原理之错误抑制与内嵌HTML</a></li><li><a href="http://www.laruence.com/2010/05/24/1526.html"  title="BTwitter(Twitter In Bash)" >BTwitter(Twitter In Bash)</a></li><li><a href="http://www.laruence.com/2011/03/22/1929.html"  title="PHP Reflection Extension的一个bug" >PHP Reflection Extension的一个bug</a></li><li><a href="http://www.laruence.com/2009/12/05/1172.html"  title="PHP5.2.x + APC的一个bug的定位" >PHP5.2.x + APC的一个bug的定位</a></li><li><a href="http://www.laruence.com/2009/05/05/740.html"  title="使用CSS实现圈人效果(CSS Sprites)" >使用CSS实现圈人效果(CSS Sprites)</a></li><li><a href="http://www.laruence.com/2008/07/18/124.html"  title="Dom事件的srcTarget,strElement探幽" >Dom事件的srcTarget,strElement探幽</a></li><li><a href="http://www.laruence.com/2008/04/21/101.html"  title="关于PHP你可能不知道的－PHP的事件驱动化设计" >关于PHP你可能不知道的－PHP的事件驱动化设计</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/05/06/758.html/feed</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>使用CSS实现圈人效果(CSS Sprites)</title>
		<link>http://www.laruence.com/2009/05/05/740.html</link>
		<comments>http://www.laruence.com/2009/05/05/740.html#comments</comments>
		<pubDate>Tue, 05 May 2009 05:29:32 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[CSS Sprites]]></category>
		<category><![CDATA[图片合并]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=740</guid>
		<description><![CDATA[	我最早了解到"图片合并"技术, 应该是在大学游戏时代, 会发现很多游戏图标, 都会合并在一个位图中, 然后使用类似"遮罩"的技术来分别显示各种图标.

	第一次使用CSS Sprites技术的时候, 其实并不知道它的这个名字, 也并没觉得多稀奇,就是个遮罩么.
	
	今天玩开心网的圈人游戏时候, 发现它的实现是使用了Js, 突发奇想, 或许可以使用CSS Sprites来实现, 抛弃内嵌的JS.]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2009/05/05/740.html"  title="Permanet Link to 使用CSS实现圈人效果(CSS Sprites)" >http://www.laruence.com/2009/05/05/740.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p></p>
<style>
img.image{ display: none; }
dl#officeMap{ margin: 0; padding: 0; background: transparent url(/wp-content/uploads/office.jpg) top left no-repeat; height: 262px; width: 350px; position: relative;}
dt{ margin: 0; padding: 0; position: absolute; font-size: 85%; display: none; }
dd{ margin: 0; padding: 0; position: absolute;  font-size: 85%; }
dd#monitorDef{ top: 65px; left: 114px; }
dd#monitorDef a{ position: absolute; width: 73px; height: 69px; text-decoration: none; }
dd#monitorDef a span{ display: none; }
dd#monitorDef a:hover{ position: absolute; background: transparent url(/wp-content/uploads/office.jpg) -109px -317px no-repeat; top: -10px; left: -5px; }
dd#monitorDef a:hover span{ display: block; text-indent: 0; vertical-align: top; color: #000; background-color: #F4F4F4; font-weight: bold; position: absolute; border: 1px solid #BCBCBC; bottom: 100%; margin: 0; padding: 5px; width: 100%;}
dd#phoneDef{ top: 111px; left: 211px; }
dd#phoneDef a{ position: absolute; width: 56px; height: 46px; text-decoration: none; }
dd#phoneDef a span{ display: none; }
dd#phoneDef a:hover{ background: transparent url(/wp-content/uploads/office.jpg) -211px -373px no-repeat; }
dd#phoneDef a:hover span{ display: block; text-indent: 0; vertical-align: top; color: #000; background-color: #F4F4F4; font-weight: bold; position: absolute; border: 1px solid #BCBCBC; bottom: 100%; margin: 0; padding: 5px; width: 100%;
}
dd#caseDef{ top: 165px; left: 168px; }
dd#caseDef a{ position: absolute; width: 81px; height: 87px; text-decoration: none;	}
dd#caseDef a span{ display: none; }
dd#caseDef a:hover{ background: transparent url(/wp-content/uploads/office.jpg) -168px -427px no-repeat; }
dd#caseDef a:hover span{ display: block; text-indent: 0; vertical-align: top; color: #000; background-color: #F4F4F4; font-weight: bold; position: absolute; border: 1px solid #BCBCBC; top: 100%; margin: 0; padding: 5px; width: 100%;}
dd#notebookDef{ top: 101px; left: 72px; }
dd#notebookDef a{ position: absolute; width: 96px; height: 54px; text-decoration: none; }
dd#notebookDef a span{ display: none; }
dd#notebookDef a:hover{ background: transparent url(/wp-content/uploads/office.jpg) -72px -625px no-repeat; }
dd#notebookDef a:hover span{ display: block; text-indent: 0; vertical-align: top; color: #000; background-color: #F4F4F4; font-weight: bold; position: absolute; border: 1px solid #BCBCBC; top: 100%; margin: 0; padding: 5px; width: 150%;}
dd#floppyDef{top:126px; left: 45px; }
dd#floppyDef a{ position: absolute; width: 64px; height: 39px; text-decoration: none; }
dd#floppyDef a span{ display: none; }
dd#floppyDef a:hover{ background: transparent url(/wp-content/uploads/office.jpg) -45px -388px no-repeat; }
dd#floppyDef a:hover span{ display: block; text-indent: 0; vertical-align: top; color: #000; background-color: #F4F4F4; font-weight: bold; position: absolute; border: 1px solid #BCBCBC; top: 100%; left: 1px; margin: 0; padding: 5px; width: 150%;}
</style>
<p></p>
<p>
	我最早了解到&#8221;图片合并&#8221;技术, 应该是在大学游戏时代, 会发现很多游戏图标, 都会合并在一个位图中, 然后使用类似&#8221;遮罩&#8221;的技术来分别显示各种图标.</p>
<p>	第一次使用CSS Sprites技术的时候, 其实并不知道它的这个名字, 也并没觉得多稀奇,就是个遮罩么.</p>
<p>	今天玩开心网的圈人游戏时候, 发现它的实现是使用了Js, 突发奇想, 或许可以使用CSS Sprites来实现, 抛弃内嵌的JS.</p>
<p>	效果如下:<br/>
</p>
<h5> 图标标记 </h5>
<dl id="officeMap" >
<dt id="monitor" >1. 显示器</dt>
<dd id="monitorDef" ><a href="javascript:void('laruence');" ><span>17&#8242;的显示器哦~</span></a></dd>
<dt id="phone" >2. 电话</dt>
<dd id="phoneDef" ><a href="javascript:void('laruence');" ><span>听筒坏了</span></a></dd>
<dt id="case" >3. 机箱</dt>
<dd id="caseDef" ><a href="javascript:void('laruence');" ><span>白色的机箱</span></a></dd>
<dt id="notebook" >4. IBM ThinkPad</dt>
<dd id="notebookDef" ><a href="javascript:alert('Product by Lenovo! -_!!');" ><span>ThinkPad</span></a></dd>
<dt id="floppy" >5. 外置光驱</dt>
<dd id="floppyDef" ><a href="javascript:void('laruence');" ><span>我不知道这玩意是哪里买的</span></a></dd>
</dl>
<p>
</p>
<p>
    有兴趣的同学, 可以直接看HTML源码, 一个独立页面的例子在<a href="/wp-content/uploads/csssprites.html"  target="_blank" >这里</a></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/05/05/740.html" >2009/05/05</a>, <a href="http://www.zendstudio.net/"  rel="external nofollow"  class="url" >gently</a> writes: 仔细的看完了。纯CSS实现起来果然很有魅力。
如果很后台程序结合起来，这种方式可能会造成很多的代码冗余，创建元素都变成了服务端处理，本来大概只需送出height,width,top,left这些。</li><li><a href="http://www.laruence.com/2009/05/05/740.html" >2009/05/05</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 恩,这倒是, 用js也不需要多余生成图片.
呵呵,只是探讨一种新的方式..</li><li><a href="http://www.laruence.com/2009/05/05/740.html" >2009/06/11</a>, <a href="http://reeze-note.appspot.com"  rel="external nofollow"  class="url" >reeze</a> writes: 恩。不过sprites的方式扩展起来比较麻烦啊。得服务器生成图片。。</li><li><a href="http://www.laruence.com/2009/05/05/740.html" >2012/01/26</a>, 荆棘 writes: 我倒想尝试一下~</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Random Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/09/27/1754.html"  title="PHP stream未能及时清理现场导致Core的bug" >PHP stream未能及时清理现场导致Core的bug</a></li><li><a href="http://www.laruence.com/2011/03/29/1949.html"  title="深入理解PHP原理之Session Gc的一个小概率Notice" >深入理解PHP原理之Session Gc的一个小概率Notice</a></li><li><a href="http://www.laruence.com/2009/11/27/1164.html"  title="memory_limit的一个bug" >memory_limit的一个bug</a></li><li><a href="http://www.laruence.com/2010/12/14/1816.html"  title="Compilation failed: support for \P, \p, and \X has not been compiled" >Compilation failed: support for \P, \p, and \X has not been compiled</a></li><li><a href="http://www.laruence.com/2010/11/02/1789.html"  title="[转载]技术文化和惨淡命运 —— 怀念中国雅虎" >[转载]技术文化和惨淡命运 —— 怀念中国雅虎</a></li><li><a href="http://www.laruence.com/2010/05/04/1450.html"  title="深入理解PHP之require/include顺序" >深入理解PHP之require/include顺序</a></li><li><a href="http://www.laruence.com/2011/06/19/2047.html"  title="PLua &#8211; Lua for PHP" >PLua &#8211; Lua for PHP</a></li><li><a href="http://www.laruence.com/2011/07/14/2115.html"  title="Zend引擎的优化" >Zend引擎的优化</a></li><li><a href="http://www.laruence.com/2008/04/16/98.html"  title="使用fscok实现异步调用PHP " >使用fscok实现异步调用PHP </a></li><li><a href="http://www.laruence.com/2009/08/18/1042.html"  title="保证PHP扩展的依赖关系" >保证PHP扩展的依赖关系</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/05/05/740.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>关于Javascript的作用域链的几句话</title>
		<link>http://www.laruence.com/2009/04/09/674.html</link>
		<comments>http://www.laruence.com/2009/04/09/674.html#comments</comments>
		<pubDate>Thu, 09 Apr 2009 07:40:58 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=674</guid>
		<description><![CDATA[作者: Laruence( ) 本文地址: http://www.laruence.com/2009/04/09/674.html 转载请注明出处 1.  js中的作用域是通过作用域链来实现的,  这个链, 是由一个一个的活动对象组成的, 最顶级的活动对象是window 2. 在js中, 在每一个执行点, this关键字都指当前函数(方法)的所有者. 3. 每个属性,其实都会定义成当前活动对象的属性, 在顶级文件中的每个函数定义,变量定义, 都定义成window对象的属性. 4. 对于函数, 如果通过函数表达式定义的函数, 则在函数表达式执行前, 该函数不可用. 而如果是通过函数定义式定义的函数, js会把它的定义提前, 也就是说在函数定义式之前, 该函数都可用. 5. 因为活动对象链的特性, 所以js支持闭包. 另外关于js中的原型链有一句要说的. 1. 只有函数对象有可以访问的prototype属性, 一般对象不是没有prototype属性, 只是没有可以访问的prototype属性.(严格来讲, 一般对象只有只能JS引擎内部访问的&#8221;[[prototype]]&#8221;属性) Comments2009/04/16, 风吹倒的男子 writes: function xx(){} //函数表达式? xx = function(){}//函数定义式? 你那句话好拗口2009/04/17, 雪候鸟 writes: var func = function(){} //函数表达式 function [...]]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2009/04/09/674.html"  title="Permanet Link to 关于Javascript的作用域链的几句话" >http://www.laruence.com/2009/04/09/674.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>1.  js中的作用域是通过作用域链来实现的,  这个链, 是由一个一个的活动对象组成的, 最顶级的活动对象是window</p>
<p>2.  在js中, 在每一个执行点, this关键字都指当前函数(方法)的所有者.</p>
<p>3.  每个属性,其实都会定义成当前活动对象的属性, 在顶级文件中的每个函数定义,变量定义, 都定义成window对象的属性.</p>
<p>4.  对于函数, 如果通过函数表达式定义的函数, 则在函数表达式执行前, 该函数不可用. 而如果是通过函数定义式定义的函数, js会把它的定义提前, 也就是说在函数定义式之前, 该函数都可用.</p>
<p>5. 因为活动对象链的特性, 所以js支持闭包.</p>
<p>另外关于js中的原型链有一句要说的.<br/>
 1. 只有函数对象有可以访问的prototype属性, 一般对象不是没有prototype属性, 只是没有可以访问的prototype属性.(严格来讲, 一般对象只有只能JS引擎内部访问的&#8221;[[prototype]]&#8221;属性)</p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/04/09/674.html" >2009/04/16</a>, <a href="http://www.riahtml.com"  rel="external nofollow"  class="url" >风吹倒的男子</a> writes: function xx(){} //函数表达式?

xx = function(){}//函数定义式?

你那句话好拗口</li><li><a href="http://www.laruence.com/2009/04/09/674.html" >2009/04/17</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: var func = function(){} //函数表达式
function func(){} //函数定义式</li><li><a href="http://www.laruence.com/2009/04/09/674.html" >2009/04/21</a>, eason writes: good</li><li><a href="http://www.laruence.com/2009/04/09/674.html" >2009/05/10</a>, LungZeno writes: 之前 ECMAScript 3 的 specification 在這方面的用字真的使人在溝通上有點混亂，現在最新出的 ECMAScript 3.1 的 specification 實在好得多。以下用新用字說。

Javascript 是沒有宣告和定義之分的，宣告的同時就會定義，未宣告即是未定義，已宣告即是已定義，最起碼在語言中是檢查不出分別的。不過 var statement 的 declaration binding instantiation 和 assignment 卻是分開的。
例如：
var global = window;

alert("declarativeVariable1" in global);  // display "true"
alert(declarativeVariable1);  // display "undefined"
var declarativeVariable1 = "some value";  // variable declaration statement
alert(declarativeVariable1);  // display "some value"

alert(declarativeFunction2);  // display declarativeFunction2.toString()
function declarativeFunction2(){}  // function declaration statement

alert("functionExpression" in global);  // display "false" for Javascript, "true" for Jscript which is wrong implementation of ECMAScript
try{
  alert(functionExpression);
}catch(error){
  alert("error");
}  // display "error" for Javascript, functionExpression.toString() for Jscript which treat function expression as function declaration statment
alert("declarativeVariable3" in global); // display "true"
alert(declarativeVariable3);  // display "undefined"
var declarativeVariable3 = function functionExpression(){};
alert(declarativeVariable3);  // display functionExpression.toString()
alert("functionExpression" in global);  // display "false" for Javascript, "true" for Jscript


其實 Javascript 的 this 關鍵字有點複雜，既非靜態（詞法），亦非動態。先不理那些內部屬性、內部方法、call方法、apply方法。簡化了綜合地說，函式內的 this 的值是取決於函式呼叫時用以取出該函式的 Reference 的 base 值的，如果是一般的物件，則 this 就是指向該物件，如果是 declarative envirnoment record （即是一般的 scope），則 this 就是指向全域物件。

例如這樣：
var someString = "global variable";
function enclosing(){
  this.someString = "property 1";
  var someString = "local variable 1";
  function test(){alert(this.someString);}
  test();
  return test;
}
var someObject = {encolsing:encolsing};
var testGlobal = someObject.enclosing();  // display "global variable"
alert(someObject.someString);  // display "property 1"
testGlobal();  // display "global variable"
secondObject = {someString:"property 2",testProperty:testGlobal};
secondObject.testProperty();  // display "property 2"
with(secondObject)
  var innerWith = function(){testProperty();};
innerWith();  // display "property 2";

ECMAScript 3.1 （現在叫 ECMAScript 5th edition）的最新 specification 寫得很清晰，例如最新的 specification 把 scope 和一般物件清楚分開處理，並把 LexicalEnvironment 和 VariableEnvironment 分離，特別它把各操作和計算「函式化」和「物件導向化」。</li></ul><hr/><h2>Related posts:</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2008/07/28/210.html"  rel="bookmark"  title="Permanent Link: 关于JavaScript的执行域,标识符解析,闭包的研究" >关于JavaScript的执行域,标识符解析,闭包的研究</a></li><li><a href="http://www.laruence.com/2007/11/15/10.html"  rel="bookmark"  title="Permanent Link: 一个误区（关于javascript的字符串拼接)" >一个误区（关于javascript的字符串拼接)</a></li><li><a href="http://www.laruence.com/2009/09/27/1123.html"  rel="bookmark"  title="Permanent Link: 关于Javascript的俩个有趣的探讨" >关于Javascript的俩个有趣的探讨</a></li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Random Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/07/28/1030.html"  title="Linux上配置Nginx+PHP5(FastCGI)" >Linux上配置Nginx+PHP5(FastCGI)</a></li><li><a href="http://www.laruence.com/2009/05/17/815.html"  title="关于事件模拟" >关于事件模拟</a></li><li><a href="http://www.laruence.com/2011/12/06/2381.html"  title="更简单的重现PHP Core的调用栈" >更简单的重现PHP Core的调用栈</a></li><li><a href="http://www.laruence.com/2007/11/15/10.html"  title="一个误区（关于javascript的字符串拼接)" >一个误区（关于javascript的字符串拼接)</a></li><li><a href="http://www.laruence.com/2012/01/24/2494.html"  title="大家新年好~" >大家新年好~</a></li><li><a href="http://www.laruence.com/2009/11/16/1147.html"  title="分割GBK中文遭遇乱码的解决" >分割GBK中文遭遇乱码的解决</a></li><li><a href="http://www.laruence.com/2010/08/18/1718.html"  title="将PHP Manual融入(g)Vim" >将PHP Manual融入(g)Vim</a></li><li><a href="http://www.laruence.com/2008/10/28/567.html"  title="一个巧妙的分页方法" >一个巧妙的分页方法</a></li><li><a href="http://www.laruence.com/2009/07/27/1020.html"  title="深入理解PHP原理之错误抑制与内嵌HTML" >深入理解PHP原理之错误抑制与内嵌HTML</a></li><li><a href="http://www.laruence.com/2008/09/24/550.html"  title="百度招聘－系统平台研发(实习)工程师" >百度招聘－系统平台研发(实习)工程师</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/04/09/674.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Js处理Json的&#8221;invalid label&#8221;错</title>
		<link>http://www.laruence.com/2008/09/01/492.html</link>
		<comments>http://www.laruence.com/2008/09/01/492.html#comments</comments>
		<pubDate>Mon, 01 Sep 2008 09:19:38 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[invalid label]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=492</guid>
		<description><![CDATA[  <p>当你使用ajax的时候,json是一个很方便的数据传输手段.
但是对于很多人来说,经常会遇到的一个很令人头疼的问题就是"invalid label"错. 明明json串看起来是对的,怎么还会出错呢?<p>]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2008/09/01/492.html"  title="Permanet Link to Js处理Json的&#8221;invalid label&#8221;错" >http://www.laruence.com/2008/09/01/492.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>当你使用ajax的时候,json是一个很方便的数据传输手段.<br/>
      但是对于很多人来说,经常会遇到的一个很令人头疼的问题就是&#8221;invalid label&#8221;错. 明明json串看起来是对的,怎么还会出错呢?
<p> 比如,如下的代码:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
   function handle_success(response){
       var json = eval(response); // response = &quot;{'foo' : 'bar'}&quot;;
  }
</pre>
<p>   浏览器会报,invalid label错, 这是因为, eval会尝试将你的response解释为一个label, 当你在脚本中直接写:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;script&gt;
  {'foo' : 'bar'};
&lt;/script&gt;
</pre>
<p>  会报错的原理是一样的.</p>
<p>  解决办法有俩个:</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
         var json = eval('(' + response + ')'); // response = &quot;{'foo' : 'bar'}&quot;;
 </pre>
<p> 或者</p>
<pre name="code"  class="sh_javascript"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
       eval('var json = ' + response); // response = &quot;{'foo' : 'bar'}&quot;;
       //json is available now
 </pre>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2008/09/01/492.html" >2008/11/01</a>, lee writes: 谢谢，不错，我也遇到这个问题，看了你这篇文章后解决了</li><li><a href="http://www.laruence.com/2008/09/01/492.html" >2009/01/09</a>, unique_zxs writes: 十分感谢你，我也遇到了这个问题。</li><li><a href="http://www.laruence.com/2008/09/01/492.html" >2009/05/12</a>, nece writes: 我也遇到了这个问题。</li><li><a href="http://www.laruence.com/2008/09/01/492.html" >2009/05/12</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 看来这个问题还是很普遍的~ , ;)</li><li><a href="http://www.laruence.com/2008/09/01/492.html" >2010/06/06</a>, Anonymous writes: 现在都不建议用eval了，解析JSON，可以用这个 
function jsonDecode(data){ 
    return (new Function("return " + data))(); 
} 

其他要想实现类似的eval的功能，一般都是在DOM中创建一个script节点，然后script.text = data; 

jQuery1.4中就是如此，其他好几种Javascript框架都是这么做的。</li><li><a href="http://www.laruence.com/2008/09/01/492.html" >2010/06/06</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @Anonymous  构建一个Function这个办法挺新颖, 赞.</li><li><a href="http://www.laruence.com/2008/09/01/492.html" >2011/01/10</a>, 彬 writes: 其实鸟哥您写这个理论上不是严格意义的 JSON, 应该算是 JavaScript 的 Object Literal吧。所以也能体现出和JSON一样的功能。JSON 与法规定 String 必须放在 双引号里面，单引号是不行的。以前看 ECMA-262 还是 RFC文档里面定义过，不太记得了。 
用 json2.js 的parse 验证一下， "{'foo' : 'bar'}" 这个一定不是 JSON， '{"foo" : "bar"}'就对了。</li><li><a href="http://www.laruence.com/2008/09/01/492.html" >2011/07/07</a>, Gone.Soft writes: 呵呵，这篇文章都被我抠出来了</li><li><a href="http://www.laruence.com/2008/09/01/492.html" >2011/12/03</a>, STR writes: 它困绕我几个小时了，现在按照你提供的方法做，可以了，谢谢！</li><li><a href="http://www.laruence.com/2008/09/01/492.html" >2011/12/23</a>, 小灰马 writes: 今天试了下，发现第一种方法比较好用，第二种方法可能会出错，例如我返回的是"\t\n\t\n {"name":"hello"}";(可能其他原因造成的多返回了几个换行符)，这时第二种方法就获得不到那个json对象啦</li></ul><hr/><h2>Related posts:</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/05/13/1462.html"  rel="bookmark"  title="Permanent Link: Javascript原型链和原型的一个误区" >Javascript原型链和原型的一个误区</a></li><li><a href="http://www.laruence.com/2011/10/05/2192.html"  rel="bookmark"  title="Permanent Link: mysqlnd插件mysqlnd_ms的介绍" >mysqlnd插件mysqlnd_ms的介绍</a></li><li><a href="http://www.laruence.com/2011/10/10/2239.html"  rel="bookmark"  title="Permanent Link: 让Json更懂中文(JSON_UNESCAPED_UNICODE)" >让Json更懂中文(JSON_UNESCAPED_UNICODE)</a></li><li><a href="http://www.laruence.com/2010/05/26/1541.html"  rel="bookmark"  title="Permanent Link: PHP类型转换相关的一个Bug" >PHP类型转换相关的一个Bug</a></li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2012/01/07/2453.html"  title="2012年1月全球www网站技术报告" >2012年1月全球www网站技术报告</a></li><li><a href="http://www.laruence.com/2011/10/10/2204.html"  title="JsonSerializable接口" >JsonSerializable接口</a></li><li><a href="http://www.laruence.com/2010/05/13/1462.html"  title="Javascript原型链和原型的一个误区" >Javascript原型链和原型的一个误区</a></li><li><a href="http://www.laruence.com/2010/02/02/1272.html"  title="注意PHP5.2.11之后的json_decode" >注意PHP5.2.11之后的json_decode</a></li><li><a href="http://www.laruence.com/2010/01/21/1254.html"  title="IE下var的重要性的又一佐证" >IE下var的重要性的又一佐证</a></li><li><a href="http://www.laruence.com/2009/09/27/1123.html"  title="关于Javascript的俩个有趣的探讨" >关于Javascript的俩个有趣的探讨</a></li><li><a href="http://www.laruence.com/2009/09/23/1089.html"  title="深入理解JavaScript定时机制" >深入理解JavaScript定时机制</a></li><li><a href="http://www.laruence.com/2009/09/08/1076.html"  title="深入理解Javascript之this关键字" >深入理解Javascript之this关键字</a></li><li><a href="http://www.laruence.com/2009/08/09/1036.html"  title="正确使用JS中的正则" >正确使用JS中的正则</a></li><li><a href="http://www.laruence.com/2009/05/28/863.html"  title="Javascript作用域原理" >Javascript作用域原理</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2008/09/01/492.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Firefox DNS Cache 清除 扩展 V0.1</title>
		<link>http://www.laruence.com/2008/08/21/358.html</link>
		<comments>http://www.laruence.com/2008/08/21/358.html#comments</comments>
		<pubDate>Thu, 21 Aug 2008 05:43:18 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Js/CSS]]></category>
		<category><![CDATA[随笔]]></category>
		<category><![CDATA[clear dns cache]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[Firefox DNS Cache]]></category>
		<category><![CDATA[Firefox DNS Cache 清除]]></category>
		<category><![CDATA[hosts]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=358</guid>
		<description><![CDATA[<p>推荐一个小东郭写的Friefox扩展：Firefox DNS Cache v0.1，支持firefox到3.*</p>
<p>做IT开发的工程师，经常需要配置host来进行开发，而不方便的是，每次修改了hosts以后，都要重启浏览器来使hosts生效。 这个扩展就是为了解决这个问题而来的， 使用了它，你就不再需要重启浏览器了</p>]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2008/08/21/358.html"  title="Permanet Link to Firefox DNS Cache 清除 扩展 V0.1" >http://www.laruence.com/2008/08/21/358.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>推荐一个<a href="http://onemouse.cn/"  target="_blank" >小东郭</a>写的Friefox扩展：Firefox DNS Cache v0.1，支持firefox到3.*。顺便帮他做个分流。</p>
<p>做IT开发的工程师，经常需要配置host来进行开发，而不方便的是，每次修改了hosts以后，都要重启浏览器来使hosts生效。 这个扩展就是为了解决这个问题而来的， 使用了它，你就不再需要重启浏览器了</p>
<blockquote>
<p>每次修改一下hosts都需要重新启动一下浏览器，现在不需要这么做了，写了一个 Firefox 扩展:<br/>
<a href="http://onemouse.cn/down/cleardnscache.xpi" >Clear DNS Cache</a><br/>
下载下来试试看，主要原理是，修改  network.dnsCacheExpiration 的值为0然后再修改回原先的值，这个参数在 firefox 默认是没有的，如果安装了这个扩展，点击不起作用的话，可以看下你的 about:config 是否有这个变量，如果没有，请添加上。这个变量单位为 second, 我的设置的是3600。</p>
<p> 这个扩展有三种方式可以使用，<br/>
1. 点击右键，可以看到 Clear DNS Cache , 选择即可。<br/>
2. 在工具栏中有 Clear DNS Cache 选项<br/>
3. 可以将 Clear DNS Cache 添加到 Tool bar 中，不知道的话，问问同事吧。</p>
<p>声明: 该扩展作者为:<a href="http://onemouse.cn/"  target="_blank" >guoxiaod</a>, 转载请注明出处，由于空间是租来的，所以安装可能 需要下载到本地，然后拖动到Firefox安装。</p>
<p><coolcode lang="php"  linenum="off" ><br/>
原文地址:<a href="http://onemouse.cn/i/17" >http://onemouse.cn/i/17</a></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2008/08/21/358.html" >2008/08/21</a>, <a href="http://www.ooso.net"  rel="external nofollow"  class="url" >volcano</a> writes: 无法找到该页
您正在搜索的页面可能已经删除、更名或暂时不可用。</li><li><a href="http://www.laruence.com/2008/08/21/358.html" >2008/08/21</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 恩，服务器有问题。
xpi文件就404，暂时先链接到晓东的下载link</li><li><a href="http://www.laruence.com/2008/08/21/358.html" >2008/08/22</a>, <a href="http://solor.cn"  rel="external nofollow"  class="url" >RainX</a> writes: 很是有用阿...</li><li><a href="http://www.laruence.com/2008/08/21/358.html" >2009/04/07</a>, jayee writes: Firefox DNS Flusher</li></ul><hr/><h2>Related posts:</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/03/05/1332.html"  rel="bookmark"  title="Permanent Link: 浏览器缓存机制" >浏览器缓存机制</a></li><li><a href="http://www.laruence.com/2007/11/15/10.html"  rel="bookmark"  title="Permanent Link: 一个误区（关于javascript的字符串拼接)" >一个误区（关于javascript的字符串拼接)</a></li><li><a href="http://www.laruence.com/2008/07/18/124.html"  rel="bookmark"  title="Permanent Link: Dom事件的srcTarget,strElement探幽" >Dom事件的srcTarget,strElement探幽</a></li><li><a href="http://www.laruence.com/2010/01/27/1265.html"  rel="bookmark"  title="Permanent Link: pkg-config与LD_LIBRARY_PATH" >pkg-config与LD_LIBRARY_PATH</a></li><li><a href="http://www.laruence.com/2011/07/14/2115.html"  rel="bookmark"  title="Permanent Link: Zend引擎的优化" >Zend引擎的优化</a></li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Random Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2012/02/08/2528.html"  title="PHP-5.3.9远程执行任意代码漏洞(CVE-2012-0830)" >PHP-5.3.9远程执行任意代码漏洞(CVE-2012-0830)</a></li><li><a href="http://www.laruence.com/2008/07/11/108.html"  title="IE下的Javascript调试利器:Companion.js" >IE下的Javascript调试利器:Companion.js</a></li><li><a href="http://www.laruence.com/2009/04/22/687.html"  title="谈谈用户可预感体验" >谈谈用户可预感体验</a></li><li><a href="http://www.laruence.com/2008/04/16/118.html"  title="采用PHP实现&#8221;服务器推&#8221;技术的聊天室" >采用PHP实现&#8221;服务器推&#8221;技术的聊天室</a></li><li><a href="http://www.laruence.com/2011/10/10/2239.html"  title="让Json更懂中文(JSON_UNESCAPED_UNICODE)" >让Json更懂中文(JSON_UNESCAPED_UNICODE)</a></li><li><a href="http://www.laruence.com/2010/04/12/1394.html"  title="IE下pre标签的InnerHTML问题" >IE下pre标签的InnerHTML问题</a></li><li><a href="http://www.laruence.com/2010/01/21/1254.html"  title="IE下var的重要性的又一佐证" >IE下var的重要性的又一佐证</a></li><li><a href="http://www.laruence.com/2010/12/14/1816.html"  title="Compilation failed: support for \P, \p, and \X has not been compiled" >Compilation failed: support for \P, \p, and \X has not been compiled</a></li><li><a href="http://www.laruence.com/2008/08/12/164.html"  title="深入理解PHP原理之函数(Introspecting PHP Function)" >深入理解PHP原理之函数(Introspecting PHP Function)</a></li><li><a href="http://www.laruence.com/2010/05/24/1515.html"  title="shell下发推脚本" >shell下发推脚本</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2008/08/21/358.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

