<?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>Fang Leo</title>
	<atom:link href="http://www.fangleo.cn/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.fangleo.cn</link>
	<description>Leo Fang’ blog - 博学之，慎思之，笃行之。</description>
	<lastBuildDate>Tue, 07 Sep 2010 05:57:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>利用httpHandlers实现Url ReWrite(2)</title>
		<link>http://www.fangleo.cn/?p=1301</link>
		<comments>http://www.fangleo.cn/?p=1301#comments</comments>
		<pubDate>Tue, 07 Sep 2010 05:56:40 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[.Net技术]]></category>
		<category><![CDATA[Url ReWrite]]></category>

		<guid isPermaLink="false">http://www.fangleo.cn/?p=1301</guid>
		<description><![CDATA[上一篇文章只是涉及简单的原理，今天的这篇稍微的深入，设计到Url ReWrite,具体看例子：
using System.Web;
using System.Text.RegularExpressions;
&#160;
&#160;
/// &#60;summary&#62;
///httphander 的摘要说明
/// &#60;/summ... ]]></description>
			<content:encoded><![CDATA[<p>上一篇文章只是涉及简单的原理，今天的这篇稍微的深入，设计到Url ReWrite,具体看例子：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">using System.Web;</li>
<li>using System.Text.RegularExpressions;</li>
<li>&nbsp;</li>
<li>&nbsp;</li>
<li>/// &lt;summary&gt;</li>
<li>///httphander 的摘要说明</li>
<li>/// &lt;/summary&gt;</li>
<li>public class httphander : IHttpHandler</li>
<li>{</li>
<li>&nbsp;&nbsp; &nbsp;public httphander()</li>
<li>&nbsp;&nbsp; &nbsp;{</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp;public void ProcessRequest(System.Web.HttpContext Context)</li>
<li>&nbsp;&nbsp; &nbsp;{</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;try</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//申明Request&nbsp; &nbsp; &nbsp; &nbsp; </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HttpRequest Request = Context.Request;</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//取来路Url </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string Url = Request.Url.PathAndQuery;</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string LookFor = @&quot;/([\d]{4}).do&quot;;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string SendTo = @&quot;/default.aspx?id=$1&quot;;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Regex Reg = new Regex(@LookFor);</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MatchCollection mc = Reg.Matches(Url);</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string reUrl = SendTo;</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (mc.Count &gt; 0)</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//用正则表达式进行匹配</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0, j = mc[0].Groups.Count; i &lt; j; i++)</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;reUrl = reUrl.Replace(&quot;$&quot; + i.ToString(), mc[0].Groups[i].Value); </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Context.Server.Execute(reUrl);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else {</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Context.Response.Redirect(Context.Request.Url.ToString());</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;catch</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Context.Response.Redirect(Context.Request.Url.ToString());</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp;public bool IsReusable {</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;get { return true; }</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>}</li></ol></div>
<p><span id="more-1301"></span></p>
<p>在上篇的配置下，直接修改上面的代码，然后测试一下，localhost/1234.do 就会自动跳转到default.aspx?id=1234.<br />
此外，我用了LookFor和SendTo两个变量来处理捕获字段和匹配字段，设想一下，如果我们把这些存放到某个xml文件中，同过for循环来里面你的配置xml中匹配，就能完成URL Rewirte的功能。</p>
<p>下篇文章会继续httpHandlers。</p>
<h2  class="related_post_title">这些文章或许你也喜欢...</h2><ul class="related_post"><li><a href="http://www.fangleo.cn/?p=1298" title="利用httpHandlers实现Url ReWrite(1)">利用httpHandlers实现Url ReWrite(1)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.fangleo.cn/?feed=rss2&amp;p=1301</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>利用httpHandlers实现Url ReWrite(1)</title>
		<link>http://www.fangleo.cn/?p=1298</link>
		<comments>http://www.fangleo.cn/?p=1298#comments</comments>
		<pubDate>Mon, 06 Sep 2010 10:02:27 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[.Net技术]]></category>
		<category><![CDATA[httpHandlers]]></category>
		<category><![CDATA[Url ReWrite]]></category>

		<guid isPermaLink="false">http://www.fangleo.cn/?p=1298</guid>
		<description><![CDATA[URL ReWrite非常的常用，PHP这方面的配置比较简单也很强大，其实.net可以很方便。以下内容只是一个大概，先了解一下基础：
ASP.NET都使用HTTP请求实现了大量的自己的功能。ASP.NET使用处理程序来... ]]></description>
			<content:encoded><![CDATA[<p>URL ReWrite非常的常用，PHP这方面的配置比较简单也很强大，其实.net可以很方便。以下内容只是一个大概，先了解一下基础：<br />
ASP.NET都使用HTTP请求实现了大量的自己的功能。ASP.NET使用处理程序来处理.aspx，.asmx，.soap和其他一些ASP.NET文件。<br />
实现HTTP处理程序包含以下步骤：<br />
1.编写一个实现IHttpHandler接口的类。<br />
2. 在web.config文件中注册这个处理程序。<br />
3.在Internet服务管理器中把文件扩展如：（.do）映射到ASP.NET ISAPI扩展DLL（aspnet_isapi.dll）上。<span id="more-1298"></span><br />
第一步<br />
构建类库：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">using System.Web;</li>
<li>/// &lt;summary&gt;</li>
<li>///httphander 的摘要说明</li>
<li>/// &lt;/summary&gt;</li>
<li>public class httphander : IHttpHandler</li>
<li>{</li>
<li>&nbsp;&nbsp; &nbsp;public httphander()</li>
<li>&nbsp;&nbsp; &nbsp;{</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp;public void ProcessRequest(System.Web.HttpContext context)</li>
<li>&nbsp;&nbsp; &nbsp;{</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;System.Web.HttpResponse obj = context.Response;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;obj.Write(&quot;&lt;html&gt;&lt;body&gt;测试一下，没有实际文件也能看到内容哦！&quot;);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;obj.Write(&quot;&lt;/body&gt;&lt;/html&gt;&quot;);</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp;public bool IsReusable {</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;get { return true; }</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>}</li></ol></div>
<p>第二步，注册的时候一定要写上一步的class（type=&#8221;httphander&#8221;）</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">&lt;httpHandlers&gt;</li>
<li>&nbsp;&nbsp; &lt;add verb=&quot;*&quot; path=&quot;*.do&quot; type=&quot;httphander&quot;/&gt;</li>
<li>&nbsp;&lt;/httpHandlers&gt;</li></ol></div>
<p>第三步<br />
运行IIS服务管理器，右键点击默认Web站点，选择属性，移动到主目录选项页，并点击配置按钮。<br />
应用程序配置对话框弹出来了。<br />
点击添加按钮并在可执行字段输入aspnet_isapi.dll文件路径，在扩展字段输入.do<br />
备注：可以先找到扩展名为.apsx，双击或编辑，复制“可执行文件地址”，然后添加.do的时候可以直接粘贴过去。最后最下方的确认文件是否存在的勾要去掉。</p>
<p>好了，测试一下吧，loaclhost/1.do或者按照你实际的配置访问一个根目录的文件。</p>
<h2  class="related_post_title">这些文章或许你也喜欢...</h2><ul class="related_post"><li><a href="http://www.fangleo.cn/?p=1301" title="利用httpHandlers实现Url ReWrite(2)">利用httpHandlers实现Url ReWrite(2)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.fangleo.cn/?feed=rss2&amp;p=1298</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>解析 this.initialize.apply(this, arguments)</title>
		<link>http://www.fangleo.cn/?p=1294</link>
		<comments>http://www.fangleo.cn/?p=1294#comments</comments>
		<pubDate>Tue, 31 Aug 2010 02:00:02 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[懒得分类]]></category>

		<guid isPermaLink="false">http://www.fangleo.cn/?p=1294</guid>
		<description><![CDATA[最近在整理一些常用的js方法，本在此基础上写一些常用的应用，顺便参考了一下其他框架的，其中看到prototype.js开始的几个方法，会用，但不是很理解，或者说理解还不透彻，所以google了一篇... ]]></description>
			<content:encoded><![CDATA[<p>最近在整理一些常用的js方法，本在此基础上写一些常用的应用，顺便参考了一下其他框架的，其中看到prototype.js开始的几个方法，会用，但不是很理解，或者说理解还不透彻，所以google了一篇文章，复习一下：</p>
<p>基础啊，但一定要扎实，知其然知其所以然.</p>
<p>prototype.js代码片段</p>
<p>代码如下:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">var Class = {</li>
<li>&nbsp;&nbsp; &nbsp;create: function() {</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return function() {</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.initialize.apply(this , arguments);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>}</li></ol></div>
<p><span id="more-1294"></span></p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">// Class使用方法如下</li>
<li>var A = Class.create();</li>
<li>A. prototype={</li>
<li>&nbsp;&nbsp; &nbsp;initialize:function(v){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this .value=v;</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp;showValue:function(){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;alert(this.value);</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>}</li>
<li>var a = new A(‘helloWord!');</li>
<li>a. showValue();//弹出对话框helloWord！</li></ol></div>
<p>l initialize是什么?<br />
l apply方法是干什么的？<br />
l arguments变量呢？<br />
l 为什么new A后就会执行initialize方法？<br />
寻找答案：</p>
<p>二、 Js的面向对象<br />
initialize是什么?<br />
只不过是个变量，代表一个方法，用途是类的构造函数。<br />
其具体功能靠js的面向对象支持，那么js的面向对象是什么样子的那？和java 的有什么相同与不同？<br />
看代码：</p>
<p>代码如下:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">var ClassName = function(v){</li>
<li>&nbsp;&nbsp; &nbsp;this.value=v;</li>
<li>&nbsp;&nbsp; &nbsp;this.getValue=function(){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return this.value;</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp;this.setValue=function(v){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this.value=v;</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>}</li></ol></div>
<p>那么JS中的函数和类有什么不同呢？<br />
其实是一样的，ClassName就是一个函数，当出现在new后面的时候就作为一个构造函数来构造对象。<br />
如</p>
<p>代码如下:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">var objectName1 = new ClassName(“a”);//得到一个对象</li></ol></div>
<p>其中objectName1就是执行ClassName构造函数后得到的对象，而在ClassName函数中的this指的就是new之后构造出来的对象，所以objectName1会后一个属性和两个方法。可以通过这样来调用他们：</p>
<p>代码如下:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">objectName1.setValue(''hello'');</li>
<li>alert(objectName1.getValue());//对话框hello</li>
<li>alert(objectName1.value) ;//对话框hello</li></ol></div>
<p>那么</p>
<p>复制代码 代码如下:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">var objectName2 = ClassName(“b”);//得到一个对象</li></ol></div>
<p>这样objectName2得到的是什么呢？显然是方法的返回值，这里ClassName只作为了一个普通的函数（虽然首字母大写了）。但是在之前写的ClassName中并没有返回值，所以objectName2会是undifinded那么“b”赋给谁了呢？在这并没有产生一个对象，而只是单纯的执行这个方法，所以这个“b”赋值给了调用这个方法的对象window，证据如下：<br />
var objectName2 = ClassName(“b”);//得到一个对象<br />
alert(window.value)；//对话框b<br />
所以JS中的所有function都是一样的，但是用途可能是不同的（用作构造对象抑或是执行一个过程）。<br />
下面该回到主题了initialize是干什么的？</p>
<p>代码如下:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">var Class = {</li>
<li>&nbsp;&nbsp; &nbsp;create: function() {</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return function() {</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.initialize.apply(this , arguments);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>}</li>
<li>var A = Class.create();</li></ol></div>
<p>这段代码是构造个一个function复制给A，这个function是</p>
<p>复制代码 代码如下:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">function() {</li>
<li>&nbsp;&nbsp; &nbsp;this.initialize.apply(this , arguments);</li>
<li>}</li></ol></div>
<p>并且后面这个方法是用来做构造函数的。当使用这个构造函数来构造对象的时候，会让构造出来的这个对象的initialize变量执行apply() 方法，apply()的用途后面在说，继续说initialize。这样在初始化对象的时候会联系到initialize（怎么联系就要看apply的了）。<br />
那么</p>
<p>代码如下:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">A.prototype={</li>
<li>&nbsp;&nbsp; &nbsp;initialize:function(v){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this .value=v;</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp;showValue:function(){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;alert(this.value);</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>}</li></ol></div>
<p>是什么意思呢？<br />
Prototype是“原型”的意思。A是一个function（），那么A. prototype，就是function中的一个变量，其实是个对象。这个对象拥有什么方法，那么function产生的对象就拥有什么方法，故<br />
var a = new A(‘helloWord!&#8217;);<br />
a. showValue();//弹出对话框helloWord！<br />
所以a对象也会有initialize方法，不只如此，每一个有A构造出来的对象都会有一个initialize方法，而在前面说过，构造的时候会调用构造函数，构造函数里面会让initialize去调用apply方法，于是在new A(‘helloWord!&#8217;)的时候initialize回去调用apply方法。这也就是调用了一个初始化的方法。</p>
<p>三、 call()和apply()<br />
下面开始研究apply()，在网上找了几个资料，并结合自己的研究，了解了call()和 apply()的功能。功能基本一样，function().call(object,{},{}……)或者function().apply (object,[……])的功能就是对象object调用这里的funciton()，不同之处是call参数从第二个开始都是传递给funciton 的，可以依次罗列用“，”隔开。而apply只有两个参数，第二个是一个数组，其中存储了所有传递给function的参数。<br />
this.initialize.apply(this , arguments);<br />
是什么意思？<br />
这里的第一个this，是指用new调用构造函数之后生成的对象，也就是前面的a，那么第二个this也当然应该是指同一个对象。那这句话就是this（也就是a）调用initialize方法，参数是arguments对象（参数的数组对象），所以在构造函数执行的时候，对象a就会去执行 initialize方法来初始化，这样就和单词“initialize”的意思对上了。<br />
那么执行initialize方法的参数怎么传递进去的呢？</p>
<p>四、 Arguments对象<br />
这段代码能说明一切了：</p>
<p>代码如下:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">function test(){</li>
<li>&nbsp;&nbsp; &nbsp;alert(typeof arguments);</li>
<li>&nbsp;&nbsp; &nbsp;for(var i=0; i&lt;arguments.length; i++){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;alert(arguments[i]);</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>}</li>
<li>test(&quot;1&quot;,&quot;2&quot;,&quot;3&quot;);</li>
<li>test(&quot;a&quot;,&quot;b&quot;);</li></ol></div>
<p>执行后alert(typeof arguments);会显示object，说明arguments是对象。然后会依次打出1、2、3。说明arguments就是调用函数的实参数组。</p>
<p>代码如下:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">var Class = {</li>
<li>&nbsp;&nbsp; &nbsp;create: function() {</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return function() {</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.initialize.apply(this , arguments);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>}</li></ol></div>
<p>arguments 就是create返回的构造函数的实参数组，那么在</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">var a = new A(‘helloWord!');</li></ol></div>
<p>的时候‘helloWord!&#8217;就是实参数组（虽然只有一个字符串），传递给方法apply，然后在调用initialize 的时候作为参数传递给初始化函数initialize。</p>
<p>ok,到这里请回顾一下，如果你还不清楚一下几个问题，请重新阅读本文：这是做什么用，原理是什么，为什么要这么用<br />
文章引用部分来自<a href="http://www.cnblogs.com/uedt/archive/2010/06/24/1764561.html">这里</a></p>
<h2  class="related_post_title">这些文章或许你也喜欢...</h2><ul class="related_post"><li><a href="http://www.fangleo.cn/?p=932" title="工业时代的解剖艺术">工业时代的解剖艺术</a></li><li><a href="http://www.fangleo.cn/?p=239" title="这话解恨，太解恨了&#8230;[转载]">这话解恨，太解恨了&#8230;[转载]</a></li><li><a href="http://www.fangleo.cn/?p=577" title="历史上战争屠城的不可避免和当前社会的屠城[节选]">历史上战争屠城的不可避免和当前社会的屠城[节选]</a></li><li><a href="http://www.fangleo.cn/?p=1002" title="Allok Video to FLV Converter [序列号]">Allok Video to FLV Converter [序列号]</a></li><li><a href="http://www.fangleo.cn/?p=636" title="壁纸月历 &#8211; 给你的桌面添加月历[.Net]">壁纸月历 &#8211; 给你的桌面添加月历[.Net]</a></li><li><a href="http://www.fangleo.cn/?p=353" title="初学扫盲:JavaScript和Java的区别">初学扫盲:JavaScript和Java的区别</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.fangleo.cn/?feed=rss2&amp;p=1294</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>监控DOM属性(attribute)变化的函数</title>
		<link>http://www.fangleo.cn/?p=1288</link>
		<comments>http://www.fangleo.cn/?p=1288#comments</comments>
		<pubDate>Fri, 06 Aug 2010 08:58:11 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[懒得分类]]></category>

		<guid isPermaLink="false">http://www.fangleo.cn/?p=1288</guid>
		<description><![CDATA[之前有的需求，就是减少自动更新的数据请求量，主要是针对需要及时更新数据的模块属于隐藏或者其parent是隐藏的状况。这种情况下，数据不需要更新，直到这个模块被切换到显示为止。
这... ]]></description>
			<content:encoded><![CDATA[<p>之前有的需求，就是减少自动更新的数据请求量，主要是针对需要及时更新数据的模块属于隐藏或者其parent是隐藏的状况。这种情况下，数据不需要更新，直到这个模块被切换到显示为止。</p>
<p>这样做的方法有很多，在数据更新内部加上两个控制方法（alive(),sleep()），在切换的同时激活对应的方法即可，似乎是一个比较简便的方法，但涉及到切换是需要知道改数据更新实例的实例名。而我的设想是，数据更新实例和切换实例完全地独立，不需要任何的交叉。所以，需要数据更新实例自己去检测这样的状态。</p>
<p>似乎还有一种简单的方法，比如我加上一个全局的cache去存储每个页面显示元素的状态，然后周期更新的时候去判断这个状态。问题是，我无法在某个更新实例被显示（或者说激活）的同时，同步地立即更新数据，更新实例的内部更新周期会导致一定的延迟，而之前由于隐藏之后，数据一致没有更新过，那么这部分的数据是严重滞后的。所以在不调用更新实例内部方法的同时，需要添加一个监听事件，便于捕获到页面的显示与隐藏。<span id="more-1288"></span></p>
<p>我选择了直接在更新某块内部添加这样的事件：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">this.auto = setInterval(function(){</li>
<li>&nbsp; var fn = arguments.callee;</li>
<li>&nbsp; //向上追溯检查是否为隐藏，放回obj{状态，第一个隐藏的节点}</li>
<li>&nbsp; if (_t.CheckVisible().state){ </li>
<li>&nbsp;&nbsp; &nbsp;_t.Update();</li>
<li>&nbsp; }else{</li>
<li>&nbsp;&nbsp; &nbsp;//添加监听事件</li>
<li>&nbsp;&nbsp; &nbsp;var o = _t.CheckVisible().obj;</li>
<li>&nbsp;&nbsp; &nbsp;if(indexOf(_t.Listerner,o) &gt;-1){&nbsp; </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;//_t.Listerner存储是否添加了监听事件</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;return;</li>
<li>&nbsp;&nbsp; &nbsp;}else{</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;_t.Listerner.push(o);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;attchListener(o,function(e){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(o.style.display!=&quot;none&quot;){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;detachListener(o,arguments.callee);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//移除监听</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_t.Listerner.splice(indexOf(_t.Listerner,o),1);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fn();</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;});</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>&nbsp; }</li>
<li>&nbsp; },this.options.interval);</li></ol></div>
<p>监听事件方法实现：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">var attchListener = function(elem,fn){</li>
<li>&nbsp;&nbsp; &nbsp;var b = new B();</li>
<li>&nbsp;&nbsp; &nbsp;if(elem.attachEvent &amp;&amp; !b.opera) {</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;var r = elem.attachEvent('onpropertychange', fn);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;return r;</li>
<li>&nbsp;&nbsp; &nbsp;}else if(b.firefox || b.opera){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;elem.addEventListener(&quot;DOMAttrModified&quot;,fn,false);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;return true;</li>
<li>&nbsp;&nbsp; &nbsp;}else{</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;//chrome及其他</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;elem.attrs = getAllAttributes(elem);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;elem.attrListener =setInterval(function(){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var tmp = getAllAttributes(elem);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(!equal(elem.attrs,tmp)){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;elem.attrs = getAllAttributes(elem);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fn();</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;},200);</li>
<li>&nbsp;&nbsp; &nbsp; }</li>
<li>&nbsp; }</li></ol></div>
<p>这里仅用到了判断style.display，在ie下，能捕获到Dom的所有变化，事件和innerHTML变化等，,由于是当前值是测试，这个方法的版本仅兼容ie6,7,8,firefox,opera,safari和chrome,其他浏览器未测试。</p>
<p>attchListener涉及到的几个方法：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">//移除</li>
<li>&nbsp;&nbsp; detachListener = function(elem,fn){</li>
<li>&nbsp;&nbsp; &nbsp;var b = new B();</li>
<li>&nbsp;&nbsp; &nbsp;if(elem.attachEvent &amp;&amp; !b.opera) {</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;var r = elem.detachEvent('onpropertychange', fn);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;return r;</li>
<li>&nbsp;&nbsp; &nbsp;}else if(b.firefox || b.opera){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;elem.removeEventListener(&quot;DOMAttrModified&quot;,fn,false);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;return true;</li>
<li>&nbsp;&nbsp; &nbsp;}else{</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;if(elem.attrListener) clearInterval(elem.attrListener);</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>&nbsp; }</li>
<li>&nbsp;&nbsp; //浏览器判断</li>
<li>&nbsp;&nbsp; B = function() {</li>
<li>&nbsp;&nbsp; &nbsp;var ua = window.navigator.userAgent.toLowerCase();</li>
<li>&nbsp;&nbsp; &nbsp;var b = {</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;msie: /msie/.test(ua) &amp;&amp; !/opera/.test(ua),</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;opera: /opera/.test(ua),</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;safari: /webkit/.test(ua) &amp;&amp; !/chrome/.test(ua),</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;firefox: /firefox/.test(ua),</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;chrome: /chrome/.test(ua)</li>
<li>&nbsp;&nbsp; &nbsp;};</li>
<li>&nbsp;&nbsp; &nbsp;var vMark = &quot;&quot;;</li>
<li>&nbsp;&nbsp; &nbsp;for (var i in b) {</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;if (b[i]) {</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;vMark = &quot;safari&quot; == i ? &quot;version&quot;: i;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;break</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp;b.version = vMark &amp;&amp; RegExp(&quot;(?:&quot; + vMark + &quot;)[\\/: ]([\\d.]+)&quot;).test(ua) ? RegExp.$1: &quot;0&quot;;</li>
<li>&nbsp;&nbsp; &nbsp;b.ie = b.msie;</li>
<li>&nbsp;&nbsp; &nbsp;b.ie6 = b.msie &amp;&amp; parseInt(b.version, 10) == 6;</li>
<li>&nbsp;&nbsp; &nbsp;b.ie7 = b.msie &amp;&amp; parseInt(b.version, 10) == 7;</li>
<li>&nbsp;&nbsp; &nbsp;b.ie8 = b.msie &amp;&amp; parseInt(b.version, 10) == 8;</li>
<li>&nbsp;&nbsp; &nbsp;return b</li>
<li>&nbsp; };</li>
<li>&nbsp; </li>
<li>&nbsp;&nbsp; &nbsp;//获取node的所有attributes&nbsp; &nbsp; &nbsp; </li>
<li>&nbsp; function getAllAttributes(node){</li>
<li>&nbsp;&nbsp; &nbsp;var obj = {};</li>
<li>&nbsp;&nbsp; &nbsp;// 判断输入的是否是元素节点</li>
<li>&nbsp;&nbsp; &nbsp;if(Boolean(node) &amp;&amp; node.nodeType == 1){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;for(var i = 0; i &lt; node.attributes.length; i++){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;var attr = node.attributes[i];</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;obj[attr.name] = attr.value;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp;return obj;</li>
<li>&nbsp; }</li>
<li>&nbsp; </li>
<li>&nbsp;&nbsp; &nbsp;//判断两个对象是否相同</li>
<li>&nbsp; function equal(objA, objB)</li>
<li>&nbsp; {</li>
<li>&nbsp;&nbsp; &nbsp;if (typeof arguments[0] != typeof arguments[1]){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;return false;&nbsp; &nbsp;</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp;//数组</li>
<li>&nbsp;&nbsp; &nbsp;if (arguments[0] instanceof Array)</li>
<li>&nbsp;&nbsp; &nbsp;{</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;if (arguments[0].length != arguments[1].length){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return false;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;var allElementsEqual = true;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;for (var i = 0; i &lt; arguments[0].length; ++i)</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;{</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (typeof arguments[0][i] != typeof arguments[1][i]){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (typeof arguments[0][i] == 'number' &amp;&amp; typeof arguments[1][i] == 'number')</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;allElementsEqual = (arguments[0][i] == arguments[1][i]);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;allElementsEqual = arguments.callee(arguments[0][i], arguments[1][i]);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; </li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;return allElementsEqual;</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>&nbsp; </li>
<li>&nbsp;&nbsp; &nbsp;//对象</li>
<li>&nbsp;&nbsp; &nbsp;if (arguments[0] instanceof Object &amp;&amp; arguments[1] instanceof Object)</li>
<li>&nbsp;&nbsp; &nbsp;{</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;var result = true;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;var attributeLengthA = 0, attributeLengthB = 0;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;for (var o in arguments[0])</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;{</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (typeof arguments[0][o] == 'number' || typeof arguments[0][o] == 'string'){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result = eval(&quot;arguments[0]['&quot; + o + &quot;'] == arguments[1]['&quot; + o + &quot;']&quot;);</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (result==false){break;}</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}else {</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!arguments.callee(eval(&quot;arguments[0]['&quot; + o + &quot;']&quot;), eval(&quot;arguments[1]['&quot; + o + &quot;']&quot;)))</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result = false;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return result;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;++attributeLengthA;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;for (var o in arguments[1]) {</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;++attributeLengthB;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;if (attributeLengthA != attributeLengthB){</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;result = false;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp;return result;</li>
<li>&nbsp;&nbsp; &nbsp;}</li>
<li>&nbsp;&nbsp; &nbsp;return arguments[0] == arguments[1];</li>
<li>&nbsp; }</li></ol></div>
<h2  class="related_post_title">这些文章或许你也喜欢...</h2><ul class="related_post"><li><a href="http://www.fangleo.cn/?p=896" title="Twitter Weekly Updates for 2009-04-26">Twitter Weekly Updates for 2009-04-26</a></li><li><a href="http://www.fangleo.cn/?p=56" title="JS添加事件处理函数">JS添加事件处理函数</a></li><li><a href="http://www.fangleo.cn/?p=336" title="植入女性乳房的苹果MP3">植入女性乳房的苹果MP3</a></li><li><a href="http://www.fangleo.cn/?p=275" title="十五招让你轻松当领导">十五招让你轻松当领导</a></li><li><a href="http://www.fangleo.cn/?p=263" title="JavaScript中的5种常用事件解读">JavaScript中的5种常用事件解读</a></li><li><a href="http://www.fangleo.cn/?p=74" title="如果美国有个央视，新闻联播就是这样">如果美国有个央视，新闻联播就是这样</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.fangleo.cn/?feed=rss2&amp;p=1288</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET接受Request.QueryString的乱码解决办法</title>
		<link>http://www.fangleo.cn/?p=1286</link>
		<comments>http://www.fangleo.cn/?p=1286#comments</comments>
		<pubDate>Tue, 03 Aug 2010 08:01:05 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[懒得分类]]></category>
		<category><![CDATA[encodeURI]]></category>
		<category><![CDATA[乱码]]></category>

		<guid isPermaLink="false">http://www.fangleo.cn/?p=1286</guid>
		<description><![CDATA[简单说明一下问题，js跳转过来的地址，用.net接受，通过querystring提取参数返回乱码。环境均为GB2312(webconfig配置和js编码)。
比如下面这串地址：go.aspx?name=%E5%BB%BA%E6%96%B0%E8%82%A1%E4%BB%BD
如果直接... ]]></description>
			<content:encoded><![CDATA[<p>简单说明一下问题，js跳转过来的地址，用.net接受，通过querystring提取参数返回乱码。环境均为GB2312(webconfig配置和js编码)。</p>
<p>比如下面这串地址：go.aspx?name=%E5%BB%BA%E6%96%B0%E8%82%A1%E4%BB%BD</p>
<p>如果直接用HttpContext.Current.Request.QueryString["name"]取值，通常乱码（在上述环境中。）那么是我用js直接window.open(&#8216;go.aspx?name=&#8217;+encodeURI(&#8220;建新股份&#8221;))过来的。</p>
<p>通常会用HttpUtility.UrlDecode，或Server.UrlDecode来解码，但问题是，一般情况下，他会乱码。在解码之前，接受到的参数，已经是乱码了。此时解码毫无意义。所以向前追溯，在接收前解码？<span id="more-1286"></span></p>
<p>解决比较简单，因为调试的时候我发现HttpContext.Current.Request.Url没有乱码，很好，我们就从这里入手。</p>
<p>NameValueCollection utf8Requests;<br />
utf8Requests =  HttpUtility.ParseQueryString(Request.Url.Query, Encoding.GetEncoding(&#8220;utf-8&#8243;));</p>
<p>或</p>
<p>NameValueCollection gb2312Requests;<br />
gb2312Requests =  HttpUtility.ParseQueryString(Request.Url.Query, Encoding.GetEncoding(&#8220;gb2312&#8243;));</p>
<p>请尝试，因为你也不能完全确定你环境的编码。上述我的问题中，%E5%BB%BA%E6%96%B0%E8%82%A1%E4%BB%BD是uft-8编码，而我的环境是gb2312的，所以我用了utf8Requests，然后：</p>
<p>HttpContext.Current.Response.Write(utf8Requests["name"] + &#8220;&lt;br /&gt;&#8221;);</p>
<p>或<br />
HttpContext.Current.Response.Write(HttpUtility.UrlDecode(utf8Requests["name"]) + &#8220;&lt;br /&gt;&#8221;);</p>
<p>或<br />
HttpContext.Current.Response.Write(Server.UrlDecode(utf8Requests["name"]) + &#8220;&lt;br /&gt;&#8221;);</p>
<p>问题解决。</p>
<h2  class="related_post_title">这些文章或许你也喜欢...</h2><ul class="related_post"><li><a href="http://www.fangleo.cn/?p=764" title="绝对私藏：122秒的广告 122年的英国历史">绝对私藏：122秒的广告 122年的英国历史</a></li><li><a href="http://www.fangleo.cn/?p=260" title="2008年8月4日日志">2008年8月4日日志</a></li><li><a href="http://www.fangleo.cn/?p=257" title="日本的古怪饮料">日本的古怪饮料</a></li><li><a href="http://www.fangleo.cn/?p=361" title="千橡启用Kaixin.com域名被指克隆开心网[附注册邀请链接]">千橡启用Kaixin.com域名被指克隆开心网[附注册邀请链接]</a></li><li><a href="http://www.fangleo.cn/?p=797" title="米兰09爱爱设计展">米兰09爱爱设计展</a></li><li><a href="http://www.fangleo.cn/?p=291" title="如何让男士保持精力旺盛的25招">如何让男士保持精力旺盛的25招</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.fangleo.cn/?feed=rss2&amp;p=1286</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>检查素数的正则表达式</title>
		<link>http://www.fangleo.cn/?p=1284</link>
		<comments>http://www.fangleo.cn/?p=1284#comments</comments>
		<pubDate>Fri, 23 Jul 2010 08:19:00 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[懒得分类]]></category>
		<category><![CDATA[正则表达式]]></category>

		<guid isPermaLink="false">http://www.fangleo.cn/?p=1284</guid>
		<description><![CDATA[一般来说，我们会使用正规表达式来做字符串匹配，今天在网上浏览的时候，看到了有人用正则表达式来检查一个数字是否为素数（质数），让我非常感兴趣，这个正则表达式如入所示：

检查... ]]></description>
			<content:encoded><![CDATA[<p>一般来说，我们会使用正规表达式来做字符串匹配，今天在网上浏览的时候，看到了有人用正则表达式来检查一个数字是否为素数（质数），让我非常感兴趣，这个正则表达式如入所示：</p>
<p style="text-align: center;"><img title="检查素数的正则表达式" src="http://coolshell.cn/wp-content/uploads/2010/07/regexpr-for-prime-number.jpg" alt="" width="450" height="45" /></p>
<p style="text-align: center;">检查素数的正则表达式/^1?$|^(11+?)+$/</p>
<p>要使用这个正规则表达式，你需要把自然数转成多个1的字符串，如：2 要写成 “11”， 3 要写成 “111”, 17 要写成“11111111111111111”，这种工作使用一些脚本语言可以轻松的完成。</p>
<p>一开始我对这个表达式持怀疑态度，但仔细研究了一下这个表达式，发现是非常合理的，下面，让我带你来细细剖析一下是这个表达式的工作原理。<span id="more-1284"></span></p>
<p>首先，我们看到这个表达式中有“|”，也就是说这个表达式可以分成两个部分：/^1?$/ 和 /^(11+?)\1+$/</p>
<p>•第一部分：/^1?$/， 这个部分相信不用我多说了，其表示匹配“空串”以及字串中只有一个“1”的字符串。<br />
•第二部分：/^(11+?)\1+$/，这个部分是整个表达式的关键部分。其可以分成两个部分，(11+?) 和\1+$，前半部很简单了，匹配以“11”开头的并重复0或n个1的字符串，后面的部分意思是把前半部分作为一个字串去匹配还剩下的字符串1次或多次（这句话的意思是——剩余的字串的1的个数要是前面字串1个数的整数倍）。<br />
可见这个正规则表达式是取非素数，要得到素数还得要对整个表达式求反。通过上面的分析，我们知道，第二部分是最重要的，对于第二部分，举几个例子，</p>
<p>示例一：判断自然数8。我们可以知道，8转成我们的格式就是“11111111”，对于(11+?)，其匹配了“11”，于是还剩下“111111”，而\1+$正好匹配了剩下的“111111”，因为，“11”这个模式在“111111”出现了三次，符合模式匹配，返回true。所以，匹配成功，于是这个数不是质数。</p>
<p>示例二：判断自然数11。转成我们需要的格式是“11111111111”（十一个1），对于(11+?)，其匹配了“11”（前两个1），还剩下“111111111”（九个1），而\1+$无法为“11”匹配那“九个1”，因为“11”这个模式并没有在“九个1”这个串中正好出现N次。于是，我们的正则表达式引擎会尝试下一种方法，先匹配“111”（前三个1），然后把“111”作为模式去匹配剩下的“11111111”（八个1），很明显，那“八个1”并没有匹配“三个1”多次。所以，引擎会继续向下尝试……直至匹配成功。</p>
<p>通过示例二，我们可以得到这样的等价数算算法，正则表达式会匹配这若干个1中有没有出现“二个1”的整数倍，“三个1”的整数倍，“四个1”的整数倍……，而，这正好是我们需要的算素数的算法。现在大家明白了吧。</p>
<p>下面，我们用perl来使用这个正规则表达式不停地输出素数：（关于perl的语法我就不多说了，请注意表达式前的取反操作符）</p>
<p>查看源代码打印帮助<br />
1 perl -e&#8217;$|++;(1 x$_)!~/^1?$|^(11+?)\1+$/&amp;amp;&amp;amp;print&amp;quot;$_ &amp;quot;while ++$_&#8217;</p>
<p>另外，让我们来举一反三，根据上述的这种方法，我们甚至可以用正则表达式来求证某方式是否有解，如：</p>
<p>•二元方程：17x + 12y = 51 判断其是否有解的正则表达式是：^(.*)\1{16}(.*)\2{11}$<br />
•三元方程：11x + 2y + 5z = 115 判断其是否有解的正则表达式是：^(.*)\1{10}(.*)\2{1}(.*)\3{4}$<br />
大家不妨自己做做练习，为什么上述的两个正则表达式可以判断方程是否有解。如果无法参透其中的奥妙的话，你可以读读这篇英文文章。</p>
<h2  class="related_post_title">这些文章或许你也喜欢...</h2><ul class="related_post"><li><a href="http://www.fangleo.cn/?p=1004" title="正则表达式高级技巧的基本概念及实例详解">正则表达式高级技巧的基本概念及实例详解</a></li><li><a href="http://www.fangleo.cn/?p=244" title="常用正则表达式收集">常用正则表达式收集</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.fangleo.cn/?feed=rss2&amp;p=1284</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>createDocumentFragment的用法</title>
		<link>http://www.fangleo.cn/?p=1281</link>
		<comments>http://www.fangleo.cn/?p=1281#comments</comments>
		<pubDate>Fri, 04 Jun 2010 05:51:49 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[懒得分类]]></category>

		<guid isPermaLink="false">http://www.fangleo.cn/?p=1281</guid>
		<description><![CDATA[一旦把节点添加到document.body(或其后的节点)中，页面就会立即反映出这个变化。对于少量的更新，这是很好的。然而，当要向document.body添加大量数据时，如果逐个添加这些节点，这个过程有可... ]]></description>
			<content:encoded><![CDATA[<p>一旦把节点添加到document.body(或其后的节点)中，页面就会立即反映出这个变化。对于少量的更新，这是很好的。然而，当要向document.body添加大量数据时，如果逐个添加这些节点，这个过程有可能会十分缓慢。为解决这个问题，可以创建一个文档碎片，把所有的新节点附加其上，然后把文档碎片的内容一次性添加到document中。</p>
<p>假设你想创建十个新段落。你可能这样写：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">var arrText=[&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;5&quot;,&quot;6&quot;,&quot;7&quot;,&quot;8&quot;,&quot;9&quot;,&quot;10&quot;];</li>
<li>for(var i=0;i</li>
<li>{</li>
<li>var op=document.createElement(&quot;P&quot;);</li>
<li>var oText=document.createTextNode(arrText[i]);</li>
<li>op.appendChild(oText);</li>
<li>document.body.appendChild(op);</li>
<li>}</li></ol></div>
<p>这段代码运行良好，但问题是它调用了十次document.body.appendChild(),每次要产生一次页面刷新。这时，文档碎片会更高效：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">var arrText=[&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;5&quot;,&quot;6&quot;,&quot;7&quot;,&quot;8&quot;,&quot;9&quot;,&quot;10&quot;];</li>
<li>var oFrag=document.createDocumentFragment();</li>
<li>for(var i=0;i</li>
<li>{</li>
<li>var op=document.createElement(&quot;P&quot;);</li>
<li>var oText=document.createTextNode(arrText[i]);</li>
<li>op.appendChild(oText);</li>
<li>oFrag.appendChild(op);</li>
<li>}</li>
<li>document.body.appendChild(oFrag);</li></ol></div>
<p>这段代码中,document.body.appendChild()仅调用了一次，这意味首只需要进行一次屏幕的刷新。</p>
<h2  class="related_post_title">这些文章或许你也喜欢...</h2><ul class="related_post"><li><a href="http://www.fangleo.cn/?p=369" title="卖猪男如何引发经济危机？">卖猪男如何引发经济危机？</a></li><li><a href="http://www.fangleo.cn/?p=499" title="英语口语学习方法整理汇总                                 ">英语口语学习方法整理汇总                                 </a></li><li><a href="http://www.fangleo.cn/?p=189" title="激人奋进的七个经典故事">激人奋进的七个经典故事</a></li><li><a href="http://www.fangleo.cn/?p=1286" title="ASP.NET接受Request.QueryString的乱码解决办法">ASP.NET接受Request.QueryString的乱码解决办法</a></li><li><a href="http://www.fangleo.cn/?p=183" title="[转帖]十句话-十分钟">[转帖]十句话-十分钟</a></li><li><a href="http://www.fangleo.cn/?p=614" title="jQuery 页面载入进度条">jQuery 页面载入进度条</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.fangleo.cn/?feed=rss2&amp;p=1281</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>凤凰网微博</title>
		<link>http://www.fangleo.cn/?p=1279</link>
		<comments>http://www.fangleo.cn/?p=1279#comments</comments>
		<pubDate>Thu, 08 Apr 2010 14:22:22 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[懒得分类]]></category>

		<guid isPermaLink="false">http://www.fangleo.cn/?p=1279</guid>
		<description><![CDATA[http://t.ifeng.com/fang
选择凤凰网主要是期待它可能会宽松的监管环境。能够尽量客观地去评述和沟通彼此的观点与想法。
此外，它的尝试与改动也是在微博大战中首次出现的一个亮点。
先期待，... ]]></description>
			<content:encoded><![CDATA[<p><a href="http://t.ifeng.com/fang" target="_blank">http://t.ifeng.com/fang</a><br />
选择凤凰网主要是期待它可能会宽松的监管环境。能够尽量客观地去评述和沟通彼此的观点与想法。<br />
此外，它的尝试与改动也是在微博大战中首次出现的一个亮点。</p>
<p>先期待，再观望</p>
<h2  class="related_post_title">这些文章或许你也喜欢...</h2><ul class="related_post"><li><a href="http://www.fangleo.cn/?p=99" title="免费在线翻译服务">免费在线翻译服务</a></li><li><a href="http://www.fangleo.cn/?p=499" title="英语口语学习方法整理汇总                                 ">英语口语学习方法整理汇总                                 </a></li><li><a href="http://www.fangleo.cn/?p=244" title="常用正则表达式收集">常用正则表达式收集</a></li><li><a href="http://www.fangleo.cn/?p=935" title="55个最常被问到的面试问题">55个最常被问到的面试问题</a></li><li><a href="http://www.fangleo.cn/?p=575" title="本站点升级到wordpress2.7">本站点升级到wordpress2.7</a></li><li><a href="http://www.fangleo.cn/?p=376" title="iPhone VS 魅族M8操作界面对比">iPhone VS 魅族M8操作界面对比</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.fangleo.cn/?feed=rss2&amp;p=1279</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>乱谈，机器猫与我的网络购物观</title>
		<link>http://www.fangleo.cn/?p=1277</link>
		<comments>http://www.fangleo.cn/?p=1277#comments</comments>
		<pubDate>Wed, 31 Mar 2010 14:24:38 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[懒得分类]]></category>

		<guid isPermaLink="false">http://www.fangleo.cn/?p=1277</guid>
		<description><![CDATA[     电子商务发展到现在，可以说是真正的融入了我们的生活，虽然严格地讲，其中的企业间的商务模式并咩有十分广泛地展开，但网络购物已经走进了普通人的生活，我算一个。
     除了某些... ]]></description>
			<content:encoded><![CDATA[<p>     电子商务发展到现在，可以说是真正的融入了我们的生活，虽然严格地讲，其中的企业间的商务模式并咩有十分广泛地展开，但网络购物已经走进了普通人的生活，我算一个。<br />
     除了某些水货需要直接当面交易以外，其他的东西基本上是通过网络平台来购买。当当上面买了很多书，卓越上买过了zippo，vancel买过衬衫，京东新蛋买过很多3c产品。甚至豆浆机，冰箱和电视等家电，也是通过网络买的。通过网络购物，已经成为我的首选。<br />
     最近在关注《机器猫》，吉林美术出版社，经典32K，45本德国套装。当当的价格是240（折后价），卓越是228（折后价）。《机器猫》是童年的回忆，很小的时候只能一本一本的看，且通常是断本。所以很早就有了买一套的念头。前一次准备买，被老婆否决，应该丫头还小，适应不了书中的内容，其实我是买了我自己看的，杯具。这次特意地收藏了，就等有什么活动就入手。<br />
     最早买书是通过贝塔斯曼书友会，那时候还是邮寄，后来通过新华书店网站（就一次，没折扣），再后来用淘宝（大量的二手书），然后就是当当卓越（延用至今）了。今天特意要说一下淘宝，最近被他的新闻骚扰的有点心烦，尤其是3.15前后的广告。<br />
     但，我并讨厌淘宝，我每年通过这个平台购买食品，化妆品。通过它的支付宝支付水电费，还行用卡。只是，是使用的趋势在减少，甚至可以说是锐减。我不敢通过淘宝买任何的超过500的东西，因为我无法确认到我手里的东西是不是卖家描述那样的，虽然淘宝声称它有1亿保障资金，500的保障团队。信任没有在我平时的购物中累积，反而略次被破坏，这个是淘宝目前面临的最大问题。<br />
淘宝错过了太多，但愿支付宝能有所突破。<br />
      。。。<br />
      我发现现在我表达我的观点很有问题，我越是追求所谓的客观，越是偏向于保守。<br />
      算了，结束。</p>
<h2  class="related_post_title">这些文章或许你也喜欢...</h2><ul class="related_post"><li><a href="http://www.fangleo.cn/?p=93" title="向主考官提出的10个漂亮的问题 ">向主考官提出的10个漂亮的问题 </a></li><li><a href="http://www.fangleo.cn/?p=242" title="最佳网页宽度及其实现">最佳网页宽度及其实现</a></li><li><a href="http://www.fangleo.cn/?p=617" title="13个代码注释的小技巧">13个代码注释的小技巧</a></li><li><a href="http://www.fangleo.cn/?p=1071" title="IE双倍边距BUG的现象及解决办法">IE双倍边距BUG的现象及解决办法</a></li><li><a href="http://www.fangleo.cn/?p=180" title="2008年7月10日日志">2008年7月10日日志</a></li><li><a href="http://www.fangleo.cn/?p=584" title="绝对私藏，广告也能很励志！">绝对私藏，广告也能很励志！</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.fangleo.cn/?feed=rss2&amp;p=1277</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>小偷，手机及google</title>
		<link>http://www.fangleo.cn/?p=1264</link>
		<comments>http://www.fangleo.cn/?p=1264#comments</comments>
		<pubDate>Tue, 23 Mar 2010 14:36:53 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[懒得分类]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[小偷]]></category>
		<category><![CDATA[手机]]></category>

		<guid isPermaLink="false">http://www.fangleo.cn/?p=1264</guid>
		<description><![CDATA[“哗”，一为男同学从我后面一下子拦在我的面前，耳朵上还挂着耳线。 “你看到了我的手机了”他很焦虑的问，略有些激动。我下意识摸了一下我自己的手机和钱包，还在。然后了解到在几... ]]></description>
			<content:encoded><![CDATA[<p>“哗”，一为男同学从我后面一下子拦在我的面前，耳朵上还挂着耳线。 “你看到了我的手机了”他很焦虑的问，略有些激动。我下意识摸了一下我自己的手机和钱包，还在。然后了解到在几秒之前，就在我和他擦肩而过没几秒，他的N97，当时本来应该继续躺在他上衣口袋里，为他播放音乐的手机，突然没有了踪影。</p>
<p>这个情形与我去年丢iphone是一样的，连天气，时间情形，一模一样。我立即提醒他报警，但是他显然有些急躁，茫然地向地上四处张望。愿上帝保佑他，如同我老婆后来说的那样，他一定很痛苦，尤其是如果他只是一个刚毕业的学生的话。<span id="more-1264"></span></p>
<p>其实这种情况很难可以定性是被偷了还是被抢了，或者是自己丢了。如此遭遇所带来的心理打击往往比单纯的被偷要来的大，比被抢稍微好一点。你甚至不能确定手机是怎么没有的。不过似乎情况没有那么糟糕，因为很快就有两个疑似便衣的中年男女从马路对面走了过来，然后一行人向最可能的现场走去。而我这个第一“嫌疑”对象，无奈地叹口气，继续我的回家的路程。</p>
<p>世博召开在即，治安问题很严峻，希望政府一定要严打此类事件。同时也要再次提醒大家，手机听歌不要放在上衣口袋，那样真的是太危险了，不被偷也容易丢。务必放在你的包里或者衣服里面的口袋，贵重物品同理。</p>
<p>附加一个话题。</p>
<p>Google.cn终于退出中国内地，转战香港。而我们的百度，并没有表现丝毫惺惺相惜之意，反而略显得意地说“我们是不是也要进入香港市场”（词非原话原句，但意思相似），实在有违我们5000年的文化沉淀。</p>
<p>google这个话题现在很沉重，加上涉及政治，在这里不便多评。就个人得失而言，近年来，我几乎一直在用google的搜索引擎(接百度的推广电话)，尤其是gmail，加已经集合了我其他所有的邮箱。虽然此次离开的并没有从根本上影响我的继续使用，但对于长久而言，不是很乐观。对此我只能无奈地说“google，走好”。</p>
<p>十分的无奈，我亲爱的祖国奈。</p>
<h2  class="related_post_title">这些文章或许你也喜欢...</h2><ul class="related_post"><li><a href="http://www.fangleo.cn/?p=338" title="Google 手机 Android 时代正式来临 ">Google 手机 Android 时代正式来临 </a></li><li><a href="http://www.fangleo.cn/?p=1049" title="cctv的曝光将间接的提高google的市场份额">cctv的曝光将间接的提高google的市场份额</a></li><li><a href="http://www.fangleo.cn/?p=865" title="Google推出“人肉搜索”服务">Google推出“人肉搜索”服务</a></li><li><a href="http://www.fangleo.cn/?p=659" title="Google Adsense for Domain 已向所有用户开放">Google Adsense for Domain 已向所有用户开放</a></li><li><a href="http://www.fangleo.cn/?p=568" title="Google公布2008年度关键词排行榜 ">Google公布2008年度关键词排行榜 </a></li><li><a href="http://www.fangleo.cn/?p=567" title="Google Chrome 1.0.154.36 Final 正式版发布">Google Chrome 1.0.154.36 Final 正式版发布</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.fangleo.cn/?feed=rss2&amp;p=1264</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
