<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title><![CDATA[木子屋 - 前台脚本]]></title>
<link>http://www.mzwu.com/</link>
<description><![CDATA[Dnawo&#39;s BLOG]]></description>
<language>zh-cn</language>
<copyright><![CDATA[Copyright 2005 PBlog3 v2.8]]></copyright>
<webMaster><![CDATA[dnawo@sohu.com(Dnawo)]]></webMaster>
<generator>PBlog2 v2.4</generator> 
<image>
	<title>木子屋</title>
	<url>http://www.mzwu.com/images/logos.gif</url>
	<link>http://www.mzwu.com/</link>
	<description>木子屋</description>
</image>

			<item>
			<link>http://www.mzwu.com/article.asp?id=2413</link>
			<title><![CDATA[cscript.exe调用vbs示例]]></title>
			<author>dnawo@sohu.com(dnawo)</author>
			<category><![CDATA[前台脚本]]></category>
			<pubDate>Tue,30 Mar 2010 11:43:46 +0800</pubDate>
			<guid>http://www.mzwu.com/default.asp?id=2413</guid>
		<description><![CDATA[test.vbs：<br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code9750);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code9750>Dim ArgObj<br/>Set ArgObj = WScript.Arguments<br/>If ArgObj.Count &lt; 1 Then<br/>&#160;&#160;&#160;&#160;msgbox &#34;miss arguments!&#34;<br/>&#160;&#160;&#160;&#160;WScript.Quit()<br/>Else<br/>&#160;&#160;&#160;&#160;Sel&#101;ct Case UCase(ArgObj(0))<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Case &#34;ALERT&#34;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;Alert ArgObj(1)<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Case &#34;ADD&#34;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Add ArgObj(1), ArgObj(2)<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Case Else<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;msgbox &#34;arguments error!&#34;<br/>&#160;&#160;&#160;&#160;End Sel&#101;ct<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;<br/>End If<br/><br/>Sub Alert(username)<br/>&#160;&#160;&#160;&#160;msgbox &#34;hello,&#34; &amp; username<br/>End Sub<br/><br/>Sub Add(a, b)<br/>&#160;&#160;&#160;&#160;msgbox CInt(a) + CInt(b)<br/>End Sub</div></div><br/>调用示例：<br/><div class="UBBPanel quotePanel"><div class="UBBTitle"><img src="http://www.mzwu.com/images/quote.gif" style="margin:0px 2px -3px 0px" alt="引用内容"/> 引用内容</div><div class="UBBContent">cscript.exe test.vbs<br/>cscript.exe test.vbs alert mzwu<br/>cscript.exe test.vbs add 5 6</div></div><br/>cscript.exe可省略，一样能正常执行！]]></description>
		</item>
		
			<item>
			<link>http://www.mzwu.com/article.asp?id=2365</link>
			<title><![CDATA[jquery.treeview.async简介]]></title>
			<author>dnawo@sohu.com(dnawo)</author>
			<category><![CDATA[前台脚本]]></category>
			<pubDate>Tue,19 Jan 2010 09:54:18 +0800</pubDate>
			<guid>http://www.mzwu.com/default.asp?id=2365</guid>
		<description><![CDATA[jquery.treeview.async用于在页面显示一个树形菜单，其特点在于所有节点都是异步获取的(只加载所需的节点，避免一次性加载全部导致客户端浏览器卡死)，服务器端返回json格式的对象数组即可。每个json对象可以包含如下属性：<br/><br/><img src="http://www.mzwu.com/pic/201001/011.gif" border="0" alt=""/><br/><br/>·简单的节点对象：{&#34;text&#34;:&#34;mzwu.com&#34;}<br/>·包含子节点对象(异步)：{&#34;text&#34;:&#34;other&#34;,&#34;id&#34;:&#34;other&#34;,&#34;hasChildren&#34;:&#34;true&#34;}<br/>·包含子节点对象(非异步)：{&#34;text&#34;:&#34;ftp&#34;,&#34;children&#34;:[{&#34;text&#34;:&#34;aaa.com&#34;},{&#34;text&#34;:&#34;bbb.com&#34;}]}<br/><br/><strong>说明</strong><br/><br/>异步获取节点数据时，treeview会使用get方式提交一个参数(root)到服务器端，treeview初始化(首次加载)时，这个参数值为source，之后异步获取子节点时，参数值为所点击节点的id值，服务器端需根据这一参数值不同返回不同的json对象数组：<br/><br/>demo.htm<br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code50307);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code50307>&lt;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank" rel="external">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>&#34;&gt;<br/>&lt;html xmlns=&#34;<a href="http://www.w3.org/1999/xhtml" target="_blank" rel="external">http://www.w3.org/1999/xhtml</a>&#34;&gt;<br/>&lt;head&gt;<br/>&lt;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=gb2312&#34; /&gt;<br/>&lt;title&gt;jquery.treeview.async示例-Mzwu.Com&lt;/title&gt;<br/>&lt;link href=&#34;lib/jquery.treeview.css&#34; rel=&#34;stylesheet&#34; type=&#34;text/css&#34; /&gt;<br/>&lt;script language=&#34;JavaScript&#34; type=&#34;text/javascript&#34; src=&#34;lib/jquery.js&#34;&gt;&lt;/script&gt;<br/>&lt;script language=&#34;JavaScript&#34; type=&#34;text/javascript&#34; src=&#34;lib/jquery.cookie.js&#34;&gt;&lt;/script&gt;<br/>&lt;script language=&#34;JavaScript&#34; type=&#34;text/javascript&#34; src=&#34;lib/jquery.treeview.min.js&#34;&gt;&lt;/script&gt;<br/>&lt;script language=&#34;JavaScript&#34; type=&#34;text/javascript&#34; src=&#34;lib/jquery.treeview.async.js&#34;&gt;&lt;/script&gt;<br/>&lt;script type=&#34;text/javascript&#34;&gt;<br/>$(document).ready(function(){<br/>&#160;&#160;&#160;&#160;$(&#34;#treeview&#34;).treeview({<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;url: &#34;treeview.asp&#34;<br/>&#160;&#160;&#160;&#160;})<br/>});<br/>&lt;/script&gt;<br/>&lt;/head&gt;<br/><br/>&lt;body&gt;<br/>&lt;ul id=&#34;treeview&#34;&gt;&lt;/ul&gt;<br/>&lt;/body&gt;<br/>&lt;/html&gt;</div></div><br/>treeview.asp：<br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code45371);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code45371>&lt;% If Request.QueryString(&#34;root&#34;)=&#34;source&#34; Then %&gt;<br/>[{&#34;text&#34;:&#34;mzwu.com&#34;},{&#34;text&#34;:&#34;other&#34;,&#34;id&#34;:&#34;other&#34;,&#34;hasChildren&#34;:&#34;true&#34;}]<br/>&lt;% End If %&gt;<br/><br/>&lt;% If Request.QueryString(&#34;root&#34;)=&#34;other&#34; Then %&gt;<br/>[{&#34;text&#34;:&#34;ftp&#34;,&#34;expanded&#34;:&#34;true&#34;,&#34;children&#34;:[{&#34;text&#34;:&#34;aaa.com&#34;},{&#34;text&#34;:&#34;bbb.com&#34;},{&#34;text&#34;:&#34;ccc.com&#34;}]},{&#34;text&#34;:&#34;web&#34;,&#34;children&#34;:[{&#34;text&#34;:&#34;xxx.com&#34;},{&#34;text&#34;:&#34;yyy.com&#34;},{&#34;text&#34;:&#34;zzz.com&#34;}]}]<br/>&lt;% End If %&gt;</div></div><br/><strong>扩展</strong><br/><br/>为json节点对象增加了两个属性：url和target，表示节点链接地址和打开链接的窗口，jquery.treeview.async修改如下：<br/><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code33621);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code33621>/*<br/> * Async Treeview 0.1 - Lazy-loading extension for Treeview<br/> * <br/> * <a href="http://bassistance.de/jquery-plugins/jquery-plugin-treeview/" target="_blank" rel="external">http://bassistance.de/jquery-plugins/jquery-plugin-treeview/</a><br/> *<br/> * Copyright (c) 2007 Jörn Zaefferer<br/> *<br/> * Dual licensed under the MIT and GPL licenses:<br/> *&nbsp;&nbsp; <a href="http://www.opensource.org/licenses/mit-license.php" target="_blank" rel="external">http://www.opensource.org/licenses/mit-license.php</a><br/> *&nbsp;&nbsp; <a href="http://www.gnu.org/licenses/gpl.html" target="_blank" rel="external">http://www.gnu.org/licenses/gpl.html</a><br/> *<br/> * Revision: $Id$<br/> *<br/> */<br/><br/>;(function($) {<br/><br/>function load(settings, root, child, container) {<br/>&#160;&#160;&#160;&#160;$.getJSON(settings.url, {root: root}, function(response) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;function cr&#101;ateNode(parent) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;var current = $(&#34;&lt;li/&gt;&#34;).attr(&#34;id&#34;, this.id || &#34;&#34;).html(&#34;&lt;span&gt;&#34; + this.text + &#34;&lt;/span&gt;&#34;).appendTo(parent);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:Red">if (this.url) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;current.children(&#34;span&#34;).html(&#34;&lt;a href=&#39;&#34;+this.url+&#34;&#39; target=&#39;&#34;+(this.target||&#34;_blank&#34;)+&#34;&#39;&gt;&#34;+this.text+&#34;&lt;/a&gt;&#34;); <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}</span><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if (this.classes) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;current.children(&#34;span&#34;).addClass(this.classes);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if (this.expanded) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;current.addClass(&#34;open&#34;);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if (this.hasChildren || this.children &amp;&amp; this.children.length) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;var branch = $(&#34;&lt;ul/&gt;&#34;).appendTo(current);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if (this.hasChildren) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;current.addClass(&#34;hasChildren&#34;);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cr&#101;ateNode.call({<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;text:&#34;placeholder&#34;,<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;id:&#34;placeholder&#34;,<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;children:[]<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}, branch);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if (this.children &amp;&amp; this.children.length) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$.each(this.children, cr&#101;ateNode, [branch])<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$.each(response, cr&#101;ateNode, [child]);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(container).treeview({add: child});<br/>&nbsp;&nbsp;&nbsp;&nbsp;});<br/>}<br/><br/>var proxied = $.fn.treeview;<br/>$.fn.treeview = function(settings) {<br/>&#160;&#160;&#160;&#160;if (!settings.url) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return proxied.apply(this, arguments);<br/>&#160;&#160;&#160;&#160;}<br/>&#160;&#160;&#160;&#160;var container = this;<br/>&#160;&#160;&#160;&#160;load(settings, &#34;source&#34;, this, container);<br/>&#160;&#160;&#160;&#160;var userToggle = settings.toggle;<br/>&#160;&#160;&#160;&#160;return proxied.call(this, $.extend({}, settings, {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;collapsed: true,<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;toggle: function() {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;var $this = $(this);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if ($this.hasClass(&#34;hasChildren&#34;)) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;var childList = $this.removeClass(&#34;hasChildren&#34;).find(&#34;ul&#34;);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;childList.empty();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;load(settings, this.id, childList, container);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if (userToggle) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;userToggle.apply(this, arguments);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}<br/>&#160;&#160;&#160;&#160;}));<br/>};<br/><br/>})(jQuery);</div></div><br/><strong>资源</strong><br/><br/>·官方站点：<a target="_blank" href="http://bassistance.de/jquery-plugins/jquery-plugin-treeview/" rel="external">http://bassistance.de/jquery-plugins/jquery-plugin-treeview/</a><br/>·下载地址：<a target="_blank" href="http://www.mzwu.com/pic/201001/jquery.treeview.zip" rel="external">点击下载</a>]]></description>
		</item>
		
			<item>
			<link>http://www.mzwu.com/article.asp?id=2326</link>
			<title><![CDATA[Js控制gif图片播放]]></title>
			<author>dnawo@sohu.com(dnawo)</author>
			<category><![CDATA[前台脚本]]></category>
			<pubDate>Fri,18 Dec 2009 10:30:39 +0800</pubDate>
			<guid>http://www.mzwu.com/default.asp?id=2326</guid>
		<description><![CDATA[<div class="UBBPanel"><div class="UBBTitle"><img src="http://www.mzwu.com/images/html.gif" style="margin:0px 2px -3px 0px"> HTML代码</div><div class="UBBContent"><TEXTAREA rows="8" id="temp47621"><!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank" rel="external">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>&#34;>
<html xmlns=&#34;<a href="http://www.w3.org/1999/xhtml" target="_blank" rel="external">http://www.w3.org/1999/xhtml</a>&#34;>
<head>
<meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=gb2312&#34; />
<title>Js控制gif图片播放-Mzwu.Com</title>
<script language=&#34;JavaScript&#34; type=&#34;text/javascript&#34;>
function $(id){ return document.getElementById(id); }
function Play(obj){ obj.src=obj.src; }
</script>
</head>

<body>
<img id=&#34;img1&#34; src=&#34;pic/200912/029.gif&#34; />
&amp;lt;br/&amp;gt;
<a href=&#34;javascript:Play($('img1'));&#34;>播放</a> <a href=&#34;javascript:&#34;>停止</a>
</body>
</html></TEXTAREA><br/><INPUT onclick="runEx('temp47621')"  type="button" class="userbutton" value="运行此代码"/> <INPUT onclick="doCopy('temp47621')"  type="button" class="userbutton" value="复制此代码"/> <INPUT onclick="saveCode('temp47621')" type="button" class="userbutton" value="保存此代码"><br/> [Ctrl+A 全部选择 提示：你可先修改部分代码，再按运行]</div></div><br/>IE6 only！]]></description>
		</item>
		
			<item>
			<link>http://www.mzwu.com/article.asp?id=2307</link>
			<title><![CDATA[IE7报错：拒绝访问]]></title>
			<author>dnawo@sohu.com(dnawo)</author>
			<category><![CDATA[前台脚本]]></category>
			<pubDate>Fri,27 Nov 2009 15:45:21 +0800</pubDate>
			<guid>http://www.mzwu.com/default.asp?id=2307</guid>
		<description><![CDATA[有个接口，站长使用iframe方式调用，在IE6、FF3.0、Opera9.6下均正常，但唯独IE7下报错：拒绝访问。最终发现是resizeTo语句的原因，接口中使用resizeTo来调整浏览器窗体大小，当使用window.open方式调用时脚本可以正常调整浏览器窗体大小，但使用iframe方式调用时调整失败，IE6、FF3.0、Opera9.6可以&#34;忽略&#34;这个错误，后继脚本仍能正常执行，而唯独IE7不行！<br/><br/>resizeTo.htm：<br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code12777);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code12777>&lt;html&gt;<br/>&lt;head&gt;<br/>&lt;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=gb2312&#34; /&gt;<br/>&lt;title&gt;js调整浏览器窗体大小测试-Mzwu.Com&lt;/title&gt;<br/>&lt;/head&gt;<br/><br/>&lt;body&gt;<br/>&lt;script type=&#34;text/javascript&#34;&gt;<br/>resizeTo(556,393);<br/>alert(&#34;www.mzwu.com&#34;);<br/>&lt;/script&gt;<br/>&lt;/body&gt;<br/>&lt;/html&gt;</div></div><br/><br/>调用代码：<br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code17308);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code17308>&lt;iframe src=&#34;<a href="http://code.5k3g.com/resizeTo.htm" target="_blank" rel="external">http://code.5k3g.com/resizeTo.htm</a>&#34; width=&#34;600&#34; height=&#34;600&#34; frameborder=&#34;0&#34; scrolling=&#34;no&#34;&gt;</div></div><br/>IE7报错：<br/><br/><img src="http://www.mzwu.com/pic/200911/025.gif" border="0" alt=""/>]]></description>
		</item>
		
			<item>
			<link>http://www.mzwu.com/article.asp?id=2288</link>
			<title><![CDATA[JavaScript和ActionScript函数相互调用示例]]></title>
			<author>dnawo@sohu.com(dnawo)</author>
			<category><![CDATA[前台脚本]]></category>
			<pubDate>Fri,06 Nov 2009 01:19:01 +0800</pubDate>
			<guid>http://www.mzwu.com/default.asp?id=2288</guid>
		<description><![CDATA[<strong>函数声明</strong><br/><br/><span style="color:Brown">JavaScript函数：</span><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code71492);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code71492>&lt;script language=&#34;JavaScript&#34; type=&#34;text/javascript&#34;&gt;<br/>//声明一个JavaScript方法供ActionScript调用<br/>function jsFun(username)<br/>{<br/>&#160;&#160;&#160;&#160;return &#34;jsFun: hello,&#34; + username;<br/>}<br/>&lt;/script&gt;</div></div><br/><span style="color:Brown">ActionScript函数：</span><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code6741);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code6741>stop();<br/><br/>import flash.external.*;<br/><br/>//声明一个ActionScript方法供JavaScript调用<br/>function asFun(username:String):String<br/>{<br/>&#160;&#160;&#160;&#160;return &#34;asFun: hello,&#34; + username;<br/>}<br/>ExternalInterface.addCallback(&#34;asFun&#34;,null,asFun);//注册</div></div><br/><strong>调用示例</strong><br/><br/><span style="color:Brown">JavaScript调用ActionScript方法：</span><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code996);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code996>&lt;script language=&#34;JavaScript&#34; type=&#34;text/javascript&#34;&gt;<br/>//JavaScript调用ActionScript方法<br/>function callFun(username)<br/>{<br/>&#160;&#160;&#160;&#160;var swf = document.getElementById(&#34;SWFObject&#34;);<br/>&#160;&#160;&#160;&#160;if(swf)<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return swf.asFun(username);<br/>&#160;&#160;&#160;&#160;else<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return null;<br/>}<br/>&lt;/script&gt;</div></div><br/><span style="color:Brown">ActionScript调用JavaScript方法：</span><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code44789);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code44789>//ActionScript调用JavaScript方法<br/>function callFun(username:String):String<br/>{<br/>&#160;&#160;&#160;&#160;return String(ExternalInterface.call(&#34;jsFun&#34;,username));<br/>}</div></div><br/><i>说明：若在JavaScript中获取ActionScript函数体，会得到如下内容：</i><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code86851);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code86851>function () { <br/>&nbsp;&nbsp;&nbsp;&nbsp;return eval(instance.CallFunction(&#34;&lt;invoke name=\&#34;&#34;+name+&#34;\&#34; returntype=\&#34;javascript\&#34;&gt;&#34; + __flash__argumentsToXML(arguments,0) + &#34;&lt;/invoke&gt;&#34;));<br/>&nbsp;&nbsp;}</div></div>]]></description>
		</item>
		
			<item>
			<link>http://www.mzwu.com/article.asp?id=2248</link>
			<title><![CDATA[VBScript、JavaScript判断xml节点是否存在]]></title>
			<author>dnawo@sohu.com(dnawo)</author>
			<category><![CDATA[前台脚本]]></category>
			<pubDate>Tue,29 Sep 2009 21:36:21 +0800</pubDate>
			<guid>http://www.mzwu.com/default.asp?id=2248</guid>
		<description><![CDATA[<span style="color:Brown">1).VBScript示例</span><br/><br/><div class="UBBPanel"><div class="UBBTitle"><img src="http://www.mzwu.com/images/html.gif" style="margin:0px 2px -3px 0px"> HTML代码</div><div class="UBBContent"><TEXTAREA rows="8" id="temp96464"><script type=&#34;text/vbscript&#34;>
Dim xmlDoc,node
Set xmlDoc = Cr&#101;ateObject(&#34;MSXML2.DOMDocument&#34;)
xmlDoc.loadXML(&#34;<xml><file/></xml>&#34;)
Set node = xmlDoc.sel&#101;ctSingleNode(&#34;xml/file&#34;)
If Not node is Nothing Then
	MsgBox &#34;存在 file 节点！&#34;
Else
	MsgBox &#34;不存在 file 节点！&#34;
End If
Set node = Nothing
Set xmlDoc = Nothing
</script></TEXTAREA><br/><INPUT onclick="runEx('temp96464')"  type="button" class="userbutton" value="运行此代码"/> <INPUT onclick="doCopy('temp96464')"  type="button" class="userbutton" value="复制此代码"/> <INPUT onclick="saveCode('temp96464')" type="button" class="userbutton" value="保存此代码"><br/> [Ctrl+A 全部选择 提示：你可先修改部分代码，再按运行]</div></div><br/><span style="color:Brown">2).JavaScript示例</span><br/><br/><div class="UBBPanel"><div class="UBBTitle"><img src="http://www.mzwu.com/images/html.gif" style="margin:0px 2px -3px 0px"> HTML代码</div><div class="UBBContent"><TEXTAREA rows="8" id="temp5268"><script type=&#34;text/javascript&#34;>
var xmlDoc,node
xmlDoc = new ActiveXObject(&#34;MSXML2.DOMDocument&#34;)
xmlDoc.loadXML(&#34;<xml><file/></xml>&#34;)
node = xmlDoc.sel&#101;ctSingleNode(&#34;xml/item&#34;)
if(node!=null)
	alert(&#34;存在 item 节点！&#34;)
else
	alert(&#34;不存在 item 节点！&#34;)
node = null
xmlDoc = null
</script></TEXTAREA><br/><INPUT onclick="runEx('temp5268')"  type="button" class="userbutton" value="运行此代码"/> <INPUT onclick="doCopy('temp5268')"  type="button" class="userbutton" value="复制此代码"/> <INPUT onclick="saveCode('temp5268')" type="button" class="userbutton" value="保存此代码"><br/> [Ctrl+A 全部选择 提示：你可先修改部分代码，再按运行]</div></div>]]></description>
		</item>
		
			<item>
			<link>http://www.mzwu.com/article.asp?id=2157</link>
			<title><![CDATA[将自定义对象赋值给prototype的结果]]></title>
			<author>dnawo@sohu.com(dnawo)</author>
			<category><![CDATA[前台脚本]]></category>
			<pubDate>Fri,24 Jul 2009 09:49:44 +0800</pubDate>
			<guid>http://www.mzwu.com/default.asp?id=2157</guid>
		<description><![CDATA[给构造函数添加一个方法我们通常这么做：<br/><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code31971);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code31971>function Class()<br/>{<br/>&#160;&#160;&#160;&#160;this.Name = &#34;Class&#34;;<br/>}<br/>Class.prototype.getName = function(){ return this.Name; };</div></div><br/>也有人是直接将一个自定义对象赋值给prototype：<br/><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code25304);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code25304>function Class()<br/>{<br/>&#160;&#160;&#160;&#160;this.Name = &#34;Class&#34;;<br/>}<br/>Class.prototype = {<br/>&#160;&#160;&#160;&#160;getName : function(){ return this.Name; }<br/>};</div></div><br/>暂时没发现有什么使用上的问题，但还是发现了一点不同：我们知道，原型对象默认有一个属性constructor，他指向构造函数本身，测试一下：<br/><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code92191);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code92191>function Class()<br/>{<br/>&#160;&#160;&#160;&#160;this.Name = &#34;Class&#34;;<br/>}<br/>Class.prototype.getName = function(){ return this.Name; };<br/><br/>alert(Class.prototype.constructor);</div></div><br/>结果显示：<br/><br/><div class="UBBPanel quotePanel"><div class="UBBTitle"><img src="http://www.mzwu.com/images/quote.gif" style="margin:0px 2px -3px 0px" alt="引用内容"/> 引用内容</div><div class="UBBContent">function Class()<br/>{<br/>&#160;&#160;&#160;&#160;this.Name = &#34;Class&#34;;<br/>}</div></div><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code18086);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code18086>function Class()<br/>{<br/>&#160;&#160;&#160;&#160;this.Name = &#34;Class&#34;;<br/>}<br/>Class.prototype = {<br/>&#160;&#160;&#160;&#160;getName : function(){ return this.Name; }<br/>};<br/><br/>alert(Class.prototype.constructor);</div></div><br/>结果显示：<br/><br/><div class="UBBPanel quotePanel"><div class="UBBTitle"><img src="http://www.mzwu.com/images/quote.gif" style="margin:0px 2px -3px 0px" alt="引用内容"/> 引用内容</div><div class="UBBContent">function Object() {<br/>&#160;&#160;&#160;&#160;[native code]<br/>}</div></div><br/>这和Object.prototype.constructor的结果是一样的，也就是说：<u>将自定义对象赋值给prototype后，改变了原型对象constructor属性的值，他不再是表示prototype所对应的构造函数，其值是超类(Object)的构造函数。</u>]]></description>
		</item>
		
			<item>
			<link>http://www.mzwu.com/article.asp?id=2156</link>
			<title><![CDATA[奇特的原型对象]]></title>
			<author>dnawo@sohu.com(dnawo)</author>
			<category><![CDATA[前台脚本]]></category>
			<pubDate>Fri,24 Jul 2009 08:32:26 +0800</pubDate>
			<guid>http://www.mzwu.com/default.asp?id=2156</guid>
		<description><![CDATA[&#34;构造函数prototype属性的值是一个对象，该对象即为构造函数的原型对象。添加给这个原型对象的任何属性，都会成为被构造函数所初始化的对象的属性。&#34;<br/><br/>这两句话高度概括了JavaScript构造函数的原型对象，我们来理解下：<br/><br/>·第一句说明了原型对象其实就是类的一个属性，不同于实例属性，不管创建了该类的多少个实例，他们都共享该属性；<br/>·第二句说明了一个特性：构造函数实例化对象将继承原型对象的属性；<br/><br/>所以，原型对象是放置方法和其他不变属性的理想地方！]]></description>
		</item>
		
			<item>
			<link>http://www.mzwu.com/article.asp?id=2155</link>
			<title><![CDATA[Javascript作用域原理]]></title>
			<author>dnawo@sohu.com(dnawo)</author>
			<category><![CDATA[前台脚本]]></category>
			<pubDate>Thu,23 Jul 2009 17:47:11 +0800</pubDate>
			<guid>http://www.mzwu.com/default.asp?id=2155</guid>
		<description><![CDATA[<strong>问题的提出</strong><br/><br/>首先看一个例子:<br/><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code77351);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code77351>var name = &#39;laruence&#39;;<br/>function echo() {<br/>&nbsp;&nbsp;&nbsp;&nbsp;alert(name);<br/>&nbsp;&nbsp;&nbsp;&nbsp;var name = &#39;eve&#39;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;alert(name);<br/>&nbsp;&nbsp;&nbsp;&nbsp;alert(age);<br/>}<br/> <br/>echo();</div></div><br/>运行结果是什么呢? <br/><br/>上面的问题, 我相信会有很多人会认为是:<br/><br/><div class="UBBPanel quotePanel"><div class="UBBTitle"><img src="http://www.mzwu.com/images/quote.gif" style="margin:0px 2px -3px 0px" alt="引用内容"/> 引用内容</div><div class="UBBContent">laruence<br/>eve<br/>[脚本出错]</div></div><br/>因为会以为在echo中, 第一次alert的时候, 会取到全局变量name的值, 而第二次值被局部变量name覆盖, 所以第二次alert是&#39;eve&#39;. 而age属性没有定义, 所以脚本会出错.<br/><br/>但其实, 运行结果应该是:<br/><br/><div class="UBBPanel quotePanel"><div class="UBBTitle"><img src="http://www.mzwu.com/images/quote.gif" style="margin:0px 2px -3px 0px" alt="引用内容"/> 引用内容</div><div class="UBBContent">undefined<br/>eve<br/>[脚本出错]</div></div><br/>为什么呢? <br/><br/><strong>JavaScript的作用域链</strong><br/><br/>首先让让我们来看看Javasript(简称JS, 不完全代表JScript)的作用域的原理: JS权威指南中有一句很精辟的描述:　&#34;JavaScript中的函数运行在它们被定义的作用域里,而不是它们被执行的作用域里.&#34;　<br/><br/>为了接下来的知识, 你能顺利理解, 我再提醒一下, 在JS中:&#34;一切皆是对象, 函数也是&#34;.<br/><br/>在JS中，作用域的概念和其他语言差不多， 在每次调用一个函数的时候 ，就会进入一个函数内的作用域，当从函数返回以后，就返回调用前的作用域.<br/><br/>JS的语法风格和C/C++类似, 但作用域的实现却和C/C++不同，并非用“堆栈&#34;方式，而是使用列表，具体过程如下(ECMA262中所述):<br/><br/>任何时刻的作用域, 都是有作用域链(scope chain, 后面介绍)来实现.<br/>在一个函数被定义的时候, 会将它定义时刻的scope chain链接到这个函数对象的[[scope]]属性.<br/>在一个函数对象被调用的时候， 会创建一个活动对象(也就是一个对象), 然后对于每一个函数的形参，都命名为该活动对象的命名属性, 然后将这个活动对象做为此时的作用域链(scope chain)最前端, 并将这个函数对象的[[scope]]加入到scope chain中.<br/><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code48512);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code48512>var func = function(lps, rps){<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var name = &#39;laruence&#39;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;........<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;func();</div></div><br/>在执行func的定义语句的时候, 会创建一个这个函数对象的[[scope]]属性(内部属性,只有JS引擎可以访问, 但FireFox的几个引擎(SpiderMonkey和Rhino)提供了私有属性__parent__来访问它), 并将这个[[scope]]属性, 链接到定义它的作用域链上(后面会详细介绍), 此时因为func定义在全局环境, 所以此时的[[scope]]只是指向全局活动对象window active object.<br/><br/>在调用func的时候, 会创建一个活动对象(假设为aObj, 由JS引擎预编译时刻创建, 后面会介绍)，给这个对象添加俩个命名属性aObj.lps, aObj.rps; 然后还会创建一个arguments对象，这个对象以数组的方式保存调用参数，还有callee等其他参数；然后将arguments也作为活动对象(假设为aObj)的一个同名命名属性(arguments)；还有就是，对于每一个这个函数申明，或者定义的变量，都作为该活动对象的同名命名属性。内部函数也是一样。<br/><br/>然后将调用参数赋值给形参数，对于缺少的调用参数，赋值为undefined。 <br/><br/>然后将这个活动对象做为scope chain的最前端, 并将func的[[scope]]属性所指向的,定义func时候的顶级活动对象, 加入到scope china.<br/><br/>有了上面的作用域链, 在发生标识符解析的时候, 就会逆向查询当前scope chain列表的每一个活动对象的属性，如果找到同名的就返回。找不到，那就是这个标识符没有被定义。<br/><br/>注意到, 因为函数对象的[[scope]]属性是在定义一个函数的时候决定的, 而非调用的时候, 所以如下面的例子:<br/><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code61588);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code61588>var name = &#39;laruence&#39;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;function echo() {<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(name);<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/> <br/>&nbsp;&nbsp;&nbsp;&nbsp;function env() {<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var name = &#39;eve&#39;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo();<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/> <br/>&nbsp;&nbsp;&nbsp;&nbsp;env();</div></div><br/>运行结果是:<br/><br/><div class="UBBPanel quotePanel"><div class="UBBTitle"><img src="http://www.mzwu.com/images/quote.gif" style="margin:0px 2px -3px 0px" alt="引用内容"/> 引用内容</div><div class="UBBContent">laruence</div></div><br/>结合上面的知识, 我们来看看下面这个例子:<br/><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code75474);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code75474>function factory() {<br/>&nbsp;&nbsp;&nbsp;&nbsp;var name = &#39;laruence&#39;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;var intro = function(){<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&#39;I am &#39; + name);<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;return intro;<br/>}<br/> <br/>function app(para){<br/>&nbsp;&nbsp;&nbsp;&nbsp;var name = para;<br/>&nbsp;&nbsp;&nbsp;&nbsp;var func = factory();<br/>&nbsp;&nbsp;&nbsp;&nbsp;func();<br/>}<br/> <br/>app(&#39;eve&#39;);</div></div><br/>当调用app的时候, scope chain是由: {window活动对象(全局)}-&gt;{app的活动对象} 组成. <br/><br/>在刚进入app函数体时, app的活动对象有一个arguments属性, 俩个值为undefined的属性: name和func. 和一个值为&#39;eve&#39;的属性para;<br/><br/>此时的scope chain如下:<br/><br/><div class="UBBPanel quotePanel"><div class="UBBTitle"><img src="http://www.mzwu.com/images/quote.gif" style="margin:0px 2px -3px 0px" alt="引用内容"/> 引用内容</div><div class="UBBContent">[[scope chain]] = [<br/>{ <br/>&nbsp;&nbsp;&nbsp;&nbsp;para : &#39;eve&#39;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;name : undefined,<br/>&nbsp;&nbsp;&nbsp;&nbsp;func : undefined,<br/>&nbsp;&nbsp;&nbsp;&nbsp;arguments : []<br/>}, {<br/>&nbsp;&nbsp;&nbsp;&nbsp;window call object <br/>}<br/>]</div></div><br/>当调用进入factory的函数体的时候, 此时的factory的scope chain为:<br/><br/><div class="UBBPanel quotePanel"><div class="UBBTitle"><img src="http://www.mzwu.com/images/quote.gif" style="margin:0px 2px -3px 0px" alt="引用内容"/> 引用内容</div><div class="UBBContent">[[scope chain]] = [<br/>{ <br/>&nbsp;&nbsp;&nbsp;&nbsp;name : undefined,<br/>&nbsp;&nbsp;&nbsp;&nbsp;intor : undefined<br/>}, {<br/>&nbsp;&nbsp;&nbsp;&nbsp;window call object <br/>}<br/>]</div></div><br/>注意到, 此时的作用域链中, 并不包含app的活动对象.<br/><br/>在定义intro函数的时候, intro函数的[[scope]]为:<br/><br/><div class="UBBPanel quotePanel"><div class="UBBTitle"><img src="http://www.mzwu.com/images/quote.gif" style="margin:0px 2px -3px 0px" alt="引用内容"/> 引用内容</div><div class="UBBContent">[[scope chain]] = [<br/>{ <br/>&nbsp;&nbsp;&nbsp;&nbsp;name : &#39;laruence&#39;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;intor : undefined<br/>}, {<br/>&nbsp;&nbsp;&nbsp;&nbsp;window call object <br/>}<br/>]</div></div><br/>从factory函数返回以后,在app体内调用intor的时候, 发生了标识符解析, 而此时的sope chain是:<br/><br/><div class="UBBPanel quotePanel"><div class="UBBTitle"><img src="http://www.mzwu.com/images/quote.gif" style="margin:0px 2px -3px 0px" alt="引用内容"/> 引用内容</div><div class="UBBContent">[[scope chain]] = [<br/>{<br/>&nbsp;&nbsp;&nbsp;&nbsp;intro call object<br/>}, { <br/>&nbsp;&nbsp;&nbsp;&nbsp;name : &#39;laruence&#39;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;intor : undefined<br/>}, {<br/>&nbsp;&nbsp;&nbsp;&nbsp;window call object <br/>}<br/>]</div></div><br/>因为scope chain中,并不包含factory活动对象. 所以, name标识符解析的结果应该是factory活动对象中的name属性, 也就是&#39;laruence&#39;.<br/><br/>所以运行结果是:<br/><br/><div class="UBBPanel quotePanel"><div class="UBBTitle"><img src="http://www.mzwu.com/images/quote.gif" style="margin:0px 2px -3px 0px" alt="引用内容"/> 引用内容</div><div class="UBBContent">I am laruence</div></div><br/>现在, 大家对&#34;JavaScript中的函数运行在它们被定义的作用域里,而不是它们被执行的作用域里.&#34;这句话, 应该有了个全面的认识了吧? <br/><br/><strong>Javascript的预编译</strong><br/><br/>我们都知道,JS是一种脚本语言, JS的执行过程, 是一种翻译执行的过程.<br/>那么JS的执行中, 有没有类似编译的过程呢?<br/><br/>首先, 我们来看一个例子:<br/><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code7259);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code7259>&lt;script&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;alert(typeof eve); //function<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function eve() {<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&#39;I am Laruence&#39;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/script&gt;</div></div><br/>诶? 在alert的时候, eve不是应该还是未定义的么? 怎么eve的类型还是function呢?<br/><br/>恩, 对, 在JS中, 是有预编译的过程的, JS在执行每一段JS代码之前, 都会首先处理var关键字和function定义式(函数定义式和函数表达式).<br/>也就是, 在执行之前, 会首先创建一个当前作用域的活动对象, 然后将当前作用域内的变量名定义为当前活动对象的属性,<br/>,而值会在真正执行的时候才计算, 此时只是简单的赋为undefined. <br/><br/>而对于函数的定义,是一个要注意的地方: <br/><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code58789);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code58789>&lt;script&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;alert(typeof eve); //结果:function<br/>&nbsp;&nbsp;&nbsp;&nbsp;alert(typeof walle); //结果:undefined<br/>&nbsp;&nbsp;&nbsp;&nbsp;function eve() { //函数定义式<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&#39;I am Laruence&#39;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;};<br/>&nbsp;&nbsp;&nbsp;&nbsp;var walle = function() { //函数表达式<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;alert(typeof walle); //结果:function<br/>&lt;/script&gt;</div></div><br/>这就是函数定义式和函数表达式的不同, 对于函数定义式, 会将函数定义提前. 而函数表达式, 会在执行过程中才计算.<br/><br/>说到这里, 顺便说一个问题 :<br/><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code57316);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code57316>var name = &#39;laruence&#39;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;age = 26;</div></div><br/>我们都知道不使用var关键字定义的变量, 相当于是全局变量, 联系到我们刚才的知识:<br/><br/>在对age做标识符解析的时候, 因为是写操作, 所以当找到到全局的window活动对象的时候都没有找到这个标识符的时候, 会在window活动对象的基础上, 返回一个值为undefined的age属性.<br/><br/>也就是说, age会被定义在顶级作用域中.<br/><br/>现在, 也许你注意到了我刚才说的: JS在执行每一段JS代码..<br/>对, 让我们看看下面的例子:<br/><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code88292);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code88292>&lt;script&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;alert(typeof eve); //结果:undefined<br/>&lt;/script&gt;<br/>&lt;script&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;function eve() {<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&#39;I am Laruence&#39;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&lt;/script&gt;</div></div><br/>明白了么? 也就是JS的预编译是以段为处理单元的… <br/><br/><strong>揭开谜底</strong><br/><br/>现在让我们回到我们的第一个问题:<br/><br/>当echo函数被调用的时候, echo的活动对象已经被预编译过程创建, 此时echo的活动对象为:<br/><br/><div class="UBBPanel quotePanel"><div class="UBBTitle"><img src="http://www.mzwu.com/images/quote.gif" style="margin:0px 2px -3px 0px" alt="引用内容"/> 引用内容</div><div class="UBBContent">[callObj] = {<br/>name : undefined<br/>}</div></div><br/>当第一次alert的时候, 发生了标识符解析, 在echo的活动对象中找到了name属性, 所以这个name属性, 完全的遮挡了全局活动对象中的name属性.<br/><br/>现在你明白了吧?]]></description>
		</item>
		
			<item>
			<link>http://www.mzwu.com/article.asp?id=2154</link>
			<title><![CDATA[apply 高级应用]]></title>
			<author>dnawo@sohu.com(dnawo)</author>
			<category><![CDATA[前台脚本]]></category>
			<pubDate>Wed,22 Jul 2009 19:06:06 +0800</pubDate>
			<guid>http://www.mzwu.com/default.asp?id=2154</guid>
		<description><![CDATA[<span style="color:Brown">1.实现类&#34;继承&#34;(将一个类的成员复制给一个对象)</span><br/><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code98019);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code98019>function Rectangle()<br/>{<br/>&#160;&#160;&#160;&#160;this.width = 0;<br/>&#160;&#160;&#160;&#160;this.height = 0;<br/>&#160;&#160;&#160;&#160;this.area = function(){ return this.width * this.height;};<br/>}<br/><br/>var o = new Object();<br/>Rectangle.apply(o);<br/>o.width = 10;<br/>o.height = 20;<br/>alert(o.area());</div></div><br/>调用apply时，o对象就是Rectangle函数中this的值，因而实现了属性的复制。<br/><br/><span style="color:Brown">2.给类设置初始化函数</span><br/><br/><div class="UBBPanel codePanel"><div class="UBBTitle"><a onClick="copycode(code52089);" style="float:right;cursor: pointer;font-weight: normal; font-style: normal">复制内容到剪贴板</a><img src="http://www.mzwu.com/images/code.gif" style="margin:0px 2px -3px 0px;" alt="程序代码"/> 程序代码</div><div class="UBBContent" id=code52089>var Class = {<br/>&#160;&#160;&#160;&#160;cr&#101;ate : function(){<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return function(){<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;this.initialize.apply(this,arguments);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}<br/>&#160;&#160;&#160;&#160;}<br/>}<br/><br/>//创建类<br/>var Rectangle = Class.cr&#101;ate();<br/>Rectangle.prototype = {<br/>&#160;&#160;&#160;&#160;initialize : function(width,height){<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;this.width = width;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;this.height = height;<br/>&#160;&#160;&#160;&#160;},<br/>&#160;&#160;&#160;&#160;toString : function(){<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return &#34;width:&#34; + this.width + &#34;\r\n&#34; + &#34;height:&#34; + this.height;<br/>&#160;&#160;&#160;&#160;}<br/>}<br/><br/>//实例化对象并初始化<br/>var rectangle = new Rectangle(80,120);<br/>alert(rectangle.toString());</div></div>]]></description>
		</item>
		
</channel>
</rss>
