﻿<?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>BlogJava-庄周梦蝶，孰蝶是我，我是孰蝶？一梦至今，蝶我已难分-随笔分类-web开发</title><link>http://www.blogjava.net/killme2008/category/19798.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 08 Jan 2008 11:02:22 GMT</lastBuildDate><pubDate>Tue, 08 Jan 2008 11:02:22 GMT</pubDate><ttl>60</ttl><item><title>介绍下smartclient</title><link>http://www.blogjava.net/killme2008/archive/2008/01/08/173663.html</link><dc:creator>dennis</dc:creator><author>dennis</author><pubDate>Tue, 08 Jan 2008 07:48:00 GMT</pubDate><guid>http://www.blogjava.net/killme2008/archive/2008/01/08/173663.html</guid><wfw:comment>http://www.blogjava.net/killme2008/comments/173663.html</wfw:comment><comments>http://www.blogjava.net/killme2008/archive/2008/01/08/173663.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/killme2008/comments/commentRss/173663.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/killme2008/services/trackbacks/173663.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp; <a href="http://www.smartclient.com/">smartclient</a>是一个企业级的ajax框架，包括非常出色的UI库、工具库和客户端服务端数据绑定等功能。smartclient本来是一个商业产品，
2007年11月7号才以LGPL协议开源。除了一些所见即所得的构建工具和企业级的可选组件外，其他都开源了。这个记的javaeye和infoq都有报道。<br />
&nbsp;&nbsp;&nbsp; 在接触smartclient以前，我还没有使用过类似的ajax ui库，比如现在很火的ext。smartclient给我的第一印象是非常漂亮的ui效果，有兴趣可以去它的官方<a href="http://www.smartclient.com/featureExplorer.jsp">demo</a>看看。smartclient的demo和文档做的非常出色，入手开发也非常容易。<br />
第一步：<a href="http://www.smartclient.com/product/download.jsp">下载LGPL版本</a>，并解压缩<br />
第二步：运行解压后目录下的\SmartClient_60_LGPL\smartclientSDK\start_embedded_server.bat，SDK自带了一个内嵌的tomcat<br />
第三步：访问 http://localhost:8080<br />
<br />
你将见到：<br />
<img src="http://www.blogjava.net/images/blogjava_net/killme2008/smartclient.jpg" alt="" border="0" /><br />
<br />
这些demo本身就是用smartclient制作的。开发过程中你需要做就是查看examples和文档中的reference（api文档），基本没有解决不了的问题。<br />
<br />
人见人爱的Hello World例子：<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">isc.Label.create({<br />
&nbsp;&nbsp;&nbsp;&nbsp;height:&nbsp;</span><span style="color: #000000;">50</span><span style="color: #000000;">,<br />
&nbsp;&nbsp;&nbsp;&nbsp;styleName:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">helloWorldText</span><span style="color: #000000;">"</span><span style="color: #000000;">,<br />
&nbsp;&nbsp;&nbsp;&nbsp;padding:&nbsp;</span><span style="color: #000000;">4</span><span style="color: #000000;">,<br />
&nbsp;&nbsp;&nbsp;&nbsp;backgroundColor:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">#ffffd0</span><span style="color: #000000;">"</span><span style="color: #000000;">,<br />
&nbsp;&nbsp;&nbsp;&nbsp;align:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">center</span><span style="color: #000000;">"</span><span style="color: #000000;">,<br />
&nbsp;&nbsp;&nbsp;&nbsp;valign:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">center</span><span style="color: #000000;">"</span><span style="color: #000000;">,<br />
&nbsp;&nbsp;&nbsp;&nbsp;wrap:&nbsp;</span><span style="color: #0000ff;">false</span><span style="color: #000000;">,<br />
&nbsp;&nbsp;&nbsp;&nbsp;showEdges:&nbsp;</span><span style="color: #0000ff;">true</span><span style="color: #000000;">,<br />
&nbsp;&nbsp;&nbsp;&nbsp;showShadow:&nbsp;</span><span style="color: #0000ff;">true</span><span style="color: #000000;">,<br />
&nbsp;&nbsp;&nbsp;&nbsp;contents:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">Hello&nbsp;world!</span><span style="color: #000000;">"</span><span style="color: #000000;"><br />
})<br />
</span></div>
<br />
效果：<br />
<img src="http://www.blogjava.net/images/blogjava_net/killme2008/smartclient2.jpg" alt="" border="0" /><br />
<br />
&nbsp;&nbsp;&nbsp; smartclient除了完整的UI组件，还包括丰富的动态效果库以及可选的皮肤等高级主题，不再展开了，毕竟贴图是在是挺麻烦的事情：）还不如有兴趣的自己翻demo。说了这么多优点，那么缺点是啥？你可能猜到了，性能！所有js UI库无法避免的问题，不过我没有其他UI库的使用经验，倒是不能给出个比较数据。我们写的东西的性能也只是堪堪能够接受。<br />
&nbsp;&nbsp; smartclient跟dwr可以说是天生一对，smartclient UI组件的数据源可以是xml也可以是json，如果采用json做交换格式，可以与dwr无缝结合，真正实现One Page,One Application（我们就是这样做的^_^)。<br />
<br />
<br />
<br />
<br />
<br />
<br /><img src ="http://www.blogjava.net/killme2008/aggbug/173663.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/killme2008/" target="_blank">dennis</a> 2008-01-08 15:48 <a href="http://www.blogjava.net/killme2008/archive/2008/01/08/173663.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Flex is open sourced!</title><link>http://www.blogjava.net/killme2008/archive/2007/04/26/113848.html</link><dc:creator>dennis</dc:creator><author>dennis</author><pubDate>Thu, 26 Apr 2007 09:02:00 GMT</pubDate><guid>http://www.blogjava.net/killme2008/archive/2007/04/26/113848.html</guid><wfw:comment>http://www.blogjava.net/killme2008/comments/113848.html</wfw:comment><comments>http://www.blogjava.net/killme2008/archive/2007/04/26/113848.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.blogjava.net/killme2008/comments/commentRss/113848.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/killme2008/services/trackbacks/113848.html</trackback:ping><description><![CDATA[官方消息：http://labs.adobe.com/wiki/index.php/Flex:Open_Source
<br><br>Flex向微软WPF开战的新起点。正如预期的那样，Adobe决定flex在Mozilla Public License (MPL)协议下纳入开源社区，flex的前景很值的期待。<br><br> <img src ="http://www.blogjava.net/killme2008/aggbug/113848.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/killme2008/" target="_blank">dennis</a> 2007-04-26 17:02 <a href="http://www.blogjava.net/killme2008/archive/2007/04/26/113848.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>jQuery使用手册（收藏）</title><link>http://www.blogjava.net/killme2008/archive/2007/04/19/111927.html</link><dc:creator>dennis</dc:creator><author>dennis</author><pubDate>Thu, 19 Apr 2007 05:51:00 GMT</pubDate><guid>http://www.blogjava.net/killme2008/archive/2007/04/19/111927.html</guid><wfw:comment>http://www.blogjava.net/killme2008/comments/111927.html</wfw:comment><comments>http://www.blogjava.net/killme2008/archive/2007/04/19/111927.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/killme2008/comments/commentRss/111927.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/killme2008/services/trackbacks/111927.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;&nbsp; 一直使用prototype.js，因为prototype的风格与ruby相似，用起来很舒服；这两天抽空看看jQuery，也是个很优秀的js基础库，特别是在选择器方面，相当实用。转自：http://www.cnblogs.com/skylaugh/archive/2006/12/18/595563.html翻译整理：Young.J官方网站：http://jq...&nbsp;&nbsp;<a href='http://www.blogjava.net/killme2008/archive/2007/04/19/111927.html'>阅读全文</a><img src ="http://www.blogjava.net/killme2008/aggbug/111927.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/killme2008/" target="_blank">dennis</a> 2007-04-19 13:51 <a href="http://www.blogjava.net/killme2008/archive/2007/04/19/111927.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>传统javascript事件模型实现观察者模式</title><link>http://www.blogjava.net/killme2008/archive/2007/03/16/104150.html</link><dc:creator>dennis</dc:creator><author>dennis</author><pubDate>Fri, 16 Mar 2007 01:19:00 GMT</pubDate><guid>http://www.blogjava.net/killme2008/archive/2007/03/16/104150.html</guid><wfw:comment>http://www.blogjava.net/killme2008/comments/104150.html</wfw:comment><comments>http://www.blogjava.net/killme2008/archive/2007/03/16/104150.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/killme2008/comments/commentRss/104150.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/killme2008/services/trackbacks/104150.html</trackback:ping><description><![CDATA[    在W3C新的事件模型框架中，IE和Mozilla都实现了相应的版本，IE的是attachEvent和detachEvent来实现元素事件的添加和删除，而Mozilla则是标准的addEventListener和 removeEventListener。在传统的javascript事件模型中，我们没办法为一个页面元素注册多个事件，只有靠自己来实现观察者模式。代码来自《ajax in action》,我添加了注释<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">命名空间</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> jsEvent </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Array();<br /><br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">构造函数</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">jsEvent.EventRouter </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(el,eventType){<br /> </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">内部维护一个事件列表</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.lsnrs </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Array();<br /> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.el </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> el;<br /> el.eventRouter </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">;<br /> </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">注册回调函数</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);"> el[eventType] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> jsEvent.EventRouter.callback;<br />};<br /><br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">添加事件</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">jsEvent.EventRouter.prototype.addListener </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(lsnr){<br /> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.lsnrs.append(lsnr,</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">); <br />} ;<br /><br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">移除事件</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">jsEvent.EventRouter.prototype.removeListener</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(lsnr){ <br /></span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.lsnrs.remove(lsnr); <br />}; <br /><br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">通知所有事件</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">jsEvent.EventRouter.prototype.notify </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(e){<br /> </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> lsnrs </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.lsnrs;<br /> </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> i</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;i</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">lsnrs.length;i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">){<br />  </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> lsnr </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> lsnrs[i];<br />  lsnr.call(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">,e);<br /> }<br />};<br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">回调函数调用notify</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">jsEvent.EventRouter.callback</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(event){<br /> </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> e </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> event </span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);"> window.event;<br /> </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> router </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.eventRouter;<br /> router.notify(e);<br />};<br /><br />Array.prototype.append </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(obj,nodup){<br /> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(nodup){ <br />  </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">[</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.length]</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">obj;<br /> }<br />};<br />Array.prototype.remove </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(o)<br />{<br />   </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> i </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.indexOf(o);<br />   </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (i</span><span style="color: rgb(0, 0, 0);">&gt;-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">)<br />  {<br />    </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.splice(i,</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);<br />   }<br />     </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> (i</span><span style="color: rgb(0, 0, 0);">&gt;-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);<br />   }  <br />}; <br /></span></div><br />这里比较巧妙的就是<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 0);"> el.eventRouter </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">注册回调函数</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);"> el[eventType] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> jsEvent.EventRouter.callback;<br /><br />首先给el元素添加属性</span><span style="color: rgb(0, 0, 0);">eventRouter是当前的EventRouter对象，然后</span><span style="color: rgb(0, 0, 0);">，比如eventType假设为onclick，el是一个button元素，那么这里就是el[</span><span style="color: rgb(0, 0, 0);">onclick]=</span><span style="color: rgb(0, 0, 0);">jsEvent.EventRouter.callback;相当于el.onclick=</span><span style="color: rgb(0, 0, 0);">jsEvent.EventRouter.callback;<br />而请注意这个回调函数</span><span style="color: rgb(0, 0, 0);">callback将首先得到元素的</span><span style="color: rgb(0, 0, 0);">eventRouter对象，再调用此对象的notify方法触发所有注册的事件。<br /><br />再请注意notify函数里面这一行：<br /></span><span style="color: rgb(0, 0, 0);"> lsnr.call(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">,e);<br /><br />我们把event对象传入此函数作参，而</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> e </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> event </span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);"> window.event;那么所有事件函数的第一个参数都将是event对象，避免了IE需要通过window.event得到的事件对象的浏览器不一致行为。<br /><br />使用此对象方式：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">　</span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> mat</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">document.getElementById('mousemat');<br />　　cursor</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">document.getElementById('cursor');<br />　　</span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> mouseRouter</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> jsEvent.EventRouter(mat,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">onmousemove</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />　　mouseRouter.addListener(writeStatus);<br />　　mouseRouter.addListener(drawThumbnail); </span></div><br /></span><span style="color: rgb(0, 0, 0);"></span><br /><span id="Codehighlighter1_43_1006_Open_Text"><span style="color: rgb(0, 128, 0);"></span></span><img src ="http://www.blogjava.net/killme2008/aggbug/104150.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/killme2008/" target="_blank">dennis</a> 2007-03-16 09:19 <a href="http://www.blogjava.net/killme2008/archive/2007/03/16/104150.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ajax技术再思考</title><link>http://www.blogjava.net/killme2008/archive/2007/03/14/103857.html</link><dc:creator>dennis</dc:creator><author>dennis</author><pubDate>Wed, 14 Mar 2007 10:56:00 GMT</pubDate><guid>http://www.blogjava.net/killme2008/archive/2007/03/14/103857.html</guid><wfw:comment>http://www.blogjava.net/killme2008/comments/103857.html</wfw:comment><comments>http://www.blogjava.net/killme2008/archive/2007/03/14/103857.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/killme2008/comments/commentRss/103857.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/killme2008/services/trackbacks/103857.html</trackback:ping><description><![CDATA[    近几日重读《ajax实战》，对AJAX技术的理解有点改变。当ajax开始火热的时候，其实那时我呆的那家公司早在02年时就已经开始用XmlHttpRequest做前后台的异步通信，因为做的是内部网应用，通过统一安装一个delphi写ActiveX表格控件来进行数据的展现和报表的打印，使用xml作为前后台交换数据的格式。所以当ajax技术开始火热的时候，我以为，我所做的就是ajax应用。买了《ajax实战》，读的也不深入，特别是前面几个章节读的半懂不懂，因为那时的我对javascript和设计模式等方面还没有深入系统的学习过。<br /><br />    我们都知道ajax是javascript、css、DOM和XmlHttpRequest的结合体，可使用了这些技术的应用就一定是ajax吗？《ajax实战》提出了衡量是否是ajax应用的四条标准：<br /><br />1 浏览器中的是应用，而不是内容；<br />2 服务器交付的是数据，而不是内容；<br />3 用户和应用的交互是连续的，大部分对于服务器的请求是隐式的而不是显式的；<br />4 代码库式巨大的、复杂的，而且式组织良好的，这个特点对于架构来说非常重要，需要认真对待。<br /><br />如果以这样的标准衡量，其实我们的很多自以为是ajax应用并非是严格意义上的ajax应用，软件的应用可以划分为瞬态的和独占的，比如china-pub网站，这只是个瞬态应用，我们只是偶尔去访问它，对交互的连续性也没有很强的要求；而另外如word、excel之类的应用，需要持续不断的交互，我们点下某个按钮，总是期待能马上有个效果出来，这样的应用就是所谓的独占应用。ajax技术已经在很广泛的瞬态应用中实施，而ajax的趋势是否就是独占式应用？gmail和google map给出了答案，以及现在比较火热的web office等。可我对于此类应用的前景并不看好，像word之类的应用，对于实时性和安全性的要求是比较高的，而当前网络环境下的延迟和安全问题，会给此类应用带来相当大的隐忧。而实现这样的独占式应用，带来的也是服务器非常巨大的并发量，gmail就是个典型的例子，当你操作非常频繁的时候，容易出现莫名其妙的错误。<br /><br />    我仍然认为ajax应该成为目前web应用的润滑剂，它应该应用在细节上改善用户体验上，而非彻底取代桌面应用，也不可能取代。<br /><img src ="http://www.blogjava.net/killme2008/aggbug/103857.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/killme2008/" target="_blank">dennis</a> 2007-03-14 18:56 <a href="http://www.blogjava.net/killme2008/archive/2007/03/14/103857.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>备忘——javascript操作表格排序</title><link>http://www.blogjava.net/killme2008/archive/2007/03/10/103009.html</link><dc:creator>dennis</dc:creator><author>dennis</author><pubDate>Sat, 10 Mar 2007 09:26:00 GMT</pubDate><guid>http://www.blogjava.net/killme2008/archive/2007/03/10/103009.html</guid><wfw:comment>http://www.blogjava.net/killme2008/comments/103009.html</wfw:comment><comments>http://www.blogjava.net/killme2008/archive/2007/03/10/103009.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/killme2008/comments/commentRss/103009.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/killme2008/services/trackbacks/103009.html</trackback:ping><description><![CDATA[表格排序，一般的处理方法是传递排序的字段到后台进行重新查询并排序，javascript也可以做到简单的表格排序，备忘代码：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 0);">           //类型</span><span style="color: rgb(0, 128, 0);">转换器，将列的字段类型转换为可以排序的类型：String,int,float</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> convert(sValue, sDataType) {<br />                </span><span style="color: rgb(0, 0, 255);">switch</span><span style="color: rgb(0, 0, 0);">(sDataType) {<br />                    </span><span style="color: rgb(0, 0, 255);">case</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">int</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">:<br />                        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> parseInt(sValue);<br />                    </span><span style="color: rgb(0, 0, 255);">case</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">float</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">:<br />                        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> parseFloat(sValue);<br />                    </span><span style="color: rgb(0, 0, 255);">case</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">date</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">:<br />                        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Date(Date.parse(sValue));<br />                    </span><span style="color: rgb(0, 0, 255);">default</span><span style="color: rgb(0, 0, 0);">:<br />                        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> sValue.toString();<br />                <br />                }<br />            }<br />            <br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">排序函数产生器，iCol表示列索引，sDataType表示该列的数据类型</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> generateCompareTRs(iCol, sDataType) {<br />        <br />                </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> compareTRs(oTR1, oTR2) {<br />                            </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> vValue1 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> convert(oTR1.cells[iCol].firstChild.nodeValue, sDataType);<br />                            </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> vValue2 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> convert(oTR2.cells[iCol].firstChild.nodeValue, sDataType);<br />        <br />                            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (vValue1 </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> vValue2) {<br />                                </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;<br />                            } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (vValue1 </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> vValue2) {<br />                                </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;<br />                            } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br />                                </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />                            }<br />                        };<br />            }<br />            <br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">排序方法</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> sortTable(sTableID, iCol, sDataType) {<br />                </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> oTable </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> document.getElementById(sTableID);<br />                </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> oTBody </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> oTable.tBodies[</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">];<br />                </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> colDataRows </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> oTBody.rows;<br />                </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> aTRs </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Array;<br />                <br />                </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">将所有列放入数组</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> i</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">; i </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> colDataRows.length; i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">) {<br />                    aTRs[i] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> colDataRows[i];<br />                }<br />                 <br />                </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">判断最后一次排序的列是否与现在要进行排序的列相同，是的话，直接使用reverse()逆序</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (oTable.sortCol </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> iCol) {<br />                    aTRs.reverse();<br />                } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br />                    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">使用数组的sort方法，传进排序函数</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                    aTRs.sort(generateCompareTRs(iCol, sDataType));<br />                }<br />        <br />                </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> oFragment </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> document.createDocumentFragment();<br />                </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> i</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">; i </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> aTRs.length; i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">) {<br />                    oFragment.appendChild(aTRs[i]);<br />                }<br />       <br />                oTBody.appendChild(oFragment);<br />                </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">记录最后一次排序的列索引</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                oTable.sortCol </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> iCol;<br />            }<br /></span></div><br />完整例子：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">html</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">head</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">title</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Table Sort Example</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">title</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">script type</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">text/javascript</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            <br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">转换器，将列的字段类型转换为可以排序的类型：String,int,float</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> convert(sValue, sDataType) {<br />                </span><span style="color: rgb(0, 0, 255);">switch</span><span style="color: rgb(0, 0, 0);">(sDataType) {<br />                    </span><span style="color: rgb(0, 0, 255);">case</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">int</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">:<br />                        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> parseInt(sValue);<br />                    </span><span style="color: rgb(0, 0, 255);">case</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">float</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">:<br />                        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> parseFloat(sValue);<br />                    </span><span style="color: rgb(0, 0, 255);">case</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">date</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">:<br />                        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Date(Date.parse(sValue));<br />                    </span><span style="color: rgb(0, 0, 255);">default</span><span style="color: rgb(0, 0, 0);">:<br />                        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> sValue.toString();<br />                <br />                }<br />            }<br />            <br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">排序函数产生器，iCol表示列索引，sDataType表示该列的数据类型</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> generateCompareTRs(iCol, sDataType) {<br />        <br />                </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> compareTRs(oTR1, oTR2) {<br />                            </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> vValue1 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> convert(oTR1.cells[iCol].firstChild.nodeValue, sDataType);<br />                            </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> vValue2 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> convert(oTR2.cells[iCol].firstChild.nodeValue, sDataType);<br />        <br />                            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (vValue1 </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> vValue2) {<br />                                </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;<br />                            } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (vValue1 </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> vValue2) {<br />                                </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;<br />                            } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br />                                </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />                            }<br />                        };<br />            }<br />            <br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">排序方法</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> sortTable(sTableID, iCol, sDataType) {<br />                </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> oTable </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> document.getElementById(sTableID);<br />                </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> oTBody </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> oTable.tBodies[</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">];<br />                </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> colDataRows </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> oTBody.rows;<br />                </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> aTRs </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Array;<br />                <br />                </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">将所有列放入数组</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> i</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">; i </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> colDataRows.length; i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">) {<br />                    aTRs[i] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> colDataRows[i];<br />                }<br />                 <br />                </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">判断最后一次排序的列是否与现在要进行排序的列相同，是的话，直接使用reverse()逆序</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (oTable.sortCol </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> iCol) {<br />                    aTRs.reverse();<br />                } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br />                    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">使用数组的sort方法，传进排序函数</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                    aTRs.sort(generateCompareTRs(iCol, sDataType));<br />                }<br />        <br />                </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> oFragment </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> document.createDocumentFragment();<br />                </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> i</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">; i </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> aTRs.length; i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">) {<br />                    oFragment.appendChild(aTRs[i]);<br />                }<br />       <br />                oTBody.appendChild(oFragment);<br />                </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">记录最后一次排序的列索引</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                oTable.sortCol </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> iCol;<br />            }<br /><br />        </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">script</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">head</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">body</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">p</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Click on the table header to sort </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> ascending order.</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">p</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">table border</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> id</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">tblSort</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">thead</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">th onclick</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">sortTable('tblSort', 0)</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> <br />                        style</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">cursor:pointer</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Last Name</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">th</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">th onclick</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">sortTable('tblSort', 1)</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> <br />                        style</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">cursor:pointer</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">First Name</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">th</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">th onclick</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">sortTable('tblSort', 2, 'date')</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> <br />                        style</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">cursor:pointer</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Birthday</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">th</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">th onclick</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">sortTable('tblSort', 3, 'int')</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> <br />                        style</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">cursor:pointer</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Siblings</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">th</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">thead</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">tbody</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Smith</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">John</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">7</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">12</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">1978</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Johnson</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Betty</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">10</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">15</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">1977</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Henderson</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Nathan</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">25</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">1949</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Williams</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">James</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">7</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">8</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">1980</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Gilliam</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Michael</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">7</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">22</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">1949</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Walker</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Matthew</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">14</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">2000</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">td</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">tr</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">tbody</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">table</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">        <br />    </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">body</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">html</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span></div><br /><img src ="http://www.blogjava.net/killme2008/aggbug/103009.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/killme2008/" target="_blank">dennis</a> 2007-03-10 17:26 <a href="http://www.blogjava.net/killme2008/archive/2007/03/10/103009.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>javascript之XML DOM对象</title><link>http://www.blogjava.net/killme2008/archive/2007/03/09/102748.html</link><dc:creator>dennis</dc:creator><author>dennis</author><pubDate>Fri, 09 Mar 2007 02:21:00 GMT</pubDate><guid>http://www.blogjava.net/killme2008/archive/2007/03/09/102748.html</guid><wfw:comment>http://www.blogjava.net/killme2008/comments/102748.html</wfw:comment><comments>http://www.blogjava.net/killme2008/archive/2007/03/09/102748.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/killme2008/comments/commentRss/102748.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/killme2008/services/trackbacks/102748.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: javacript中对xml dom的支持，与其他任何特性一样面临着浏览器兼容问题。一 IE中的XML DOM1.微软通过ActiveX的MSXML库提供了支持，通过：Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> var oXmlDom = new...&nbsp;&nbsp;<a href='http://www.blogjava.net/killme2008/archive/2007/03/09/102748.html'>阅读全文</a><img src ="http://www.blogjava.net/killme2008/aggbug/102748.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/killme2008/" target="_blank">dennis</a> 2007-03-09 10:21 <a href="http://www.blogjava.net/killme2008/archive/2007/03/09/102748.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oh,my god.我终于能看懂正则表达式咯</title><link>http://www.blogjava.net/killme2008/archive/2007/03/07/102323.html</link><dc:creator>dennis</dc:creator><author>dennis</author><pubDate>Wed, 07 Mar 2007 01:54:00 GMT</pubDate><guid>http://www.blogjava.net/killme2008/archive/2007/03/07/102323.html</guid><wfw:comment>http://www.blogjava.net/killme2008/comments/102323.html</wfw:comment><comments>http://www.blogjava.net/killme2008/archive/2007/03/07/102323.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/killme2008/comments/commentRss/102323.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/killme2008/services/trackbacks/102323.html</trackback:ping><description><![CDATA[    最近一直在读《javascript高级程序设计》的正则表达式章节，终于对我一直搞不明白的正则表达式开始有点感觉了，别人写的表达式基本也能看懂了，可要自己熟练地写还需要多多练习。推荐一个学习正则表达式的地方，javaeye的<a href="http://www.javaeye.com/subject/Regular-Expression">正则表达式专栏</a>以及<a href="http://www.regexlab.com/zh/">正则表达式工作室</a>。<br /><br />常用正则表达式，掌握了规则，看懂这些表达式并不困难，当然，要达到熟练写的程度就不那么容易了。<br /><br /><p>匹配中文字符的正则表达式： [\u4e00-\u9fa5]</p><p>匹配双字节字符(包括汉字在内)：[^\x00-\xff]</p><p>应用：计算字符串的长度（一个双字节字符长度计2，ASCII字符计1）</p><p>String.prototype.len=function(){return this.replace([^\x00-\xff]/g,"aa").length;}</p><p>匹配空行的正则表达式：\n[\s| ]*\r</p><p>匹配HTML标记的正则表达式：/&lt;(.*)&gt;.*&lt;\/\1&gt;|&lt;(.*) \/&gt;/</p><p>匹配首尾空格的正则表达式：(^\s*)|(\s*$)</p><p>应用：javascript中没有像vbscript那样的trim函数，我们就可以利用这个表达式来实现，如下：</p><p>String.prototype.trim = function()
<br />{
<br />return this.replace(/(^\s*)|(\s*$)/g, "");
<br />}</p><p>利用正则表达式分解和转换IP地址：</p><p>下面是利用正则表达式匹配IP地址，并将IP地址转换成对应数值的Javascript程序：</p><p>function IP2V(ip)
<br />{
<br />re=/(\d+)\.(\d+)\.(\d+)\.(\d+)/g //匹配IP地址的正则表达式
<br />if(re.test(ip))
<br />{
<br />return RegExp.$1*Math.pow(255,3))+RegExp.$2*Math.pow(255,2))+RegExp.$3*255+RegExp.$4*1
<br />}
<br />else
<br />{
<br />throw new Error("Not a valid IP address!")
<br />}
<br />}</p><p>不过上面的程序如果不用正则表达式，而直接用split函数来分解可能更简单，程序如下：</p><p>var ip="10.100.20.168"
<br />ip=ip.split(".")
<br />alert("IP值是："+(ip[0]*255*255*255+ip[1]*255*255+ip[2]*255+ip[3]*1))</p><p>匹配Email地址的正则表达式：\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*</p><p>匹配网址URL的正则表达式：http://([\w-]+\.)+[\w-]+(/[\w- ./?%&amp;=]*)?</p><p>利用正则表达式去除字串中重复的字符的算法程序：</p><p>var s="abacabefgeeii"
<br />var s1=s.replace(/(.).*\1/g,"$1")
<br />var re=new RegExp("["+s1+"]","g")
<br />var s2=s.replace(re,"")
<br />alert(s1+s2) //结果为：abcefgi</p><p>我原来在CSDN上发贴寻求一个表达式来实现去除重复字符的方法，最终没有找到，这是我能想到的最简单的实现方法。思路是使用后向引用取出包括重复的字符，再以重复的字符建立第二个表达式，取到不重复的字符，两者串连。这个方法对于字符顺序有要求的字符串可能不适用。</p><p>得用正则表达式从URL地址中提取文件名的javascript程序，如下结果为page1</p><p>s="http://www.gzcynet/page1.htm"
<br />s=s.replace(/(.*\/){0,}([^\.]+).*/ig,"$2")
<br />alert(s)</p><p>利用正则表达式限制网页表单里的文本框输入内容：</p><p>用正则表达式限制只能输入中文：onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')"
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"</p><p>用正则表达式限制只能输入全角字符：
onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,'')"
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,''))"</p><p>用正则表达式限制只能输入数字：onkeyup="value=value.replace(/[^\d]/g,'')
"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"</p><p>用正则表达式限制只能输入数字和英文：onkeyup="value=value.replace(/[\W]/g,'')
"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
</p><br /><img src ="http://www.blogjava.net/killme2008/aggbug/102323.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/killme2008/" target="_blank">dennis</a> 2007-03-07 09:54 <a href="http://www.blogjava.net/killme2008/archive/2007/03/07/102323.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>javascript之DOM技术（二）</title><link>http://www.blogjava.net/killme2008/archive/2007/02/10/99135.html</link><dc:creator>dennis</dc:creator><author>dennis</author><pubDate>Sat, 10 Feb 2007 07:12:00 GMT</pubDate><guid>http://www.blogjava.net/killme2008/archive/2007/02/10/99135.html</guid><wfw:comment>http://www.blogjava.net/killme2008/comments/99135.html</wfw:comment><comments>http://www.blogjava.net/killme2008/archive/2007/02/10/99135.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/killme2008/comments/commentRss/99135.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/killme2008/services/trackbacks/99135.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: javascript之DOM技术（一）				一。样式编程1.页面中的每一个元素都具有一个style对象，此对象管理元素的CSS样式。这是在IE4.0引入的，后来作为DOM标准被接受。使用方法:var oDiv=document.getElementById("div1");alert(oDiv.style.backgroundColor);style对象拥有一个cssText属性，返回描...&nbsp;&nbsp;<a href='http://www.blogjava.net/killme2008/archive/2007/02/10/99135.html'>阅读全文</a><img src ="http://www.blogjava.net/killme2008/aggbug/99135.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/killme2008/" target="_blank">dennis</a> 2007-02-10 15:12 <a href="http://www.blogjava.net/killme2008/archive/2007/02/10/99135.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ECMAScript对象基础</title><link>http://www.blogjava.net/killme2008/archive/2007/02/06/98290.html</link><dc:creator>dennis</dc:creator><author>dennis</author><pubDate>Tue, 06 Feb 2007 06:05:00 GMT</pubDate><guid>http://www.blogjava.net/killme2008/archive/2007/02/06/98290.html</guid><wfw:comment>http://www.blogjava.net/killme2008/comments/98290.html</wfw:comment><comments>http://www.blogjava.net/killme2008/archive/2007/02/06/98290.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/killme2008/comments/commentRss/98290.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/killme2008/services/trackbacks/98290.html</trackback:ping><description><![CDATA[ 1.Global对象。这对象之所以特别就是因为它根本不存在!-_-。如果你声明<br />var pointer=Global；<br />报错，找不到此对象。这是因为在ECMAScript中，每个函数都某个对象的方法，我们用到的isNaN(),isFinite(),parseInt()和parseFloat()函数，看起来是独立的函数，其实它们都是Global对象的函数。<br />需要注意两个用于处理url编码的函数：<br /><br />1)encodeURI()和decodeURI()  处理完整的uri<br />2)encodeURIComponent()和decodeURIComponent()     处理片段<br /><br />2.其他对象如Array,Math,Date对象，我发现比较有趣的是Array的处理方式与ruby中Array的处理方式几乎一样。<br /><br />3.ECMAScript对象的创建方式：<br />1）工厂方式：<br /><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img id="Codehighlighter1_20_42_Open_Image" onclick="this.style.display='none'; Codehighlighter1_20_42_Open_Text.style.display='none'; Codehighlighter1_20_42_Closed_Image.style.display='inline'; Codehighlighter1_20_42_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_20_42_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_20_42_Closed_Text.style.display='none'; Codehighlighter1_20_42_Open_Image.style.display='inline'; Codehighlighter1_20_42_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" /><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> showColor()</span><span id="Codehighlighter1_20_42_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"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_20_42_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />  alert(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.color)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img id="Codehighlighter1_85_257_Open_Image" onclick="this.style.display='none'; Codehighlighter1_85_257_Open_Text.style.display='none'; Codehighlighter1_85_257_Closed_Image.style.display='inline'; Codehighlighter1_85_257_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_85_257_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_85_257_Closed_Text.style.display='none'; Codehighlighter1_85_257_Open_Image.style.display='inline'; Codehighlighter1_85_257_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> createCar(sColor, iDoors, iMpg) </span><span id="Codehighlighter1_85_257_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"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_85_257_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> oTempCar </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Object;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    oTempCar.color </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> sColor;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    oTempCar.doors </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> iDoors;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    oTempCar.mpg </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> iMpg;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    oTempCar.showColor </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">showColor;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> oTempCar;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> oCar1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> createCar(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">red</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">23</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> oCar2 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> createCar(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">blue</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">25</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span></div><br />这样的方式看起来很奇怪，好象方法showColor()不是对象的方法<br /><br />2）构造函数方式：<br /><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img id="Codehighlighter1_35_176_Open_Image" onclick="this.style.display='none'; Codehighlighter1_35_176_Open_Text.style.display='none'; Codehighlighter1_35_176_Closed_Image.style.display='inline'; Codehighlighter1_35_176_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_35_176_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_35_176_Closed_Text.style.display='none'; Codehighlighter1_35_176_Open_Image.style.display='inline'; Codehighlighter1_35_176_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" /><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> Car(sColor, iDoors, iMpg) </span><span id="Codehighlighter1_35_176_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"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_35_176_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.color </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> sColor;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.doors </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> iDoors;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.mpg </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> iMpg;<br /><img id="Codehighlighter1_141_173_Open_Image" onclick="this.style.display='none'; Codehighlighter1_141_173_Open_Text.style.display='none'; Codehighlighter1_141_173_Closed_Image.style.display='inline'; Codehighlighter1_141_173_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_141_173_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_141_173_Closed_Text.style.display='none'; Codehighlighter1_141_173_Open_Image.style.display='inline'; Codehighlighter1_141_173_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.showColor </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> () </span><span id="Codehighlighter1_141_173_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"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_141_173_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        alert(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.color)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> oCar1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Car(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">red</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">23</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> oCar2 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Car(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">blue</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">25</span><span style="COLOR: #000000">);</span></div><br /><br />这样的方式有个新问题，那就是每次构造一个对象都将重复生成函数showColor，为每个对象创建独立的函数版本。<br /><br />3）原型方式<br /><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img id="Codehighlighter1_15_17_Open_Image" onclick="this.style.display='none'; Codehighlighter1_15_17_Open_Text.style.display='none'; Codehighlighter1_15_17_Closed_Image.style.display='inline'; Codehighlighter1_15_17_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_15_17_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_15_17_Closed_Text.style.display='none'; Codehighlighter1_15_17_Open_Image.style.display='inline'; Codehighlighter1_15_17_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" /><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> Car() </span><span id="Codehighlighter1_15_17_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"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_15_17_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />Car.prototype.color </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">red</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />Car.prototype.doors </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />Car.prototype.mpg </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">23</span><span style="COLOR: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />Car.prototype.drivers </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Array(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Mike</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Sue</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /><img id="Codehighlighter1_186_211_Open_Image" onclick="this.style.display='none'; Codehighlighter1_186_211_Open_Text.style.display='none'; Codehighlighter1_186_211_Closed_Image.style.display='inline'; Codehighlighter1_186_211_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_186_211_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_186_211_Closed_Text.style.display='none'; Codehighlighter1_186_211_Open_Image.style.display='inline'; Codehighlighter1_186_211_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" />Car.prototype.showColor </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> () </span><span id="Codehighlighter1_186_211_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"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_186_211_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    alert(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.color);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> oCar1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Car();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> oCar2 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Car();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />oCar1.drivers.push(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Matt</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />alert(oCar1.drivers);    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">outputs "Mike,Sue,Matt"</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">alert(oCar2.drivers);    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">outputs "Mike,Sue,Matt"</span></div><br /><br />利用对象的prototype属性来构造对象，但是有两个问题：没办法使用构造函数传参来生成对象；函数虽然被不同对象共享，但是属性竟然也被共享，比如上面代码中，oCar1的drivers属性与oCar2的drivers属性是同一个Array对象。<br /><br />4）为了解决上面问题，我们引入了构造函数/原型的混合方式：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img id="Codehighlighter1_35_153_Open_Image" onclick="this.style.display='none'; Codehighlighter1_35_153_Open_Text.style.display='none'; Codehighlighter1_35_153_Closed_Image.style.display='inline'; Codehighlighter1_35_153_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_35_153_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_35_153_Closed_Text.style.display='none'; Codehighlighter1_35_153_Open_Image.style.display='inline'; Codehighlighter1_35_153_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" /><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> Car(sColor, iDoors, iMpg) </span><span id="Codehighlighter1_35_153_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"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_35_153_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.color </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> sColor;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.doors </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> iDoors;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.mpg </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> iMpg;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.drivers </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Array(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Mike</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Sue</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_194_219_Open_Image" onclick="this.style.display='none'; Codehighlighter1_194_219_Open_Text.style.display='none'; Codehighlighter1_194_219_Closed_Image.style.display='inline'; Codehighlighter1_194_219_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_194_219_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_194_219_Closed_Text.style.display='none'; Codehighlighter1_194_219_Open_Image.style.display='inline'; Codehighlighter1_194_219_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" />Car.prototype.showColor </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> () </span><span id="Codehighlighter1_194_219_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"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_194_219_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    alert(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.color);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> oCar1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Car(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">red</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">23</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> oCar2 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Car(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">blue</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">25</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />oCar1.drivers.push(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Matt</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />alert(oCar1.drivers);    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">outputs "Mike,Sue,Matt"</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">alert(oCar2.drivers);    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">outputs "Mike,Sue"</span></div><br /><br />属性通过构造函数方式，而函数则通过原型来生成，这就避免了纯粹原型方式带来的问题。但是函数放在对象的构造函数定义，让习惯java,c++的人也感觉不爽，对象为什么不能放在一块地方定义呢？这就引出来了动态原型方式<br /><br />5）动态原型方式：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img id="Codehighlighter1_35_335_Open_Image" onclick="this.style.display='none'; Codehighlighter1_35_335_Open_Text.style.display='none'; Codehighlighter1_35_335_Closed_Image.style.display='inline'; Codehighlighter1_35_335_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_35_335_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_35_335_Closed_Text.style.display='none'; Codehighlighter1_35_335_Open_Image.style.display='inline'; Codehighlighter1_35_335_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" /><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> Car(sColor, iDoors, iMpg) </span><span id="Codehighlighter1_35_335_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"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_35_335_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.color </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> sColor;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.doors </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> iDoors;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.mpg </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> iMpg;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.drivers </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Array(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Mike</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Sue</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_202_333_Open_Image" onclick="this.style.display='none'; Codehighlighter1_202_333_Open_Text.style.display='none'; Codehighlighter1_202_333_Closed_Image.style.display='inline'; Codehighlighter1_202_333_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_202_333_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_202_333_Closed_Text.style.display='none'; Codehighlighter1_202_333_Open_Image.style.display='inline'; Codehighlighter1_202_333_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">typeof</span><span style="COLOR: #000000"> Car._initialized </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">undefined</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">) </span><span id="Codehighlighter1_202_333_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"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_202_333_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_251_292_Open_Image" onclick="this.style.display='none'; Codehighlighter1_251_292_Open_Text.style.display='none'; Codehighlighter1_251_292_Closed_Image.style.display='inline'; Codehighlighter1_251_292_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_251_292_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_251_292_Closed_Text.style.display='none'; Codehighlighter1_251_292_Open_Image.style.display='inline'; Codehighlighter1_251_292_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        Car.prototype.showColor </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> () </span><span id="Codehighlighter1_251_292_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"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_251_292_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />            alert(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.color);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        Car._initialized </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> oCar1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Car(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">red</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">23</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> oCar2 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Car(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">blue</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">25</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span></div><br />通过引入_initialized 属性，当第一次构造对象时生成方法showColor ，再次生成对象时，此时的_initialized 已经是true,就避免了重复生成函数，属性的定义和函数的定义都在构造函数内，也满足了语义上的对象封装概念。<br /><br />我们应当尽量采用 <span style="FONT-WEIGHT: bold">构造函数/原型混合方式</span> 和<span style="FONT-WEIGHT: bold"> 动态原型方式</span> 来创建ECMAScript对象。<img src ="http://www.blogjava.net/killme2008/aggbug/98290.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/killme2008/" target="_blank">dennis</a> 2007-02-06 14:05 <a href="http://www.blogjava.net/killme2008/archive/2007/02/06/98290.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ECMAScript基础</title><link>http://www.blogjava.net/killme2008/archive/2007/02/06/98289.html</link><dc:creator>dennis</dc:creator><author>dennis</author><pubDate>Tue, 06 Feb 2007 06:03:00 GMT</pubDate><guid>http://www.blogjava.net/killme2008/archive/2007/02/06/98289.html</guid><wfw:comment>http://www.blogjava.net/killme2008/comments/98289.html</wfw:comment><comments>http://www.blogjava.net/killme2008/archive/2007/02/06/98289.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/killme2008/comments/commentRss/98289.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/killme2008/services/trackbacks/98289.html</trackback:ping><description><![CDATA[ 开始读《JAVASCRIPT高级程序设计》<br />第2章 ECMAScript基础<br /><br />JavaScript实质上是ECMAScript在web环境中的实现，还有其他实现（如Flash的ActionScript等）。因此了解基本的ECMAScript相当于掌握javascript的基础。<br /><br />1。ECMAScript的基础概念：<br />1）区分大小写<br />2）变量是弱类型（解释型语言的基本特点）<br />3）每行结尾的分号可有可无（与java不同）<br />4）注释的形式与java相同（单行或者块注释）<br />5）大括号代表代码块{}<br /><br />2。变量，使用var定义。如var test="test1"<br />当然，变量是弱类型，并且可以不被初始化而定义<br />var test="test1"<br />var test2;<br />test=1;<br />建议采用匈牙利类型标记法来命名变量。<br /><br />3.关键字和保留字（略）<br /><br />4。原始值和引用值<br />与java类似，变量分成原始类型与引用类型两类：<br />1）原始值存储在stack中<br />2）引用值是存储在heap中的对象，存储在变量处的是一个point<br /><br />5。原始类型：<br />1）ECMAScript有5种原始类型：Undefined、Null、Boolean、Number和String。可以使用typeof来判断一个值是否在某类型的范围内。如：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> s</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">test</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />alert(</span><span style="COLOR: #0000ff">typeof</span><span style="COLOR: #000000"> s)  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">输出"string"</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span></div><br />注意：type null返回object，因为null被认为是对象的占位符。<br /><br />2)Undefined类型<br />当变量未初始化时，该变量的默认值就是undefined。但是，undefined并不同于未定义的值。但是，typeof并不区分两者，比如：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> temp1;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />alert(</span><span style="COLOR: #0000ff">typeof</span><span style="COLOR: #000000"> temp1);  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">未初始化，输出undefined</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">alert(</span><span style="COLOR: #0000ff">typeof</span><span style="COLOR: #000000"> temp2);   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">未定义，也是undefined</span></div><br /><br />函数无返回值，返回的也是undefined<br /><br />3）Null类型<br />Null只有一个值，也就是null。Undefined本质上是从Null派生来的，因此两者相等：<br />alert(null==undefined);  //输出true<br />但两者意义不同，Undefined表示变量未被初始化之前的值，而Null则表示尚未存在的对象，也就是对象的占位符。<br /><br />4）Boolean类型<br />Boolean有两个值：true,false<br /><br />5)Number类型<br />Number类型很有趣，Number可以表示32位的数字，也可以表示64位的浮点数，以0开头的数字当成八进制，以ox开头即为十六进制。有趣的地方在于所有数字运算结果都是返回十进制！<br />在ECMAScript中，浮点数的计算本质上是存储的是字符串。<br />Number类型的大小在Number.MAX_VALUE和Number.MIN_VALUE之间<br />无穷大用Infinity表示，如你所见，Number.MAX_VALUE就是Infinity，而Number.MIN_VALUE就是-Infinity，可以通过isFinite(n)来判断n是否超过界限<br /><br />最后，还有一个特殊值是NaN，表示Not a Number（非数），非数产生在类型转换失败时，注意，它与自身不相当：alert(NaN==NaN);  //输出false<br /><br />不推荐使用NaN，我们可以通过isNaN()来判断是否是非数（很常用咯）<br /><br />6) String类型<br />String是唯一没有固定大小的原始类型，可以存储0或者多个Unicode字符。与java不同的是，可以使用双引好和单引号来声明字符：<br />var s1="test1";<br />var s2='test2';<br />常见转义符与其他语言相同。<br /><br />6。类型转换<br />1）转换成字符串:<br />Boolean,String和Number类型本质上都是伪对象，他们都有toString()方法（与java相同）<br /><br />Number类型的toString()有两种模式：<br />toString()，返回数字的十进制<br />toString(n)，返回n进制的字符串(n为2,8,10,16）<br /><br />2）转换成数字：<br />两个方法：parseInt()和parseFloat()方法。用法略过，需要注意的是parseInt如果没指定基数，会把以0开始的解析为8进制。parseFloat反而不会。<br /><br />3）强制类型转换：<br />3种强制类型转换：<br />String(value);<br />Boolean(value);<br />Number(value);<br />规则如下：<br />（1）String(value)与toString()基本一样，除了对null或者undefined的转换之外，如：<br />var s1=String(null); //通过<br />var oNull=null;<br />var s2=oNull.toString(); //报错<br /><br />（2）Boolean(value)，如果该value是空字符串、数字0、undefined或者null，返回false，其他返回true<br /><br />（3）Number()与parseInt和parseFloat基本相同，不同的是Number()将转换整体，如果转换失败返回NaN。如：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">Number(</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">)  ;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  0</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">Number(</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">);  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">   1</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">Number(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Object());   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  NaN</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">Number('</span><span style="COLOR: #000000">5.6</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">7</span><span style="COLOR: #000000">');    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  NaN</span></div><br /><br />7。引用类型：<br />1)Object类：类似于java中java.lang.Object的地位和作用，js中所有类都继承此类而来。它包含下面的属性：<br />（1）Constructor——对创建该对象函数的引用<br />（2）Prototype——对该对象对象原型的引用，对所有的类，它将返回一个Object实例<br />（3）HasOwnProperty(property)——判断是否有某个属性<br />（4）IsPropertOf(object)——判断该对象是否为另一个对象的原型<br />（5）PropertyIsEnumerable(property)——判断对象的属性是否可以枚举<br />（6）ToString()——返回对象的原始字符串表示<br />（7）ValueOf()——返回最适合该对象的原始值，对于许多类，它的结果与ToString()相同<br /><br />2）Boolean类，尽量避免使用，注意的是，在Boolean表达式中，所有的值将被自动转化为true，所以下面的输出：<br />var oFalseObject=new Boolean(false);<br />alert(oFalseObject&amp;&amp;true);  //输出true，而不是false<br /><br />3) Number类,是Number原始类型的引用类型，应该少使用此类，尽量使用原始类型。需要注意3个方法：<br />（1）toFixed()：返回具有指定位数小数的字符串，如：<br />var oNumberObject=new Number(99);<br />alert(oNumberObject.toFixed(2));  // 输出99.00<br /><br /> (2) toExponential()，返回用科学记数法表示的数字的字符串形式，如：<br />var oNumberObject=new Number(99);<br />alert(oNumberObject.toExponential(1));  //输出9.9e+1<br /><br />(3)toPrecision(),对数进行舍入，返回尽可能接近真实值的数字，如：<br />var oNumberObject=new Number(99);<br />alert(oNumberObject.toPrecision(3));  //输出99.0<br />注意，这3个方法都将进行四舍五入操作<br /><br />4）String类，是String原始类型的对象，常见方法见下面的例子：<br /><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> oStringObject</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> String(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">hello world</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />alert(oStringObject.length);  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">输出11</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">alert(oStringObject.toString()</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">oStringObject.valueOf());  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">输出true</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">alert(oStringObject.charAt(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">));   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">输出e</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">alert(oStringObject.charCodeAt(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)); </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">输出e的字符代码：101</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">alert(oStringObject.concat(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,china</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">输出hello world,china</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">alert(oStringObject.indexOf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">e</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">输出1</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">alert(oStringObject.lastIndexOf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">o</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">输出7</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> oStringObject1</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> String(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">yellow</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> oStringObject2</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> String(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">brick</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> iResult</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">oStringObject1.localeCompare(oStringObject2);  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">根据本地比较</span><span style="COLOR: #008000"><br /><img id="Codehighlighter1_556_602_Open_Image" onclick="this.style.display='none'; Codehighlighter1_556_602_Open_Text.style.display='none'; Codehighlighter1_556_602_Closed_Image.style.display='inline'; Codehighlighter1_556_602_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_556_602_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_556_602_Closed_Text.style.display='none'; Codehighlighter1_556_602_Open_Image.style.display='inline'; Codehighlighter1_556_602_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(iResult</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)</span><span id="Codehighlighter1_556_602_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"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_556_602_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />  alert(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">oStringObject1在oStringObject2后面</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /><img id="Codehighlighter1_621_668_Open_Image" onclick="this.style.display='none'; Codehighlighter1_621_668_Open_Text.style.display='none'; Codehighlighter1_621_668_Closed_Image.style.display='inline'; Codehighlighter1_621_668_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_621_668_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_621_668_Closed_Text.style.display='none'; Codehighlighter1_621_668_Open_Image.style.display='inline'; Codehighlighter1_621_668_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" />}</span></span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(iResult</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)</span><span id="Codehighlighter1_621_668_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"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_621_668_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />   alert(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">oStringObject1在oStringObject2前面</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />   alert(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">oStringObject1和oStringObject2相同</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />alert(oStringObject.substring(</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">7</span><span style="COLOR: #000000">));  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">输出"lo w"</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">alert(oStringObject.slice(</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">7</span><span style="COLOR: #000000">));  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">输出"lo w"</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">alert(oStringObject.toUpperCase());<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />alert(oStringObject.toLowerCase());<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />alert(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">中国</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.toLocaleLowerCase());</span></div><br /><br />8.操作符和语句，省略大部分操作符的介绍和控制语句，与其他语言（java,ruby）基本相同，需要注意的摘抄如下：<br />1）delete操作符：用于删除对以前定义的对象属性或者方法的引用，如：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> o</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Object();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />o.name</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">dennis</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />alert(o.name); </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">输出dennis</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">delete</span><span style="COLOR: #000000"> o.name;   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">解除引用</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">alert(o.name);  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">输出undifined</span></div><br /><br />2)for ... in语句，严格的枚举语句，用于枚举对象属性<br /><br />3）switch可以作用于字符串，而不仅仅是整数<br /><br />4）不支持重载（与ruby相同），可以通过arguments对象来变相实现<br /><br />5）在ECMAScript中，函数其实是完整一个对象（与ruby相同，或者说动态语言的基本特点），可以采用：<br />var function_name=new Function(arg1,arg2,arg3,...,function_body);<br />来定义函数（速度比普通方法慢）。函数可以作为参数传递，函数的length属性返回此函数的参数个数<br />6）ECMAScript的闭包概念与其他动态语言的概念很不同，我还不大理解，过段时间好好研究一下。(写入备忘录）<img src ="http://www.blogjava.net/killme2008/aggbug/98289.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/killme2008/" target="_blank">dennis</a> 2007-02-06 14:03 <a href="http://www.blogjava.net/killme2008/archive/2007/02/06/98289.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>javascript事件模型框架</title><link>http://www.blogjava.net/killme2008/archive/2007/02/06/98286.html</link><dc:creator>dennis</dc:creator><author>dennis</author><pubDate>Tue, 06 Feb 2007 05:58:00 GMT</pubDate><guid>http://www.blogjava.net/killme2008/archive/2007/02/06/98286.html</guid><wfw:comment>http://www.blogjava.net/killme2008/comments/98286.html</wfw:comment><comments>http://www.blogjava.net/killme2008/archive/2007/02/06/98286.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/killme2008/comments/commentRss/98286.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/killme2008/services/trackbacks/98286.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 最近一直在读《javascript高级程序设计》，也快读完了，读到事件这一章，书中提供的一个事件工具类很实用，我注释了一下，并摘记：//eventutil.jsvar EventUtil = new Object;/**//*   此方法用来给特定对象添加事件，oTarget是指定对象,sEventType是事件类型，如click、keydown等，    fnHandler是事件回调函数/*Ev...&nbsp;&nbsp;<a href='http://www.blogjava.net/killme2008/archive/2007/02/06/98286.html'>阅读全文</a><img src ="http://www.blogjava.net/killme2008/aggbug/98286.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/killme2008/" target="_blank">dennis</a> 2007-02-06 13:58 <a href="http://www.blogjava.net/killme2008/archive/2007/02/06/98286.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>javascript之DOM技术(一)</title><link>http://www.blogjava.net/killme2008/archive/2007/02/06/98218.html</link><dc:creator>dennis</dc:creator><author>dennis</author><pubDate>Tue, 06 Feb 2007 03:38:00 GMT</pubDate><guid>http://www.blogjava.net/killme2008/archive/2007/02/06/98218.html</guid><wfw:comment>http://www.blogjava.net/killme2008/comments/98218.html</wfw:comment><comments>http://www.blogjava.net/killme2008/archive/2007/02/06/98218.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/killme2008/comments/commentRss/98218.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/killme2008/services/trackbacks/98218.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 《javascript高级程序设计》学习笔记&nbsp;&nbsp;<a href='http://www.blogjava.net/killme2008/archive/2007/02/06/98218.html'>阅读全文</a><img src ="http://www.blogjava.net/killme2008/aggbug/98218.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/killme2008/" target="_blank">dennis</a> 2007-02-06 11:38 <a href="http://www.blogjava.net/killme2008/archive/2007/02/06/98218.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>