<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客网-asfman-文章分类-javascript</title><link>http://www.cnitblog.com/asfman/category/2127.html</link><description>有些人注定要生活在彼岸 可以亲近可以爱怜 甚至可以穷尽一生去思念 只是无法触及 有些距离 注定不能跨越 只能俩俩相望 就像有些爱只能养在心里 长在眼中 不要捧在手里 放在身边 注定只能邂逅 无法遭遇</description><language>zh-cn</language><lastBuildDate>Fri, 11 Apr 2008 16:27:09 GMT</lastBuildDate><pubDate>Fri, 11 Apr 2008 16:27:09 GMT</pubDate><ttl>60</ttl><item><title>with and eval together change the function's scope chain </title><link>http://www.cnitblog.com/asfman/articles/42251.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Fri, 11 Apr 2008 08:50:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/42251.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/42251.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/42251.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/42251.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/42251.html</trackback:ping><description><![CDATA[&lt;script&gt;<br>Function.prototype.$bind=function(object)<br>{<br>&nbsp;&nbsp;&nbsp; function callback()<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return arguments[0];<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; with(object)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return eval("callback("+this.toString()+")");<br>&nbsp;&nbsp;&nbsp; }<br>}<br><br>var obj={a:1,b:2};<br>var f=function (){<br>&nbsp;&nbsp;&nbsp; a=10;<br>&nbsp;&nbsp;&nbsp; b=11;<br>}.$bind(obj);<br><br>f();<br>alert(obj.a);<br>&lt;/script&gt; <br><img src ="http://www.cnitblog.com/asfman/aggbug/42251.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2008-04-11 16:50 <a href="http://www.cnitblog.com/asfman/articles/42251.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>变量作用域</title><link>http://www.cnitblog.com/asfman/articles/41383.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Mon, 24 Mar 2008 01:23:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/41383.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/41383.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/41383.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/41383.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/41383.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 我们可能注意到了，javascript的变量和对象的属性之间有很多的相似点。例如，它们采用相同的赋值方式，而且在j表达式中的用法也相同，等等。那么变量i和对象o的属性i之间有什么根本的区别吗？答案是没有。在js中变量基本上和对象的属性是一样的。<br>&nbsp;&nbsp;&nbsp;&nbsp; 当js的解释器开始运行时，它首先要做的事情之一就是执行任何js代码之前，创建一个全局对象（gloal object）。这个对象的属性就是js程序的全局变量。当声明一个js全局变量时，实际上所做的事定义了那个全局对象的一个属性。<br>&nbsp;&nbsp;&nbsp; 此外，js解释器还会用预定义的值和函数来初始化全局对象的许多属性。例如，属性Infinity、parseInt和Math分别引用了数值Infinity、预定义的函数parseInt()和预定义的对象Math。<br>&nbsp;&nbsp;&nbsp;&nbsp; 在程序的顶层代码中（例如，不属于函数的js代码），你可以使用js的关键字this来引用这个全局对象。在函数内部，this则有别的用途。<br>&nbsp;&nbsp;&nbsp;&nbsp; 在客户端js中，window对象代表游览窗口，它是包含在该窗口中的所有js代码的全局对象。这个全局window对象具有自我引用的window属性，它代替了this属性，可以用来引用这个全局对象。window对象定义了全局的核心属性，如parseInt和Math，此外它还定义了全局的客户端属性，如navigator和screen.<br>&nbsp;&nbsp;&nbsp;&nbsp; 如果全局变量时特殊的全局对象的属性，那么局部变量又是什么呢？它们也是一个对象的属性，这个对象被称为调用对象（call object）。虽然调用对象的生命周期比全局对象短，但是它们的用途是相同的。在执行一个函数时，函数的参数和局部变量是作为调用对象的属性而存储的。用一个完全独立的对象来存储局部变量使js可以防止局部变量覆盖同名的全局变量的值。<br>&nbsp;&nbsp;&nbsp;&nbsp; js的解释器每次开始执行一个函数时，都会为那个函数创建一个执行环境（execution context）。显然，一个执行环境就是所有js代码段执行时所在环境。这个环境的一个重要部分是定义变量的对象。因此，运行不属于任何函数的js代码的环境使用的是全局对象。所有js函数都运行在自己独有的执行环境中，而且具有自己的调用对象，在调用对象中定义了局部变量。<br>&nbsp;&nbsp;&nbsp; 要注意一个有趣的地方，js的实现允许有多个全局执行环境，每个执行环境有不同的全局对象（但是，在这种情况下，每个全局对象就不完全是全局了）。一个显而易见的例子是，客户端js的每个独立的游览窗口或同一窗口的不同框架中都定义了独立的全局执行环境。每个框架或窗口中的客户端js代码都运行在自己的执行环境中，具有自己的全局对象。但是，这些独立的客户端全局对象具有将与其他对象彼此连接起来的属性。因此，一个框架中js代码可以使用表示式parent.frames[1]来引用另一个框架中的js代码，在第2个框架中的代码可以使用表达式parent.frames[0].x来引用第一个框架中的全局变量x。一个js解释器可以在不同的全局执行环境运行脚本，而且这些环境之间并不完全脱节的，它们彼此可以相互引用。<br>&nbsp;&nbsp;&nbsp; 最后一点需要额外说明一下。如果一个执行环境中的js代码可以读写另一个执行环境中定义的属性，并且执行它的函数，那么复杂度就上升了一层，我们需要考虑安全性的问题了。以客户端js为例。假设游览窗口a正在运行一个脚本或者它含有来自局域网的信息，而窗口b则正在运行来自inernet的某个站点的脚本。一般来说，我们不希望窗口b中的代码能访问a的属性。如果允许这样做，那么它可能就读取公司的机密信息并窃取这些信息。所以，为了安全地运行js代码，必须有一定的安全机制。当从一个执行环境访问另一个执行环境时，如果这种访问是不允许的，那么就禁止执行它。<br>&nbsp;&nbsp;&nbsp; 全局变量具有全局的作用域，而函数zhog声明的变量具有局部的作用域。如果一个函数定义嵌套在另一个函数中，那么在嵌套的函数中声明的变量具有嵌套的局部作用域。既然我们知道全局变量是全局对象的属性，而局部变量是一个特殊的调用对象的属性，那么我们可以再次关注一下变量作用域的表示法，对于它进行再定义。有关作用域的新描述给理解多环境下的变量提供了一种有用的方法，它为js的工作过程提供了一种强大的、新的理解。<br>&nbsp;&nbsp;&nbsp; 每个js执行环境都有一个和它关联在一起的作用域链（scope chain）。这个作用域链式一个对象列表或对象链。当js代码需要查询变量x的值时（一个称为变量名解析variable name resolution的过程），它就开始查看该链的第一个对象。如果那个对象有一个名为x的属性，那么就采用那个属性的值。如果第一个对象没有名为x的属性，js就会继续查询链中的第2个对象。如果第2个对象仍然没有名为x的属性那么就继续查询下一个对象，直到到达全局对象为止。<br>&nbsp;&nbsp;&nbsp;&nbsp; 在js的顶层代码中（例如，不属于任何函数定义的代码），作用域链只由一个对象构成，那就是全局对象。所有变量都是在这个对象中查询。如果一个变量并不存在，那么这个变量的值就是为定义。在一个（非嵌套的）函数中，作用域链由两个对象构成，第一个是函数的调用对象，第二个就是全局对象。当函数引用一个变量时，首先检查的是调用对象（局部作用域），其次才检查全局对象（全局作用域）。在一个嵌套函数的作用域链中可以有三个或更多的对象。<br>
<img src ="http://www.cnitblog.com/asfman/aggbug/41383.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2008-03-24 09:23 <a href="http://www.cnitblog.com/asfman/articles/41383.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一切都是对象的属性</title><link>http://www.cnitblog.com/asfman/articles/41342.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Sat, 22 Mar 2008 08:05:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/41342.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/41342.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/41342.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/41342.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/41342.html</trackback:ping><description><![CDATA[&nbsp;&nbsp; 如果全局变量是特殊的全局对象的属性，那么局部变量又是什么呢？它们也是一个对象的属性，这个对象被称为调用对象(call object)。虽然调用对象的生命周期比全局对象短，但是它们的用途是相同的。在执行一个函数时，函数的参数和局部变量是作为调用对象的属性而存储的。用一个完全独立的对象来存储局部变量使javascript可以防止局部变量覆盖同名的全局变量的值。
<img src ="http://www.cnitblog.com/asfman/aggbug/41342.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2008-03-22 16:05 <a href="http://www.cnitblog.com/asfman/articles/41342.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>save pic</title><link>http://www.cnitblog.com/asfman/articles/40876.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Thu, 13 Mar 2008 05:11:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/40876.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/40876.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/40876.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/40876.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/40876.html</trackback:ping><description><![CDATA[&lt;script&gt;<br>function savePic(url,sAddress,name)<br>{<br>&nbsp;&nbsp;&nbsp; var suffix = url.match(/\.[^.]*$/)[0];<br>&nbsp;&nbsp;&nbsp; var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");<br>&nbsp;&nbsp;&nbsp; xmlhttp.open("get",url,false);<br>&nbsp;&nbsp;&nbsp; xmlhttp.send();<br>&nbsp;&nbsp;&nbsp; var oS = new ActiveXObject("ADODB.Stream");<br>&nbsp;&nbsp;&nbsp; oS.Type = 1;<br>&nbsp;&nbsp;&nbsp; oS.Mode = 3;<br>&nbsp;&nbsp;&nbsp; oS.Open();<br>&nbsp;&nbsp;&nbsp; oS.Write(xmlhttp.responseBody);<br>&nbsp;&nbsp;&nbsp; oS.SaveToFile(sAddress+name+suffix);<br>&nbsp;&nbsp;&nbsp; oS.Close();<br>}<br>savePic("<a href="http://www.haokan.cc/images/uploadimg/20083412271113475.jpg">http://www.haokan.cc/images/uploadimg/20083412271113475.jpg</a>", "c:\\","test"); <br>&lt;/script&gt;<br>
<img src ="http://www.cnitblog.com/asfman/aggbug/40876.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2008-03-13 13:11 <a href="http://www.cnitblog.com/asfman/articles/40876.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于Javascript的内存泄漏问题的整理稿</title><link>http://www.cnitblog.com/asfman/articles/39727.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Wed, 13 Feb 2008 15:52:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/39727.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/39727.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/39727.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/39727.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/39727.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 关于Javascript的内存泄漏问题的整理稿常规循环引用内存泄漏和Closure内存泄漏 要了解javascript的内存泄漏问题，首先要了解的就是javascript的GC原理。我记得原来在犀牛书《JavaScript: The Definitive Guide》中看到过，IE使用的GC算法是计数器，因此只碰到循环 引用就会造成memory leakage。后来一直觉得和观...&nbsp;&nbsp;<a href='http://www.cnitblog.com/asfman/articles/39727.html'>阅读全文</a><img src ="http://www.cnitblog.com/asfman/aggbug/39727.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2008-02-13 23:52 <a href="http://www.cnitblog.com/asfman/articles/39727.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>concat</title><link>http://www.cnitblog.com/asfman/articles/38819.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Sun, 13 Jan 2008 15:46:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/38819.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/38819.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/38819.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/38819.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/38819.html</trackback:ping><description><![CDATA[Function.prototype.concat = function()<br>{<br>&nbsp;&nbsp;&nbsp; var funcs = [this].concat(Array.apply([], arguments));<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; return function(){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var ret = [];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(var i = 0; i &lt; funcs.length; i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var func = funcs[i] instanceof Function ? funcs[i] : new Function(funcs[i]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret.push(func.apply(this, arguments));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ret;<br>&nbsp;&nbsp;&nbsp; }<br>} 
<img src ="http://www.cnitblog.com/asfman/aggbug/38819.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2008-01-13 23:46 <a href="http://www.cnitblog.com/asfman/articles/38819.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>FunctionExpression FunctionDecration</title><link>http://www.cnitblog.com/asfman/articles/38269.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Sun, 30 Dec 2007 00:23:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/38269.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/38269.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/38269.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/38269.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/38269.html</trackback:ping><description><![CDATA[&lt;script&gt;<br>(function f(){alert(1)})(f=function(){alert(2)});<br>f(f=function(){alert(3)});<br>(f,f)(f=function(){alert(4)});<br>&lt;/script&gt;<br>function表达式的函数名 其实是在此function内和外之间加了一节scope chain 函数名是在其上的<br>所以函数表达式和函数声明的__parent__才会不同<br><br>在函数自己的域上 除了eval的所有var声明都是在开始执行函数内容之前做的 而一个变量声明多少次都是一样的 所以 参数和var作用是一样的 没有先后之分<br>eval var直道执行时才声明 它也不会覆盖任何东西 因为重复声明和一次声明是一样的 但它的作用范围只在它执行之后<br><br>&lt;script&gt;<br>var test=function test(n){<br>&nbsp;&nbsp;&nbsp; return n&lt;1?1:test(n-1)*n;<br>}<br>var test2=test;<br>test=null;<br>alert(test2(3));//ie wrong,ff result 6<br>&lt;/script&gt;<br><br><br>&lt;script&gt;<br>function test(n){<br>&nbsp;&nbsp;&nbsp; return n&lt;1?1:test(n-1)*n;<br>}<br>var test2=test;<br>test=null;<br>alert(test2(3));//ff ie both wrong<br>&lt;/script&gt;
<img src ="http://www.cnitblog.com/asfman/aggbug/38269.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-12-30 08:23 <a href="http://www.cnitblog.com/asfman/articles/38269.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>scop chains</title><link>http://www.cnitblog.com/asfman/articles/37726.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Sat, 15 Dec 2007 05:35:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/37726.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/37726.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/37726.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/37726.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/37726.html</trackback:ping><description><![CDATA[<h1>Scope in JavaScript</h1>
<div id=comment_invite_top><strong>Got something to say?</strong>
<p><a href="http://www.digital-web.com/articles/scope_in_javascript/comments/"><u><font color=#0000ff>Share your comments</font></u></a> on this topic with other web professionals</p>
</div>
<p class=location>In: <a href="http://www.digital-web.com/types/articles/"><u><font color=#0000ff>Articles</font></u></a></p>
<p class=author>By <a href="http://www.digital-web.com/about/contributors/mike_west"><u><font color=#0000ff>Mike West</font></u></a></p>
<p class=date>Published on September 11, 2006</p>
<p><a href="http://en.wikipedia.org/wiki/Scope_%28programming%29"><u><font color=#0000ff>Scope</font></u></a> is one of the foundational aspects of the JavaScript language, and probably the one I&#8217;ve struggled with the most when building complex programs. I can&#8217;t count the number of times I&#8217;ve lost track of what the <code>this</code> keyword refers to after passing control around from function to function, and I&#8217;ve often found myself contorting my code in all sorts of confusing ways, trying to retain some semblance of sanity in my understanding of which variables were accessible where.</p>
<blockquote class=pullquote>
<p class=pullquote><span class=pullquote>In typical object-oriented programming, we need a way of identifying and referring to the object that we&#8217;re currently working with. <code>this</code> serves the purpose admirably, providing our objects the ability to examine themselves, and point at their own properties.</span></p>
</blockquote>
<p>This article will tackle the problem head-on, outlining definitions of context and scope, examining two JavaScript methods that allow us to manipulate context, and concluding with a deep dive into an <em>effective</em> solution to ninety percent of the problems I&#8217;ve run into.</p>
<h3>Where Am I? And Who Are You?</h3>
<p>Every bit of your JavaScript program is executed in one <strong>execution context</strong> or another. You can think of these contexts as your code&#8217;s neighborhood, giving each line an understanding of where it comes from, and who its friends and neighbors are. As it turns out, this is important information, as JavaScript societies have fairly strict rules about who can associate with whom; execution contexts are better thought of as gated communities than as open subdivisions.</p>
<p>We can refer to these social boundaries generally as <strong>scope</strong>, and they&#8217;re important enough to be codified in each neighborhood&#8217;s charter, which we&#8217;ll refer to as the context&#8217;s <strong>scope chain</strong>. Code within a particular neighborhood can only access variables listed on its scope chain, and prefers interaction with locals to associations outside its neighborhood.</p>
<p>Practically speaking, evaluating a function establishes a distinct execution context that appends its local scope to the scope chain it was defined within. JavaScript resolves identifiers within a particular context by climbing up the scope chain, moving locally to globally. This means that local variables with the same name as variables higher up on the scope chain take precedence, which makes sense: If my good friends are talking together about &#8220;Mike West,&#8221; it&#8217;s pretty clear that they&#8217;re talking about <em>me</em>, not about the <a href="http://www.mikewest.net/" rel=nofollow><u><font color=#0000ff>bluegrass singer</font></u></a> or the <a href="http://www.isds.duke.edu/~mw/" rel=nofollow><u><font color=#0000ff>Duke professor</font></u></a>, even though the latter two are (arguably) better known.</p>
<p>Let&#8217;s walk through some example code to explore the implications:</p>
<p><code>&lt;script type="text/javascript"&gt; <br>&nbsp;var ima_celebrity = "Everyone can see me! I'm famous!", <br>&nbsp;&nbsp;the_president = "I'm the decider!"; <br>&nbsp; <br>&nbsp;function pleasantville() { <br>&nbsp;&nbsp;var the_mayor = "I rule Pleasantville with an iron fist!", <br>&nbsp;&nbsp;&nbsp;ima_celebrity = "All my neighbors know who I am!"; <br>&nbsp; <br>&nbsp;&nbsp;function lonely_house() { <br>&nbsp;&nbsp;&nbsp;var agoraphobic = "I fear the day star!", <br>&nbsp;&nbsp;&nbsp;&nbsp;a_cat = "Meow."; <br>&nbsp;&nbsp;} <br>&nbsp;} <br>&lt;/script&gt; </code></p>
<p>Our global star, <code>ima_celebrity</code>, is recognized by everyone. She&#8217;s politically active, talking with <code>the_president</code> on a fairly frequent basis, and incredibly friendly; she&#8217;ll sign autographs and answer questions for anyone she runs into. That said, she doesn&#8217;t have a whole lot of personal contact with her fans. She&#8217;s pretty sure they <em>exist</em> and that they probably have lives of their own somewhere, but she certainly doesn&#8217;t know what they&#8217;re doing, or even their names.</p>
<p>Inside <code>pleasantville</code>, <code>the_mayor</code> is a well-known face. She&#8217;s always walking the streets of her town, chatting up her constituents, shaking hands, and kissing babies. As <code>pleasantville</code> is a big, important neighborhood, she&#8217;s got a big red phone in her office, giving her a direct line to the president (or at least a top aide) 24 hours a day, 7 days a week. She&#8217;s seen <code>lonely_house</code> up on a hill at the outskirts of town, but never really worried about who lives inside.</p>
<p>That <code>lonely_house</code> is a world unto itself. The <code>agoraphobic</code> stays inside most of the time, playing solitaire and feeding <code>a_cat</code>. He&#8217;s called <code>the_mayor</code> a few times to ask about local noise regulations, and even wrote <code>ima_celebrity</code> (Pleasantville&#8217;s <code>ima_celebrity</code>, that is) some fan mail after seeing her on the local news.</p>
<h3><code>this</code>? What&#8217;s that?</h3>
<p>In addition to establishing a scope chain, each execution context offers a keyword named <code>this</code>. In its most common usage, <code>this</code> serves as an identity function, providing our neighborhoods a way of referring to themselves. We can&#8217;t always rely on that behavior, however: Depending on how we get into a particular neighborhood, <code>this</code> might mean something else entirely. In fact, <em>how we get into the neighborhood</em> is itself exactly what <code>this</code> generally refers to. Four scenarios deserve special attention:</p>
<ul>
    <li><strong>Calling an Object&#8217;s Method</strong>
    <p><span class=pullquote>In typical object-oriented programming, we need a way of identifying and referring to the object that we&#8217;re currently working with. <code>this</code> serves the purpose admirably, providing our objects the ability to examine themselves, and point at their own properties.</span></p>
    <p><code>&nbsp;&lt;script type="text/javascript"&gt; <br>&nbsp;&nbsp;var deep_thought = { <br>&nbsp;&nbsp;&nbsp;the_answer: 42, <br>&nbsp;&nbsp;&nbsp;ask_question: function () { <br>&nbsp;&nbsp;&nbsp;&nbsp;return this.the_answer; <br>&nbsp;&nbsp;&nbsp;} <br>&nbsp;&nbsp;}; <br>&nbsp; <br>&nbsp;&nbsp;var the_meaning = deep_thought.ask_question(); <br>&nbsp;&lt;/script&gt; </code></p>
    <p>This example builds an object named <code>deep_thought</code>, sets its <code>the_answer</code> property to 42, and creates an <code>ask_question</code> method. When <code>deep_thought.ask_question()</code> is executed, JavaScript establishes an execution context for the function call, setting <code>this</code> to the object referenced by whatever came before the last &#8221;.&#8221;, in this case: <code>deep_thought</code>. The method can then look in the mirror via <code>this</code> to examine its own properties, returning the value stored in <code>this.the_answer</code>: 42.</p>
    <li><strong>Constructor</strong>
    <p>Likewise, when defining a function to be used as a constructor with the <code>new</code> keyword, <code>this</code> can be used to refer to the object being created. Let&#8217;s rewrite the example above to reflect that scenario:</p>
    <p><code>&nbsp;&lt;script type="text/javascript"&gt; <br>&nbsp;&nbsp;function BigComputer(answer) { <br>&nbsp;&nbsp;&nbsp;this.the_answer = answer; <br>&nbsp;&nbsp;&nbsp;this.ask_question = function () { <br>&nbsp;&nbsp;&nbsp;&nbsp;return this.the_answer; <br>&nbsp;&nbsp;&nbsp;} <br>&nbsp;&nbsp;} <br>&nbsp; <br>&nbsp;&nbsp;var deep_thought = new BigComputer(42); <br>&nbsp;&nbsp;var the_meaning = deep_thought.ask_question(); <br>&nbsp;&lt;/script&gt; </code></p>
    <p>Instead of explicitly creating the <code>deep_thought</code> object, we&#8217;ll write a function to create <code>BigComputer</code> objects, and <em>instantiate</em> <code>deep_thought</code> as an instance variable via the <code>new</code> keyword. When <code>new BigComputer()</code> is executed, a completely new object is created transparently in the background. <code>BigComputer</code> is called, and its <code>this</code> keyword is set to reference that new object. The function can set properties and methods on <code>this</code>, which is transparently returned at the end of <code>BigComputer</code>&#8217;s execution.</p>
    <p>Notice, though, that <code>deep_thought.the_question()</code> still works just as it did before. What&#8217;s going on there? Why does <code>this</code> mean something different inside <code>the_question</code> than it does inside <code>BigComputer</code>? Put simply, we <em>entered</em> <code>BigComputer</code> via <code>new</code>, so <code>this</code> meant &#8220;the new object.&#8221; On the other hand, we <em>entered</em> <code>the_question</code> via <code>deep_thought</code>, so while we&#8217;re executing that method, <code>this</code> means &#8220;whatever <code>deep_thought</code> refers to&#8221;. <code>this</code> is not read from the scope chain as other variables are, but instead is <em>reset</em> on a context by context basis.</p>
    <li><strong>Function Call</strong>
    <p>What if we just call a normal, everyday function without any of this fancy object stuff? What does <code>this</code> mean in that scenario?</p>
    <p><code>&nbsp;&lt;script type="text/javascript"&gt; <br>&nbsp;&nbsp;function test_this() { <br>&nbsp;&nbsp;&nbsp;return this; <br>&nbsp;&nbsp;} <br>&nbsp;&nbsp;var i_wonder_what_this_is = test_this(); <br>&nbsp;&lt;/script&gt; </code></p>
    <p>In this case, we weren&#8217;t provided a context by <code>new</code>, nor were we given a context in the form of an object to piggyback off of. Here, <code>this</code> defaults to reference the most global thing it can: for web pages, this is the <code>window</code> object.</p>
    <li><strong>Event Handler</strong>
    <p>For a more complicated twist on the normal function call, let&#8217;s say that we&#8217;re using a function to handle an <code>onclick</code> event. What does <code>this</code> mean when the event triggers our function&#8217;s execution? Unfortunately, there&#8217;s not a simple answer to this question.</p>
    <p>If we write the event handler inline, <code>this</code> refers to the global <code>window</code> object:</p>
    <p><code>&nbsp;&lt;script type="text/javascript"&gt; <br>&nbsp;&nbsp;function click_handler() { <br>&nbsp;&nbsp;&nbsp;alert(this); // alerts the window object <br>&nbsp;&nbsp;} <br>&nbsp;&lt;/script&gt; <br>&nbsp;... <br>&nbsp;&lt;button id='thebutton' onclick='click_handler()'&gt;Click me!&lt;/button&gt; </code></p>
    <p>However, when we add an event handler via JavaScript, <code>this</code> refers to the DOM element that generated the event. (Note: The event handling shown here is short and readable, but otherwise poor. Please use a <a href="http://dean.edwards.name/weblog/2005/10/add-event2/"><u><font color=#0000ff>real addEvent function</font></u></a> instead.):</p>
    <p><code>&nbsp;&lt;script type="text/javascript"&gt; <br>&nbsp;&nbsp;function click_handler() { <br>&nbsp;&nbsp;&nbsp;alert(this); // alerts the button DOM node <br>&nbsp;&nbsp;} <br>&nbsp; <br>&nbsp;&nbsp;function addhandler() { <br>&nbsp;&nbsp;&nbsp;document.getElementById('thebutton').onclick = click_handler; <br>&nbsp;&nbsp;} <br>&nbsp; <br>&nbsp;&nbsp;window.onload = addhandler; <br>&nbsp;&lt;/script&gt; <br>&nbsp;... <br>&nbsp;&lt;button id='thebutton'&gt;Click me!&lt;/button&gt; </code></p>
    </li>
</ul>
<h3>Complications</h3>
<p>Let&#8217;s run with that last example for a moment longer. What if instead of running <code>click_handler</code>, we wanted to ask <code>deep_thought</code> a question every time we clicked the button? The code for that seems pretty straightforward; we might try this:</p>
<p><code>&lt;script type="text/javascript"&gt; <br>&nbsp;function BigComputer(answer) { <br>&nbsp;&nbsp;this.the_answer = answer; <br>&nbsp;&nbsp;this.ask_question = function () { <br>&nbsp;&nbsp;&nbsp;alert(this.the_answer); <br>&nbsp;&nbsp;} <br>&nbsp;} <br>&nbsp; <br>&nbsp;function addhandler() { <br>&nbsp;&nbsp;var deep_thought = new BigComputer(42), <br>&nbsp;&nbsp;&nbsp;the_button = document.getElementById('thebutton'); <br>&nbsp; <br>&nbsp;&nbsp;the_button.onclick = deep_thought.ask_question; <br>&nbsp;} <br>&nbsp; <br>&nbsp;window.onload = addhandler; <br>&lt;/script&gt; </code></p>
<p>Perfect, right? We click on the button, <code>deep_thought.ask_question</code> is executed, and we get back &#8220;42.&#8221; So why is the browser giving us <code>undefined</code> instead? What did we do wrong?</p>
<p>The problem is simply this: We&#8217;ve passed off a reference to the <code>ask_question</code> method, which, when executed as an event handler, runs in a different context than when it&#8217;s executed as an object method. In short, the <code>this</code> keyword in <code>ask_question</code> is pointing at the DOM element that generated the event, not at a <code>BigComputer</code> object. The DOM element doesn&#8217;t have a <code>the_answer</code> property, so we&#8217;re getting back <code>undefined</code> instead of &#8220;42.&#8221; <code>setTimeout</code> exhibits similar behavior, delaying the execution of a function while at the same time moving it out into a global context.</p>
<p>This issue crops up all over the place in our programs, and it&#8217;s a terribly difficult problem to debug without keeping careful track of what&#8217;s going on in all the corners of your program, especially if your object has properties that <em>do</em> exist on DOM elements or the <code>window</code> object.</p>
<h3>Manipulating Context With <code>.apply()</code> and <code>.call()</code></h3>
<p>We really <em>do</em> want to be able to ask <code>deep_thought</code> a question when we click the button, and more generally, we <em>do</em> want to be able to call object methods in their native context when responding to things like events and <code>setTimeout</code> calls. Two little-known JavaScript methods, <code>apply</code> and <code>call</code>, indirectly enable this functionality by allowing us to manually override the default value of <code>this</code> when we execute a function call. Let&#8217;s look at <code>call</code> first:</p>
<p><code>&lt;script type="text/javascript"&gt; <br>&nbsp;var first_object = { <br>&nbsp;&nbsp;num: 42 <br>&nbsp;}; <br>&nbsp;var second_object = { <br>&nbsp;&nbsp;num: 24 <br>&nbsp;}; <br>&nbsp; <br>&nbsp;function multiply(mult) { <br>&nbsp;&nbsp;return this.num * mult; <br>&nbsp;} <br>&nbsp; <br>&nbsp;multiply.call(first_object, 5); // returns 42 * 5 <br>&nbsp;multiply.call(second_object, 5); // returns 24 * 5 <br>&lt;/script&gt; </code></p>
<p>In this example, we first define two objects, <code>first_object</code> and <code>second_object</code>, each with a <code>num</code> property. Then we define a <code>multiply</code> function that accepts a single argument, and returns the product of that argument, and the <code>num</code> property of its <code>this</code> object. If we called that function by itself, the answer returned would almost certainly be <code>undefined</code>, since the global <code>window</code> object doesn&#8217;t have a <code>num</code> property unless we explicitly set one. We need some way of telling <code>multiply</code> what its <code>this</code> keyword ought refer to; the <code>call</code> method of the <code>multiply</code> function is exactly what we&#8217;re looking for.</p>
<p>The first argument to <code>call</code> defines what <code>this</code> means inside the executed function. The remaining arguments to <code>call</code> are passed into the executed function, just as if you&#8217;d called it yourself. So, when <code>multiply.call(first_object, 5)</code> is executed, the <code>multiply</code> function is called, <code>5</code> is passed in as the first argument, and the <code>this</code> keyword is set to refer to object <code>first_object</code>. Likewise, when <code>multiply.call(second_object, 5)</code> is executed, the <code>multiply</code> function is called, <code>5</code> is passed in as the first argument, and the <code>this</code> keyword is set to refer to object <code>second_object</code>.</p>
<p><code>apply</code> works in exactly the same way as <code>call</code>, but allows you to wrap up the arguments to the called function in an array, which can be quite useful when programatically generating function calls. Replicating the functionality we just talked about using <code>apply</code> is trivial:</p>
<p><code>&lt;script type="text/javascript"&gt; <br>&nbsp;... <br>&nbsp; <br>&nbsp;multiply.apply(first_object, [5]); // returns 42 * 5 <br>&nbsp;multiply.apply(second_object, [5]); // returns 24 * 5 <br>&lt;/script&gt; </code></p>
<p><code>apply</code> and <code>call</code> are very useful on their own, and well worth keeping around in your toolkit, but they only get us halfway to solving the problem of context shifts for event handlers. It&#8217;s easy to think that we could solve the problem by simply using <code>call</code> to shift the meaning of <code>this</code> when we set up the handler:</p>
<p><code>function addhandler() { <br>&nbsp;var deep_thought = new BigComputer(42), <br>&nbsp;&nbsp;the_button = document.getElementById('thebutton'); <br>&nbsp; <br>&nbsp;the_button.onclick = deep_thought.ask_question.call(deep_thought); <br>} </code></p>
<p>The problem with this line of reasoning is simple: <code>call</code> executes the function <em>immediately</em>. Instead of providing a function reference to the <code>onclick</code> handler, we&#8217;re giving it <em>the result</em> of an executed function. We need to exploit another feature of JavaScript to really solve this problem.</p>
<h3>The Beauty of <code>.bind()</code></h3>
<p>I&#8217;m not a <em>huge</em> fan of the <a href="http://prototype.conio.net/"><u><font color=#0000ff>Prototype JavaScript framework</font></u></a>, but I am very much impressed with the quality of its code as a whole. In particular, one simple addition it makes to the <code>Function</code> object has had a hugely positive impact on my ability to manage the context in which function calls execute: <code>bind</code> performs the same general task as <code>call</code>, altering the context in which a function executes. The difference is that <code>bind</code> returns a function reference that can be used later, rather than the result of an immediate execution that we get with <code>call</code>.</p>
<p>If we simplify the <code>bind</code> function a bit to get at the key concepts, we can insert it into the multiplication example we discussed earlier to really dig into how it works; it&#8217;s quite an elegant solution:</p>
<p><code>&lt;script type="text/javascript"&gt; <br>&nbsp;var first_object = { <br>&nbsp;&nbsp;num: 42 <br>&nbsp;}; <br>&nbsp;var second_object = { <br>&nbsp;&nbsp;num: 24 <br>&nbsp;}; <br>&nbsp; <br>&nbsp;function multiply(mult) { <br>&nbsp;&nbsp;return this.num * mult; <br>&nbsp;} <br>&nbsp; <br>&nbsp;Function.prototype.bind = function(obj) { <br>&nbsp;&nbsp;var method = this, <br>&nbsp;&nbsp;&nbsp;temp = function() { <br>&nbsp;&nbsp;&nbsp;&nbsp;return method.apply(obj, arguments); <br>&nbsp;&nbsp;&nbsp;}; <br>&nbsp; <br>&nbsp;&nbsp;return temp; <br>&nbsp;} <br>&nbsp; <br>&nbsp;var first_multiply = multiply.bind(first_object); <br>&nbsp;first_multiply(5); // returns 42 * 5 <br>&nbsp; <br>&nbsp;var second_multiply = multiply.bind(second_object); <br>&nbsp;second_multiply(5); // returns 24 * 5 <br>&lt;/script&gt; </code></p>
<p>First, we define <code>first_object</code>, <code>second_object</code>, and the <code>multiply</code> function, just as before. With those taken care of, we move on to creating a <code>bind</code> method on the <code>Function</code> object&#8217;s <a href="http://en.wikipedia.org/wiki/Prototype-based_programming"><code><u><font color=#0000ff>prototype</font></u></code></a>, which has the effect of making <code>bind</code> available for all functions in our program. When <code>multiply.bind(first_object)</code> is called, JavaScript creates an execution context for the <code>bind</code> method, setting <code>this</code> to the <code>multiply</code> function, and setting the first argument, <code>obj</code>, to reference <code>first_object</code>. So far, so good.</p>
<p>The real genius of this solution is the creation of <code>method</code>, set equal to <code>this</code> (the <code>multiply</code> function itself). When the anonymous function is created on the next line, <code>method</code> is accessible via its scope chain, as is <code>obj</code> (<code>this</code> couldn&#8217;t be used here, because when the newly created function is executed, <code>this</code> will be overwritten by a new, local context). This alias to <code>this</code> makes it possible to use <code>apply</code> to execute the <code>multiply</code> function, passing in <code>obj</code> to ensure that the context is set correctly. In computer-science-speak, <code>temp</code> is a <a href="http://www.jibbering.com/faq/faq_notes/closures.html"><cite><u><font color=#0000ff>closure</font></u></cite></a> that, when returned at the end of the <code>bind</code> call, can be used in any context whatsoever to execute <code>multiply</code> in the context of <code>first_object</code>.</p>
<p>This is exactly what we need for the event handler and <code>setTimeout</code> scenarios discussed above. The following code solves that problem completely, binding the <code>deep_thought.ask_question</code> method to the <code>deep_thought</code> context, so that it executes correctly whenever the event is triggered:</p>
<p><code>function addhandler() { <br>&nbsp;var deep_thought = new BigComputer(42), <br>&nbsp;&nbsp;the_button = document.getElementById('thebutton'); <br>&nbsp; <br>&nbsp;the_button.onclick = deep_thought.ask_question.bind(deep_thought); <br>} </code></p>
<p>Beautiful.</p>
<h3>References</h3>
<ul>
    <li><a href="http://www.jibbering.com/faq/faq_notes/closures.html"><u><font color=#0000ff>JavaScript Closures</font></u></a> is the best resource on the net for a thorough discussion of closures: what they do, how they do it, and how to use them without going insane.
    <li>The <a href="http://prototype.conio.net/"><u><font color=#0000ff>Protype JavaScript Framework</font></u></a> is full of little nuggets like <code>bind</code>. The version available here not only allows the binding of a particular <code>this</code> value, but also of some or all of a function&#8217;s arguments, which comes in handy all too often.
    <li><a href="http://javascript.crockford.com/"><u><font color=#0000ff>Douglas Crockford&#8217;s JavaScript essays</font></u></a> are excellent resources for both basic and advanced JavaScript programmers. The man knows what he&#8217;s talking about, and explains difficult concepts in an easy-to-grasp manner.
    <li><a href="http://digital-web.com/articles/variable_scope_for_new_programmers/"><u><font color=#0000ff>Variable Scope for New Programmers</font></u></a> is a good article if you'd like more discussion of scope from a beginner's perspective. Written by <a href="http://snook.ca/"><u><font color=#0000ff>Jonathan Snook</font></u></a>, and published in this very magazine at the end of last year, it's still an informative and useful read. </li>
</ul>
<img src ="http://www.cnitblog.com/asfman/aggbug/37726.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-12-15 13:35 <a href="http://www.cnitblog.com/asfman/articles/37726.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于泄漏</title><link>http://www.cnitblog.com/asfman/articles/37683.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Fri, 14 Dec 2007 00:54:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/37683.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/37683.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/37683.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/37683.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/37683.html</trackback:ping><description><![CDATA[<p>经ie7测试 <br>function myButton()<br>{<br>&nbsp;&nbsp;&nbsp; var container=document.createElement("button");<br>&nbsp;&nbsp;&nbsp; /*container.style......*/<br>&nbsp;&nbsp;&nbsp; var text=document.createElement("button");<br>&nbsp;&nbsp;&nbsp; /*text.style......text.innerText......*/</p>
<p>&nbsp;&nbsp;&nbsp; text.onclick=EventBuilder(container);<br>&nbsp;&nbsp;&nbsp; //在这里无论是上面这种写法还是直接写function(){}结果占用内存都一样<br>&nbsp;&nbsp;&nbsp; //只有直接引用外部函数如text.onclick=EventBuilder才能释放button对象,减少内存<br>&nbsp;&nbsp;&nbsp; document.body.appendChild(container);<br>&nbsp;&nbsp;&nbsp; document.body.appendChild(text);<br>&nbsp;&nbsp;&nbsp; //如果onmouseover中我没有用到container 当然可以用 text=null container=null来打破循环引用<br>&nbsp;&nbsp;&nbsp; //经测试用null打不破循环<br>} </p>
<p>function EventBuilder(container)<br>{<br>&nbsp;&nbsp;&nbsp; return function(e)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(container)//这里container可访问<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; text=this;//用this访问自身<br>&nbsp;&nbsp;&nbsp; }<br>} <br>for(var i =0;i&lt;5000;i++)<br>myButton()<br>//conclusion<br>闭包使返回的内部函数持有私有变量，所以此私有变量持有的dom对象不能被回收。<br>（被回收的条件：1。 没有context 2。没有被引用 ）<br>不内部写function。把内部变量传递给外部函数闭包返回不能解决问题。<br>所以唯一的方法是直接引用外部函数，如text.onclick = outFunc;</p>
<img src ="http://www.cnitblog.com/asfman/aggbug/37683.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-12-14 08:54 <a href="http://www.cnitblog.com/asfman/articles/37683.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于打印设置</title><link>http://www.cnitblog.com/asfman/articles/36852.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Sat, 24 Nov 2007 15:49:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/36852.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/36852.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/36852.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/36852.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/36852.html</trackback:ping><description><![CDATA[<p>&lt;!--语言无关 保存成 .HTML 看看--&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>&lt;meta name=vs_targetSchema content="<a href="http://schemas.microsoft.com/intellisense/ie5">http://schemas.microsoft.com/intellisense/ie5</a>"&gt; <br>&lt;title&gt;完美的Web打印&lt;/title&gt;<br>&lt;meta http-equiv="Content-Type" content="text/html; charset=gb2312"&gt;<br>&lt;!--media=print 这个属性可以在打印时有效--&gt;<br>&lt;style media=print&gt;<br>.Noprint{display:none;}<br>.PageNext{page-break-after: always;}<br>&lt;/style&gt;</p>
<p>&lt;style&gt;<br>.tdp<br>{<br>&nbsp;&nbsp;&nbsp; border-bottom: 1 solid #000000;<br>&nbsp;&nbsp;&nbsp; border-left: ? solid #000000;<br>&nbsp;&nbsp;&nbsp; border-right: ? solid #ffffff;<br>&nbsp;&nbsp;&nbsp; border-top: 0 solid #ffffff;<br>}<br>.tabp<br>{<br>&nbsp;&nbsp;&nbsp; border-color: #000000 #000000 #000000 #000000;<br>&nbsp;&nbsp;&nbsp; border-style: solid;<br>&nbsp;&nbsp;&nbsp; border-top-width: 2px;<br>&nbsp;&nbsp;&nbsp; border-right-width: 2px;<br>&nbsp;&nbsp;&nbsp; border-bottom-width: 1px;<br>&nbsp;&nbsp;&nbsp; border-left-width: 1px;<br>}<br>.NOPRINT {<br>&nbsp;font-family: "宋体";<br>&nbsp;font-size: 9pt;<br>}</p>
<p>&lt;/style&gt;</p>
<p>&lt;/head&gt;</p>
<p>&lt;body &gt;<br>&lt;center class="Noprint" &gt;<br>&nbsp; &lt;p&gt;<br>&nbsp; &lt;OBJECT&nbsp; id=WebBrowser&nbsp; classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2&nbsp; height=0&nbsp; width=0&gt;<br>&nbsp; &lt;/OBJECT&gt;<br>&nbsp; &lt;input&nbsp; type=button&nbsp; value=打印&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; onclick=document.all.WebBrowser.ExecWB(6,1)&gt;<br>&nbsp; &lt;input&nbsp; type=button&nbsp; value=直接打印&nbsp; onclick=document.all.WebBrowser.ExecWB(6,6)&gt;<br>&nbsp; &lt;input&nbsp; type=button&nbsp; value=页面设置&nbsp; onclick=document.all.WebBrowser.ExecWB(8,1)&gt;<br>&lt;/p&gt;<br>&nbsp; &lt;p&gt;&nbsp;&nbsp;&nbsp; &lt;input&nbsp; type=button&nbsp; value=打印预览&nbsp; onclick=document.all.WebBrowser.ExecWB(7,1)&gt;<br>&nbsp;&nbsp;&nbsp; &lt;br&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/p&gt;<br>&nbsp; &lt;hr align="center" width="90%" size="1" noshade&gt;<br>&lt;/center&gt;</p>
<p>&lt;table width="90%" border="0" align="center" cellpadding="2" cellspacing="0"&nbsp; class="tabp"&gt;<br>&nbsp;&lt;tr&gt;<br>&nbsp; &lt;td colspan="3" class="tdp"&gt;第1页&lt;/td&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/tr&gt;<br>&nbsp;&lt;tr&gt;<br>&nbsp;&nbsp; &lt;td width="29%" class="tdp"&gt;&amp;nbsp;&lt;/td&gt;<br>&nbsp;&nbsp; &lt;td width="28%" class="tdp"&gt;&amp;nbsp;&lt;/td&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td width="43%" class="tdp"&gt;&amp;nbsp;&lt;/td&gt;<br>&nbsp; &lt;/tr&gt;<br>&nbsp;&lt;tr&gt;<br>&nbsp;&nbsp; &lt;td colspan="3" class="tdp"&gt;&amp;nbsp;&lt;/td&gt;<br>&nbsp; &lt;/tr&gt;<br>&nbsp;&lt;tr&gt;<br>&nbsp;&nbsp; &lt;td colspan="3" class="tdp"&gt;&lt;table width="100%"&nbsp; border="0" cellspacing="0" cellpadding="0"&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td width="50%" class="tdp"&gt;&lt;p&gt;这样的报表&lt;/p&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;p&gt;对一般的要求就够了。&lt;/p&gt;&lt;/td&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&gt;&amp;nbsp;&lt;/td&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/tr&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/table&gt;&lt;/td&gt;<br>&nbsp; &lt;/tr&gt;<br>&lt;/table&gt;<br>&lt;hr align="center" width="90%" size="1" noshade class="NOPRINT" &gt;</p>
<p>&lt;div class="PageNext"&gt;&lt;/div&gt;&lt;!--打印范围控制--&gt;</p>
<p>&lt;table width="90%" border="0" align="center" cellpadding="2" cellspacing="0"&nbsp; class="tabp"&gt;<br>&nbsp; &lt;tr&gt;<br>&nbsp;&nbsp;&nbsp; &lt;td class="tdp"&gt;第2页&lt;/td&gt;<br>&nbsp; &lt;/tr&gt;<br>&nbsp; &lt;tr&gt;<br>&nbsp;&nbsp;&nbsp; &lt;td class="tdp"&gt;看到分页了吧&lt;/td&gt;<br>&nbsp; &lt;/tr&gt;<br>&nbsp; &lt;tr&gt;<br>&nbsp;&nbsp;&nbsp; &lt;td class="tdp"&gt;&amp;nbsp;&lt;/td&gt;<br>&nbsp; &lt;/tr&gt;<br>&nbsp; &lt;tr&gt;<br>&nbsp;&nbsp;&nbsp; &lt;td class="tdp"&gt;&amp;nbsp;&lt;/td&gt;<br>&nbsp; &lt;/tr&gt;<br>&nbsp; &lt;tr&gt;<br>&nbsp;&nbsp;&nbsp; &lt;td class="tdp"&gt;&lt;table width="100%"&nbsp; border="0" cellspacing="0" cellpadding="0"&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td width="50%" class="tdp"&gt;&lt;p&gt;这样的报表&lt;/p&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;p&gt;对一般的要求就够了。&lt;/p&gt;&lt;/td&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&gt;&amp;nbsp;&lt;/td&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/tr&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/table&gt;&lt;/td&gt;<br>&nbsp; &lt;/tr&gt;<br>&lt;/table&gt;</p>
<p><br>&lt;/body&gt;<br>&lt;/html&gt;</p>
<img src ="http://www.cnitblog.com/asfman/aggbug/36852.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-11-24 23:49 <a href="http://www.cnitblog.com/asfman/articles/36852.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>diary.js</title><link>http://www.cnitblog.com/asfman/articles/36814.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Fri, 23 Nov 2007 15:35:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/36814.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/36814.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/36814.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/36814.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/36814.html</trackback:ping><description><![CDATA[<p>/*<br>&nbsp;* Letter Paper Constructor<br>&nbsp;* Author:Dron<br>&nbsp;* Date: 2007-5-10<br>&nbsp;* Contact: ucren.com<br>&nbsp;*/</p>
<p>var LetterPaperConstructor = {</p>
<p>&nbsp;config : (function ()<br>&nbsp;{<br>&nbsp;&nbsp;var obj = document.getElementById("paper");<br>&nbsp;&nbsp;return {<br>&nbsp;&nbsp;&nbsp;title : obj.getAttribute("title") || "",<br>&nbsp;&nbsp;&nbsp;date : obj.getAttribute("date") || "1900-1-1",<br>&nbsp;&nbsp;&nbsp;heart : obj.getAttribute("heart") || "",<br>&nbsp;&nbsp;&nbsp;weather : obj.getAttribute("weather") || "",<br>&nbsp;&nbsp;&nbsp;author : obj.getAttribute("author") || "",<br>&nbsp;&nbsp;&nbsp;content : obj.innerHTML<br>&nbsp;&nbsp;};<br>&nbsp;})(),</p>
<p>&nbsp;corePath : (<br>&nbsp;&nbsp;function ()<br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;var s = document.getElementsByTagName("script");<br>&nbsp;&nbsp;&nbsp;&nbsp;s = s[s.length - 1];<br>&nbsp;&nbsp;&nbsp;var c = s.src;<br>&nbsp;&nbsp;&nbsp;&nbsp;c = c.match(/(.*)core\.js$/)[1];<br>&nbsp;&nbsp;&nbsp;return c;<br>&nbsp;&nbsp;}<br>&nbsp;)(),</p>
<p>&nbsp;template : [<br>&nbsp;&nbsp;&nbsp;"&lt;html&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&lt;head&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&lt;meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" /&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&lt;title&gt;{title}&lt;/title&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&lt;style type=\"text/css\"&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;body, td { font: 14px &#203;&#206;&#204;&#229;; }",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;body { background-color: #ddd; margin: 0; padding: 0; }",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;#content { width: auto; margin: 0 45px; background: #fff url(\"{corePath}common/images/line.gif\") repeat 0 0; line-height: 20px; }",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;#content td { color: #808080; }",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;#content .title { width: auto; text-align: center; font-weight: bold; }",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;#padding-bottom { width: auto; height: 37px; }",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&lt;/style&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&lt;/head&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&lt;body&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&lt;table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"608\" align=\"center\" style=\"margin: 5px auto;\"&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&lt;tr&gt;&lt;td background=\"{corePath}common/images/table-top.gif\" width=\"608\" height=\"45\"&gt;&lt;/td&gt;&lt;/tr&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&lt;tr&gt;&lt;td background=\"{corePath}common/images/table-middle.gif\"&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=\"content\"&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=\"title\"&gt;{title}&lt;/div&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" height=\"20\"&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td width=\"120\"&gt;Date:&lt;i&gt; {date}&lt;/i&gt;&lt;/td&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td width=\"120\"&gt;Heart:&lt;i&gt; {heart}&lt;/i&gt;&lt;/td&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td width=\"120\"&gt;Weather:&lt;i&gt; {weather}&lt;/i&gt;&lt;/td&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td width=\"120\"&gt;Author:&lt;i&gt; {author}&lt;/i&gt;&lt;/td&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/table&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{content}",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=\"padding-bottom\"&gt;&amp;nbsp;&lt;/div&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&lt;/td&gt;&lt;/tr&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&lt;tr&gt;&lt;td background=\"{corePath}common/images/table-bottom.gif\" height=\"8\"&gt;&lt;/td&gt;&lt;/tr&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&lt;/table&gt;",<br>&nbsp;&nbsp;&nbsp;"&nbsp;&lt;/body&gt;",<br>&nbsp;&nbsp;&nbsp;"&lt;/html&gt;"<br>&nbsp;&nbsp;],</p>
<p>&nbsp;disposeTemplate : function ()<br>&nbsp;{<br>&nbsp;&nbsp;this.template = this.template.join("\r\n")<br>&nbsp;&nbsp;&nbsp;.replace(/\{corePath\}/g, this.corePath)<br>&nbsp;&nbsp;&nbsp;.replace(/\{title\}/g, this.config.title)<br>&nbsp;&nbsp;&nbsp;.replace(/\{content\}/, this.config.content)<br>&nbsp;&nbsp;&nbsp;.replace(/\{date\}/, this.config.date)<br>&nbsp;&nbsp;&nbsp;.replace(/\{heart\}/, this.config.heart)<br>&nbsp;&nbsp;&nbsp;.replace(/\{weather\}/, this.config.weather)<br>&nbsp;&nbsp;&nbsp;.replace(/\{author\}/, this.config.author);<br>&nbsp;},</p>
<p>&nbsp;initialize : function ()<br>&nbsp;{<br>&nbsp;&nbsp;var me = this;<br>&nbsp;&nbsp;this.disposeTemplate();<br>&nbsp;&nbsp;window.setTimeout(function ()<br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;document.write(me.template);<br>&nbsp;&nbsp;}, 1);<br>&nbsp;}</p>
<p>}<br>LetterPaperConstructor.initialize();</p>
<img src ="http://www.cnitblog.com/asfman/aggbug/36814.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-11-23 23:35 <a href="http://www.cnitblog.com/asfman/articles/36814.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>base64 Encoding</title><link>http://www.cnitblog.com/asfman/articles/36354.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Fri, 16 Nov 2007 05:48:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/36354.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/36354.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/36354.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/36354.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/36354.html</trackback:ping><description><![CDATA[<p>&lt;html&gt;<br>&lt;head&gt;<br>&lt;title&gt;base64 Encoding/Decoding&lt;/title&gt;<br>&lt;/head&gt;</p>
<p>&lt;script type="text/javascript"&gt;&lt;!--<br>var keyStr = "ABCDEFGHIJKLMNOP" +<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "QRSTUVWXYZabcdef" +<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "ghijklmnopqrstuv" +<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "wxyz0123456789+/" +<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "=";</p>
<p>function encode64(input) {<br>&nbsp;&nbsp; input = escape(input);<br>&nbsp;&nbsp; var output = "";<br>&nbsp;&nbsp; var chr1, chr2, chr3 = "";<br>&nbsp;&nbsp; var enc1, enc2, enc3, enc4 = "";<br>&nbsp;&nbsp; var i = 0;</p>
<p>&nbsp;&nbsp; do {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chr1 = input.charCodeAt(i++);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chr2 = input.charCodeAt(i++);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chr3 = input.charCodeAt(i++);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enc1 = chr1 &gt;&gt; 2;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enc2 = ((chr1 &amp; 3) &lt;&lt; 4) | (chr2 &gt;&gt; 4);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enc3 = ((chr2 &amp; 15) &lt;&lt; 2) | (chr3 &gt;&gt; 6);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enc4 = chr3 &amp; 63;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (isNaN(chr2)) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enc3 = enc4 = 64;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else if (isNaN(chr3)) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enc4 = 64;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; output = output + <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; keyStr.charAt(enc1) + <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; keyStr.charAt(enc2) + <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; keyStr.charAt(enc3) + <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; keyStr.charAt(enc4);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chr1 = chr2 = chr3 = "";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enc1 = enc2 = enc3 = enc4 = "";<br>&nbsp;&nbsp; } while (i &lt; input.length);</p>
<p>&nbsp;&nbsp; return output;<br>}</p>
<p>function decode64(input) {<br>&nbsp;&nbsp; var output = "";<br>&nbsp;&nbsp; var chr1, chr2, chr3 = "";<br>&nbsp;&nbsp; var enc1, enc2, enc3, enc4 = "";<br>&nbsp;&nbsp; var i = 0;</p>
<p>&nbsp;&nbsp; // remove all characters that are not A-Z, a-z, 0-9, +, /, or =<br>&nbsp;&nbsp; var base64test = /[^A-Za-z0-9\+\/\=]/g;<br>&nbsp;&nbsp; if (base64test.exec(input)) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert("There were invalid base64 characters in the input text.\n" +<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Valid base64 characters are A-Z, a-z, 0-9, '+', '/', and '='\n" +<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Expect errors in decoding.");<br>&nbsp;&nbsp; }<br>&nbsp;&nbsp; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");</p>
<p>&nbsp;&nbsp; do {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enc1 = keyStr.indexOf(input.charAt(i++));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enc2 = keyStr.indexOf(input.charAt(i++));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enc3 = keyStr.indexOf(input.charAt(i++));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enc4 = keyStr.indexOf(input.charAt(i++));</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chr1 = (enc1 &lt;&lt; 2) | (enc2 &gt;&gt; 4);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chr2 = ((enc2 &amp; 15) &lt;&lt; 4) | (enc3 &gt;&gt; 2);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chr3 = ((enc3 &amp; 3) &lt;&lt; 6) | enc4;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; output = output + String.fromCharCode(chr1);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (enc3 != 64) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; output = output + String.fromCharCode(chr2);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (enc4 != 64) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; output = output + String.fromCharCode(chr3);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chr1 = chr2 = chr3 = "";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enc1 = enc2 = enc3 = enc4 = "";</p>
<p>&nbsp;&nbsp; } while (i &lt; input.length);</p>
<p>&nbsp;&nbsp; return unescape(output);<br>}</p>
<p>//--&gt;<br>&lt;/script&gt;</p>
<p>&lt;body&gt;<br>&lt;form name="base64Form"&gt;<br>&nbsp;&nbsp; Type in the message you want to encode in base64, or paste&lt;br&gt;<br>&nbsp;&nbsp; base64 encoded text into the text field, select Encode or Decode, &lt;br&gt;<br>&nbsp;&nbsp; and click the button!&lt;br&gt;</p>
<p>&nbsp;&nbsp; &lt;textarea name="theText" cols="40" rows="6"&gt;&lt;/textarea&gt;&lt;br&gt;</p>
<p>&nbsp;&nbsp; &lt;input type="button" name="encode" value="Encode to base64"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; onClick="document.base64Form.theText.value=encode64(document.base64Form.theText.value);"&gt;<br>&nbsp;&nbsp; &lt;input type="button" name="decode" value="Decode from base64" <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; onClick="document.base64Form.theText.value=decode64(document.base64Form.theText.value);"&gt;<br>&lt;/form&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</p>
<img src ="http://www.cnitblog.com/asfman/aggbug/36354.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-11-16 13:48 <a href="http://www.cnitblog.com/asfman/articles/36354.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>user behavior of sct</title><link>http://www.cnitblog.com/asfman/articles/36277.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Wed, 14 Nov 2007 08:49:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/36277.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/36277.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/36277.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/36277.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/36277.html</trackback:ping><description><![CDATA[<p>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br>&lt;component&gt;<br>&lt;implements type="Behavior"&gt;<br>&nbsp; &lt;attach event="onmouseover" handler="over"/&gt;<br>&nbsp; &lt;layout&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp; Just a Behavior test<br>&nbsp; &lt;/layout&gt;<br>&lt;/implements&gt;<br>&lt;public&gt;<br>&nbsp; &lt;method name="test"/&gt;<br>&nbsp; &lt;event name="onasfman"/&gt;<br>&lt;/public&gt;<br>&lt;script language="Javascript"&gt;<br>function over()<br>{<br>&nbsp; test();<br>}<br>function test()<br>{<br>&nbsp; var oEvent = createEventObject();<br>&nbsp; oEvent.asfman = "customize property";<br>&nbsp; fireEvent("onasfman",oEvent);<br>}<br>&lt;/script&gt;<br>&lt;/component&gt;<br><br>html:<br><br>&lt;html&gt;<br>&lt;head&gt;&lt;/head&gt;<br>&lt;body&gt;<br>&lt;div id="test" style="behavior:url(behavior2.sct);width:100px;height:100px;border:1px solid red;"&gt;&lt;/div&gt;<br>&lt;script&gt;<br>document.getElementById("test").onasfman=function()<br>{<br>&nbsp;&nbsp; alert(event.asfman);<br>}</p>
<p>&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</p>
<img src ="http://www.cnitblog.com/asfman/aggbug/36277.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-11-14 16:49 <a href="http://www.cnitblog.com/asfman/articles/36277.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>implements type=behavior的各种尝试</title><link>http://www.cnitblog.com/asfman/articles/36246.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Tue, 13 Nov 2007 08:33:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/36246.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/36246.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/36246.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/36246.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/36246.html</trackback:ping><description><![CDATA[<p>wsc文件： <br>&lt;?XML version="1.0"?&gt;<br>&lt;component id="bvrscript"&gt;<br>&lt;registration progid="Behaviorscript"/&gt;<br>&lt;implements type="Behavior"&gt;<br>&nbsp;&nbsp; &lt;attach event="onmouseover" handler="over"/&gt;<br>&nbsp;&nbsp; &lt;attach event="onmouseout" handler="out"/&gt;<br>&nbsp;&nbsp; &lt;attach event="onload" handler="ld" for="window"/&gt;<br>&nbsp;&nbsp; &lt;layout&gt;<br>&nbsp;&nbsp; &lt;![CDATA[<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;h1&gt;This is the HTML to show in the element&lt;/h1&gt;<br>&nbsp;&nbsp; ]]&gt;<br>&nbsp;&nbsp; &lt;/layout&gt;</p>
<p>&lt;/implements&gt;<br>&lt;public&gt;<br>&nbsp; &lt;event name="customize" /&gt;<br>&nbsp; &lt;method name="test"/&gt;<br>&lt;/public&gt;<br>&lt;script language="JScript"&gt;<br>&lt;![CDATA[<br>function ld()<br>{<br>&nbsp;&nbsp; document.body.innerHTML += "load successfully!";<br>}<br>var orColor,orBg;<br>function over(){<br>&nbsp;&nbsp; orColor = style.color;<br>&nbsp;&nbsp; style.color = "red";<br>&nbsp;&nbsp; style.backgroundColor = "yellow";<br>}<br>function out(){<br>&nbsp;&nbsp; style.color = orColor;<br>&nbsp;&nbsp; style.backgroundColor = "";<br>}<br>function test(){<br>var oEvent = createEventObject();<br>oEvent.asfman="pass the expando prop";<br>fireEvent("customize",oEvent);<br>return 123;<br>}<br>]]&gt;<br>&lt;/script&gt;<br>&lt;/component&gt;<br>htm文件：<br>&lt;html&gt;</p>
<p>&lt;head&gt;<br>&lt;meta http-equiv="Content-Type" content="text/html; charset=gb2312"&gt;<br>&lt;title&gt;this is a test div&lt;/title&gt;<br>&lt;/head&gt;</p>
<p>&lt;body&gt;<br>&lt;div id="test" style="behavior:url(behavior.wsc);border:1px solid red;width:200px;height:100px;line-height:100px;text-align:center;"&gt;&lt;/div&gt;<br>&lt;script&gt;<br>var o = document.getElementById("test");<br>o.customize=function(){alert(event.asfman);};<br>alert(o.test());<br>&lt;/script&gt;<br>&lt;/body&gt;</p>
<p>&lt;/html&gt;<br>新在学会了通过createEventObject创建事件实例传递属性给event，非常爽</p>
<img src ="http://www.cnitblog.com/asfman/aggbug/36246.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-11-13 16:33 <a href="http://www.cnitblog.com/asfman/articles/36246.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>wmp.dll控件常用属性</title><link>http://www.cnitblog.com/asfman/articles/35982.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Wed, 07 Nov 2007 08:24:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/35982.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/35982.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/35982.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/35982.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/35982.html</trackback:ping><description><![CDATA[wmp.dll控件常用属性&nbsp; <br>&nbsp;&nbsp;&nbsp; 本人在网上收集到windows media player 控件的一些属性，望对有需要的朋友有所帮助。（在计算机中装了wmp9以上，就会有wmp.dll控件，属性如下所示) <br>属性/方法名： 说明： <br>[基本属性] 　 <br>URL:String; 指定媒体位置，本机或网络地址 <br>uiMode:String; 播放器界面模式，可为Full, Mini, None, Invisible <br>playState:integer; 播放状态，1=停止，2=暂停，3=播放，6=正在缓冲，9=正在连接，10=准备就绪 <br>enableContextMenu:Boolean; 启用/禁用右键菜单 <br>fullScreen:boolean; 是否全屏显示 <br>[controls] wmp.controls //播放器基本控制 <br>controls.play; 播放 <br>controls.pause; 暂停 <br>controls.stop; 停止 <br>controls.currentPosition:double; 当前进度 <br>controls.currentPositionString:string; 当前进度，字符串格式。如&#8220;00:23&#8221; <br>controls.fastForward; 快进 <br>controls.fastReverse; 快退 <br>controls.next; 下一曲 <br>controls.previous; 上一曲 <br>[settings] wmp.settings //播放器基本设置 <br>settings.volume:integer; 音量，0-100 <br>settings.autoStart:Boolean; 是否自动播放 <br>settings.mute:Boolean; 是否静音 <br>settings.playCount:integer; 播放次数 <br>[currentMedia] wmp.currentMedia //当前媒体属性 <br>currentMedia.duration:double; 媒体总长度 <br>currentMedia.durationString:string; 媒体总长度，字符串格式。如&#8220;03:24&#8221; <br>currentMedia.getItemInfo(const string); 获取当前媒体信息"Title"=媒体标题，"Author"=艺术家，"Copyright"=版权信息，"Description"=媒体内容描述，"Duration"=持续时间（秒），"FileSize"=文件大小，"FileType"=文件类型，"sourceURL"=原始地址 <br>currentMedia.setItemInfo(const string); 通过属性名设置媒体信息 <br>currentMedia.name:string; 同 currentMedia.getItemInfo("Title") <br>[currentPlaylist] wmp.currentPlaylist //当前播放列表属性 <br>currentPlaylist.count:integer; 当前播放列表所包含媒体数 <br>currentPlaylist.Item[integer]; 获取或设置指定项目媒体信息，其子属性同wmp.currentMedia&nbsp;<br><br>//2...<br>＝＝＝＝＝＝＝＝＝＝WindowsMediaPlayer的常用属性和方法＝＝＝＝＝＝＝＝＝＝＝<br>[基本属性]&nbsp;<br>URL:string&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;可以指定媒体位置&nbsp;<br>enableContextMenu:Boolean&nbsp;显示/不显示播放位置的右键菜单&nbsp;<br>fullScreen:boolean&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;全屏显示&nbsp;<br>stretchToFit:boolean&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;非全屏状态时是否伸展到最佳大小&nbsp;<br>uMode:string&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;播放器的模式，full：有下面的控制条;&nbsp;none：只有播放部份没有控制条&nbsp;<br>playState:integer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;当前控件状态，下面是三种基本状态：&nbsp;<br>3：正在播放&nbsp;<br>2：暂停&nbsp;<br>1：已停止&nbsp;<br>状态变化时会触发OnStatusChange事件&nbsp;<br><br>[controls]&nbsp;<br>可通过WindowsMediaPlayer.controls对播放器进行控制并取得相关的一些信息：&nbsp;<br>&nbsp;controls.play;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;播放&nbsp;<br>&nbsp;<a name=baidusnap0></a><strong style="COLOR: black; BACKGROUND-COLOR: #ffff66">controls.stop</strong>;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;停止&nbsp;<br>&nbsp;controls.pause;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;暂停&nbsp;<br>&nbsp;controls.currentPosition：Double&nbsp;当前播放进度&nbsp;<br>&nbsp;controls.currentPositionString：string&nbsp;时间格式的字符串&nbsp;"0:32"&nbsp;<br><br>[currentMedia]&nbsp;<br>可以通过WindowsMediaPlayer.currentMedia取得当前媒体的信息&nbsp;<br>&nbsp;currentMedia.duration&nbsp;&nbsp;Double&nbsp;总长度&nbsp;<br>&nbsp;currentMedia.durationString&nbsp;时间格式的字符串&nbsp;"4:34"&nbsp;<br><br>[settings]&nbsp;<br>可以通过WindowsMediaPlayer.settings对播放器进行设置，包括音量和声道等。&nbsp;<br>settings.volume:integer&nbsp;音量&nbsp;（0-100）&nbsp;<br>settings.balance:integer&nbsp;声道，通过它应该可以进行立体声、左声道、右声道的控制。&nbsp;<br>--&gt;<br>&lt;input&nbsp;type="button"&nbsp;value='换文件'&nbsp;onclick="MediaPlayer.controls.src='d:\xx.mid';"&gt;
<img src ="http://www.cnitblog.com/asfman/aggbug/35982.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-11-07 16:24 <a href="http://www.cnitblog.com/asfman/articles/35982.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>获取mac ip </title><link>http://www.cnitblog.com/asfman/articles/35862.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Sun, 04 Nov 2007 15:31:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/35862.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/35862.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/35862.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/35862.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/35862.html</trackback:ping><description><![CDATA[<p><font face=Verdana>在做 B/S 结构的系统时，我们常常需要获取客户端的一些信息，如 IP 和 MAC ，以结合身份验证。 要获取服务器端的 MAC 很容易，但是要获取客户端的 MAC 的地址确要花费一翻心思，通常的做法是调用 Win32API 或直接调用 nbtstat 命令，这样做有很多问题，而另一种方法就是直接用客户端脚本，我们这里用 Javascript ，这样做的好处是不需要服务器端进行处理，有客户端自行获取，传递到服务器端，且速度和可靠性都比在服务器端获取好。<br>具体实现的html和javascript如下：</font><br>&nbsp;<br></p>
<div style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<div><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">html</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">head</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">title</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">WMI&nbsp;Scripting&nbsp;HTML</span><span style="COLOR: #000000">&lt;/</span><span style="COLOR: #000000">title</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">meta&nbsp;http</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">equiv</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Content-Type</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;content</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">text/html;&nbsp;charset=gb2312</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">/&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">script&nbsp;language</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">JScript</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;event</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">OnCompleted(hResult,pErrorObject,&nbsp;pAsyncContext)</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">foo</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top>document.forms[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">].txtMACAddr.value</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">unescape(MACAddr);<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top>document.forms[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">].txtIPAddr.value</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">unescape(IPAddr);<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top>document.forms[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">].txtDNSName.value</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">unescape(sDNSName);<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">document.formbar.submit();</span><span style="COLOR: #008000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;/</span><span style="COLOR: #000000">script</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">script&nbsp;language</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">JScript</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;event</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">OnObjectReady(objObject,objAsyncContext)</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">foo</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(objObject.IPEnabled&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;objObject.IPEnabled&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">undefined</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;objObject.IPEnabled&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">)<br><img id=_605_951_Open_Image onclick="this.style.display='none'; document.getElementById('_605_951_Open_Text').style.display='none'; document.getElementById('_605_951_Closed_Image').style.display='inline'; document.getElementById('_605_951_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=_605_951_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_605_951_Closed_Text').style.display='none'; document.getElementById('_605_951_Open_Image').style.display='inline'; document.getElementById('_605_951_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=_605_951_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id=_605_951_Open_Text><span style="COLOR: #000000">{<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(objObject.MACAddress&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;objObject.MACAddress&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">undefined</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top>MACAddr&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;objObject.MACAddress;<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(objObject.IPEnabled&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;objObject.IPAddress(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;objObject.IPAddress(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">undefined</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top>IPAddr&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;objObject.IPAddress(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(objObject.DNSHostName&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;objObject.DNSHostName&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">undefined</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top>sDNSName&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;objObject.DNSHostName;<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;/</span><span style="COLOR: #000000">script</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;/</span><span style="COLOR: #000000">head</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">body</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">object&nbsp;id</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">locator</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;classid</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">CLSID:76A64158-CB41-11D1-8B02-00600806D9B6</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;viewastext</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;/</span><span style="COLOR: #000000">object</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">object&nbsp;id</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">foo</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;classid</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;/</span><span style="COLOR: #000000">object</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">script&nbsp;language</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">JScript</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;service&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;locator.ConnectServer();<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;MACAddr&nbsp;;<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;IPAddr&nbsp;;<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;DomainAddr;<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;sDNSName;<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top>service.Security_.ImpersonationLevel</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">;<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top>service.InstancesOfAsync(foo,&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">Win32_NetworkAdapterConfiguration</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">);<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;/</span><span style="COLOR: #000000">script</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">form&nbsp;id</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">formfoo</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;name</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">formbar</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;action</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">index.do</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;method</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">post</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">input&nbsp;value</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">00-11-11-B4-52-EF</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;name</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">txtMACAddr</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">/&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">input&nbsp;value</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">210.42.38.50</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;name</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">txtIPAddr</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">/&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">input&nbsp;value</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">zhupan</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;name</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">txtDNSName</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">/&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;/</span><span style="COLOR: #000000">form</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;/</span><span style="COLOR: #000000">body</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;/</span><span style="COLOR: #000000">html</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span></div>
</div>
<br><br><font face=Verdana>其实最关键的还是用到两个ActiveX：<br>&lt;OBJECT id=locator classid=CLSID:76A64158-CB41-11D1-8B02-00600806D9B6 VIEWASTEXT&gt;&lt;/OBJECT&gt;<br>&lt;OBJECT id=foo classid=CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223&gt;&lt;/OBJECT&gt;<br>不过这两个ActiveX都是系统自带，不用去下载或注册。<br>接下来的工作就是用脚本和ActiveX交互</font><br><br><br>
<p id=TBPingURL>Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1859378</p>
<img src ="http://www.cnitblog.com/asfman/aggbug/35862.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-11-04 23:31 <a href="http://www.cnitblog.com/asfman/articles/35862.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>闭包 单个单个传递参数</title><link>http://www.cnitblog.com/asfman/articles/35282.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Wed, 24 Oct 2007 08:04:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/35282.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/35282.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/35282.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/35282.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/35282.html</trackback:ping><description><![CDATA[<p>&lt;script&gt;<br>function check(args,thisValue)<br>{<br>&nbsp;&nbsp;&nbsp; if(args.length&lt;args.callee.length)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return function(){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return args.callee.apply(thisValue,Array.prototype.slice.call(args).concat(Array.prototype.slice.call(arguments)));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; };<br>}</p>
<p>function f(a,b,c)<br>{<br>&nbsp;&nbsp;&nbsp; var t=check(arguments,this);<br>&nbsp;&nbsp;&nbsp; if(t)return t;<br>&nbsp;&nbsp;&nbsp; alert([a,b,c]);<br>}<br>var d=f(1)(2)(3);<br>var e=f(4,5)(6);<br>&lt;/script&gt;</p>
<img src ="http://www.cnitblog.com/asfman/aggbug/35282.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-10-24 16:04 <a href="http://www.cnitblog.com/asfman/articles/35282.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>setRquestHeader使用实例1</title><link>http://www.cnitblog.com/asfman/articles/35281.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Wed, 24 Oct 2007 07:41:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/35281.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/35281.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/35281.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/35281.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/35281.html</trackback:ping><description><![CDATA[<p>&lt;<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#37;&#64;&#76;&#97;&#110;&#103;&#117;&#97;&#103;&#101;">%@Language</a> = "Javascript" %&gt;<br>&lt;%<br>//Response.Write(Request.ServerVariables("http_accept"));<br>&nbsp;var a=Request.QueryString('a').Item;<br>&nbsp;var b=Request.QueryString('b').Item;<br>&nbsp;if(!a){total="";}<br>&nbsp;else{<br>&nbsp;var total=a-0+(b-0);}<br>&nbsp;acc=Request.ServerVariables('HTTP_ACCEPT')+''<br>&nbsp;if (acc.indexOf('asfman')!=-1) {<br>&nbsp; Response.Write(total)<br>&nbsp;} else {<br>%&gt;<br>&lt;script&gt;<br>var xmlhttp = new XMLHttpRequest();<br>&nbsp;function calc() {<br>&nbsp; frm=document.forms[0]<br>&nbsp; url="?a="+frm.elements['a'].value+"&amp;b="+frm.elements['b'].value<br>&nbsp; xmlhttp.open("GET",url,true);<br>&nbsp; xmlhttp.onreadystatechange=function() {<br>&nbsp;&nbsp; if (xmlhttp.readyState==4) {<br>&nbsp;&nbsp;&nbsp; document.forms[0].elements['total'].value=xmlhttp.responseText<br>&nbsp;&nbsp; }<br>&nbsp; }<br>&nbsp;xmlhttp.setRequestHeader('Accept','asfman');<br>&nbsp;xmlhttp.send()<br>&nbsp;return false<br>}<br>&lt;/script&gt;<br>&lt;form action="" method="get" onsubmit="return calc()"&gt;<br>&lt;input type=text name=a value="&lt;%=a%&gt;"&gt; + &lt;input type=text name=b value="&lt;%=b%&gt;"&gt;<br>&nbsp;= &lt;input type=text name=total value="&lt;%=total%&gt;"&gt;<br>&lt;input type=submit value="Calculate"&gt;<br>&lt;/form&gt;<br>&lt;%<br>}<br>%&gt;</p>
<img src ="http://www.cnitblog.com/asfman/aggbug/35281.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-10-24 15:41 <a href="http://www.cnitblog.com/asfman/articles/35281.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>绝妙的闭包绑定关联事件</title><link>http://www.cnitblog.com/asfman/articles/34809.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Sat, 13 Oct 2007 05:58:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/34809.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/34809.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/34809.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/34809.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/34809.html</trackback:ping><description><![CDATA[&nbsp;onMethodExecute:function(o,n,f,beforeMethod){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var rad = "_asfman_"+asfman.randomWord(6);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; o[rad]= o[n];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; o[n]= function(){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var a=arguments;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; beforeMethod &amp;&amp; f.apply(this,a);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this[rad].apply(this,a);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; beforeMethod || f.apply(this,a);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;}<br>&nbsp;&nbsp;}<br>很难想象大肉是如何想出来的
<img src ="http://www.cnitblog.com/asfman/aggbug/34809.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-10-13 13:58 <a href="http://www.cnitblog.com/asfman/articles/34809.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>about eval new Function execScript</title><link>http://www.cnitblog.com/asfman/articles/34516.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Mon, 08 Oct 2007 02:35:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/34516.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/34516.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/34516.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/34516.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/34516.html</trackback:ping><description><![CDATA[function test()<br>{<br>&nbsp;&nbsp;&nbsp; eval("var i=1");//i为局部变量，在外面访问不到 <br>}<br><br>function test()<br>{<br>&nbsp;&nbsp; new Function("var i=2");//i为局部变量。。。<br>}<br><br>function test()<br>{<br>&nbsp;&nbsp; execScript("var i=3");//i为全局变量<br>}<br>
<img src ="http://www.cnitblog.com/asfman/aggbug/34516.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-10-08 10:35 <a href="http://www.cnitblog.com/asfman/articles/34516.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于正则表达式的循环使用</title><link>http://www.cnitblog.com/asfman/articles/33959.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Mon, 24 Sep 2007 07:26:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/33959.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/33959.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/33959.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/33959.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/33959.html</trackback:ping><description><![CDATA[&lt;script&gt;<br>var s="";<br>var str="|b+c|d";<br>var re=/[^|]+/g;<br>var re2=/[^+]+/g;<br>re.test(str);<br>document.write(RegExp.lastMatch+"&lt;br&gt;");<br>re.test(str);<br>document.write(RegExp.lastMatch+"&lt;br&gt;");<br>re.test(str);//false<br>document.write(RegExp.lastMatch+"&lt;br&gt;");<br>re.test(str);//re从false以后，又会从头开始<br>document.write(RegExp.lastMatch);<br>&lt;/script&gt;<br>当正则表达式re有过一次false以后，再re.test(str)则会从头开始查找<br>written by asfman 2007.9.24
<img src ="http://www.cnitblog.com/asfman/aggbug/33959.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-09-24 15:26 <a href="http://www.cnitblog.com/asfman/articles/33959.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Array.prototype.slice处理arguments对象</title><link>http://www.cnitblog.com/asfman/articles/32616.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Wed, 29 Aug 2007 18:03:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/32616.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/32616.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/32616.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/32616.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/32616.html</trackback:ping><description><![CDATA[&lt;script&gt;<br>Function.prototype.bind=function(o)<br>{<br>var args=Array.prototype.slice.call(arguments,1);<br>&nbsp;&nbsp; this.apply(o, args);<br>}<br>function a(p1,p2){<br>alert(p1+p2+this.x);<br>}<br>var o={x:1};<br>a.bind(o,1,2);<br>&lt;/script&gt;
<img src ="http://www.cnitblog.com/asfman/aggbug/32616.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-08-30 02:03 <a href="http://www.cnitblog.com/asfman/articles/32616.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CreateDocumentFragment的用处</title><link>http://www.cnitblog.com/asfman/articles/32614.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Wed, 29 Aug 2007 17:14:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/32614.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/32614.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/32614.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/32614.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/32614.html</trackback:ping><description><![CDATA[<p>一旦把节点添加到document.body(或其后的节点)中，页面就会立即反映出这个变化。对于少量的更新，这是很好的。然而，当要向document.body添加大量数据时，如果逐个添加这些节点，这个过程有可能会十分缓慢。为解决这个问题，可以创建一个文档碎片，把所有的新节点附加其上，然后把文档碎片的内容一次性添加到document中。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; 假设你想创建十个新段落。你可能这样写：</p>
<div style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<div><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;arrText</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">7</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">];<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">arrText.length;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img id=_90_233_Open_Image onclick="this.style.display='none'; document.getElementById('_90_233_Open_Text').style.display='none'; document.getElementById('_90_233_Closed_Image').style.display='inline'; document.getElementById('_90_233_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=_90_233_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_90_233_Closed_Text').style.display='none'; document.getElementById('_90_233_Open_Image').style.display='inline'; document.getElementById('_90_233_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=_90_233_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id=_90_233_Open_Text><span style="COLOR: #000000">{<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;op</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">document.createElement(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">P</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;oText</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">document.createTextNode(arrText[i]);<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;op.appendChild(oText);<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;document.body.appendChild(op);<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span></div>
</div>
<p>&nbsp;这段代码运行良好，但问题是它调用了十次document.body.appendChild(),每次要产生一次页面刷新。这时，文档碎片会更高效：</p>
<div style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<div><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;arrText</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">7</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">];<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;oFrag</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">document.createDocumentFragment();<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">arrText.length;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img id=_136_273_Open_Image onclick="this.style.display='none'; document.getElementById('_136_273_Open_Text').style.display='none'; document.getElementById('_136_273_Closed_Image').style.display='inline'; document.getElementById('_136_273_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=_136_273_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_136_273_Closed_Text').style.display='none'; document.getElementById('_136_273_Open_Image').style.display='inline'; document.getElementById('_136_273_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=_136_273_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id=_136_273_Open_Text><span style="COLOR: #000000">{<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;op</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">document.createElement(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">P</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;oText</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">document.createTextNode(arrText[i]);<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;op.appendChild(oText);<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;oFrag.appendChild(op);<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align=top>document.body.appendChild(oFrag);</span></div>
</div>
这段代码中,document.body.appendChild()仅调用了一次，这意味首只需要进行一次屏幕的刷新。
<img src ="http://www.cnitblog.com/asfman/aggbug/32614.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-08-30 01:14 <a href="http://www.cnitblog.com/asfman/articles/32614.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>attemp to get runtime object</title><link>http://www.cnitblog.com/asfman/articles/32612.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Wed, 29 Aug 2007 16:35:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/32612.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/32612.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/32612.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/32612.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/32612.html</trackback:ping><description><![CDATA[&lt;script language="JavaScript"&gt;<br>function b(o)<br>{<br>&nbsp; alert(o("f"));<br>&nbsp; o("f","新的值");<br>}<br>function a()<br>{<br>&nbsp; var f = "原始的值";<br>&nbsp; var o = function(__s,__n){return eval(__s+(arguments.length&gt;=2?"=__n":""))};<br>&nbsp; b(o);<br>&nbsp; alert(f);<br>}<br>a();<br>&lt;/script&gt;
<img src ="http://www.cnitblog.com/asfman/aggbug/32612.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-08-30 00:35 <a href="http://www.cnitblog.com/asfman/articles/32612.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>think aboust slice </title><link>http://www.cnitblog.com/asfman/articles/32145.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Tue, 21 Aug 2007 07:15:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/32145.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/32145.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/32145.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/32145.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/32145.html</trackback:ping><description><![CDATA[&lt;script&gt;<br>Array.prototype.slice=function(n){<br>var temp=[];<br>for(var i=0;i&lt;this.length;i++)<br>{<br>if(i&gt;=n||i&lt;0)<br>temp.push(this[i]);<br>}<br>return temp;<br>}<br>function a(){<br>return Array.prototype.slice.call(arguments,2);<br>}<br>alert(a(1,2,3,4));<br>&lt;/script&gt; <br>我想slice肯定是这种写法,arugments有length属性 也能通过var i=0;i&lt;l;i++枚举 导致<br>Array.prototype.slice.call(arguments,2)运行正常 跟Array对象一样 <br>不过一般都采用 ：<br>Array.apply(null,arguments).slice(2)
<img src ="http://www.cnitblog.com/asfman/aggbug/32145.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-08-21 15:15 <a href="http://www.cnitblog.com/asfman/articles/32145.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sc用object相互调用</title><link>http://www.cnitblog.com/asfman/articles/31253.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Sun, 05 Aug 2007 01:07:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/31253.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/31253.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/31253.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/31253.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/31253.html</trackback:ping><description><![CDATA[sct 1:<br>&lt;package&gt;<br>&lt;component&gt;<br>&lt;runtime&gt;<br>&lt;example&gt; <br>var o=new ActiveXObject("asfman.best");<br>alert(o.factorial(12))<br>&lt;/example&gt;<br>&lt;/runtime&gt;<br>&lt;registration <br>&nbsp;description="factorial function"<br>&nbsp;classid="{12345678-aabb-ccdd-eeff-012345678901}" <br>&nbsp;progid="asfman.best"&gt;<br>&lt;/registration&gt;<br>&lt;public&gt;<br>&lt;method name="f" internalName="factorial" dispid="0" /&gt;<br>&lt;/public&gt;<br>&lt;script language="Jscript"&gt;<br>function factorial(n)<br>{<br>&nbsp;return n&gt;1?n*arguments.callee(n-1):1;<br>}<br>&lt;/script&gt;<br>&lt;implements type="ASP" /&gt;<br>&lt;/component&gt;<br>&lt;/package&gt; <br>sct2:<br>&lt;package&gt;<br>&lt;component&gt;<br>&lt;registration <br>&nbsp;description="test2 object"<br>&nbsp;classid="{12345678-aabb-ccdd-eeff-112345678901}" <br>&nbsp;progid="asfman.best2"&gt;<br>&lt;/registration&gt;<br>&lt;object id="test" progid="asfman.best" /&gt;<br>&lt;public&gt;<br>&lt;method name="a" internalName="a" dispid="0" /&gt;<br>&lt;/public&gt;<br>&lt;script language="Jscript"&gt;<br>function a(n)<br>{<br>&nbsp;return test.f(n);<br>}<br>&lt;/script&gt;<br>&lt;implements type="ASP" /&gt;<br>&lt;/component&gt;<br>&lt;/package&gt; 
<img src ="http://www.cnitblog.com/asfman/aggbug/31253.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-08-05 09:07 <a href="http://www.cnitblog.com/asfman/articles/31253.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Create Advanced Web Applications With Object-Oriented Techniques</title><link>http://www.cnitblog.com/asfman/articles/29253.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Sat, 30 Jun 2007 08:07:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/29253.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/29253.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/29253.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/29253.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/29253.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: http://msdn.microsoft.com/msdnmag/issues/07/05/JavaScript/default.aspx?loc=en#S6JavaScript Objects Are DictionariesJavaScript Functions Are First ClassConstructor Functions but No ClassesPrototypesSta...&nbsp;&nbsp;<a href='http://www.cnitblog.com/asfman/articles/29253.html'>阅读全文</a><img src ="http://www.cnitblog.com/asfman/aggbug/29253.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/asfman/" target="_blank">汪杰</a> 2007-06-30 16:07 <a href="http://www.cnitblog.com/asfman/articles/29253.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>你真的会写JavaScript吗？</title><link>http://www.cnitblog.com/asfman/articles/29250.html</link><dc:creator>汪杰</dc:creator><author>汪杰</author><pubDate>Sat, 30 Jun 2007 06:30:00 GMT</pubDate><guid>http://www.cnitblog.com/asfman/articles/29250.html</guid><wfw:comment>http://www.cnitblog.com/asfman/comments/29250.html</wfw:comment><comments>http://www.cnitblog.com/asfman/articles/29250.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/asfman/comments/commentRss/29250.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/asfman/services/trackbacks/29250.html</trackback:ping><description><![CDATA[<p><font size=2>JavaScript是一门基于原型的语言，但它却拥有一个 new 操作符使得其看起来象一门经典的面对对象语言。那样也迷惑了程序员们，导致一些有问题的编程模式。</font></p>
<p><font size=2>其实你永远不需要在JavaScript使用 new Object()。用字面量的形式{}去取代吧。<br></font><font size=2><br>同理，不要使用 new Array() ，而代之以字面量[]。JavaScript中的数组并不象Java中的数组那样工作的，使用类似Java的语法只会让你糊涂。</font></p>
<p><font size=2>同理不用使用 new Number, new String, 或者 new Boolean。这些的用法只会产生无用的类型封装对象。就直接使用简单的字面量吧。</font></p>
<p><font size=2>不要使用 new Function 去创建函数对象。用函数表达式更好。比如：</font></p>
<p><font size=2>frames[0].onfocus = new Function(&#8221;document.bgColor=&#8217;antiquewhite&#8217;&#8221;)</font></p>
<p><font size=2>更好的写法是：</font></p>
<p><font size=2>frames[0].onfocus = function () {document.bgColor = &#8216;antiquewhite&#8217;;};</font></p>
<p><font size=2>第二种形式让脚本编译器更快的看到函数主体，于是其中的语法错误也会更快被检测出来。有时候程序员使用 new Function 是因为他们没有理解内部函数是如何工作的。</font></p>
<p><font size=2>selObj.onchange = new Function(&#8221;dynamicOptionListObjects[&#8221;+<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dol.index+&#8221;].change(this)&#8221;);</font></p>
<p><font size=2>如果我们让用字符串做函数体，编译器不能看到它们。如果我们用字符串表达式做函数体，我们同样也看不到它们。更好的方式就是不要盲目编程。通过制造一个返回值为函数的函数调用，我