<?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>博客园-ξσ Dicky's Blog σξ</title><link>http://www.cnblogs.com/Dicky/</link><description>朋友多了,寂寞卻沒少,朋友沒有了你,得到了天下最高的技術又能如何?人類的全部才能無非是時間和耐心的混合物.---巴尔扎克
Traditional Chinese</description><language>zh-cn</language><lastBuildDate>Tue, 07 Oct 2008 19:26:26 GMT</lastBuildDate><pubDate>Tue, 07 Oct 2008 19:26:26 GMT</pubDate><ttl>60</ttl><item><title>文件夹加密码方法</title><link>http://www.cnblogs.com/Dicky/archive/2008/06/08/FoldEncrypt.html</link><dc:creator>ξσ Dicky σξ</dc:creator><author>ξσ Dicky σξ</author><pubDate>Sun, 08 Jun 2008 03:49:00 GMT</pubDate><guid>http://www.cnblogs.com/Dicky/archive/2008/06/08/FoldEncrypt.html</guid><wfw:comment>http://www.cnblogs.com/Dicky/comments/1215920.html</wfw:comment><comments>http://www.cnblogs.com/Dicky/archive/2008/06/08/FoldEncrypt.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/Dicky/comments/commentRss/1215920.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/Dicky/services/trackbacks/1215920.html</trackback:ping><description><![CDATA[加密：<br />
将文件夹加扩展名: <br />
.{00021401-0000-0000-C000-000000000046}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 无关联 <br />
.{21EC2020-3AEA-1069-A2DD-08002B30309D}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 控制面板 <br />
.{2227A280-3AEA-1069-A2DE-08002B30309D}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 打印机 <br />
.{D6277990-4C6A-11CF-8D87-00AA0060F5BF}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 任务计划 <br />
.{645FF040-5081-101B-9F08-00AA002F954E}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 回收站 <br />
.{25336920-03F9-11CF-8FD0-00AA00686F13}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 网页 <br />
.{7BD29E00-76C1-11CF-9DD0-00A0C9034933}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 历史文件夹 <br />
.{871C5380-42A0-1069-A2EA-08002B30309D}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IE <br />
.{208D2C60-3AEA-1069-A2D7-08002B30309D}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 网上邻居 <br />
.{992CFFA0-F557-101A-88EC-00DD010CCC48}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 拨号网络 <br />
.{645FF040-5081-101B-9F08-00AA002F954E}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 回收站<br />
.{00020c01-0000-0000-c000-000000000046}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 波形文件<br />
.{20D04FE0-3AEA-1069-A2D8-08002B30309D}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 我的电脑<br />
注意：不要直接改，要先把想该的名字在记事本中写好后复制粘贴！！ <br />
<br />
解密： <br />
开始--运行--command ren 盘符路径文件名.{645FF040-5081-101B-9F08-00AA002F954E} 新文件名
<img src ="http://www.cnblogs.com/Dicky/aggbug/1215920.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42828/" target="_blank">[新闻]Mono 2.0 发布 Linux 上的 .NET 框架成熟了吗？</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>灰色星期一,网站变灰白风格CSS代码</title><link>http://www.cnblogs.com/Dicky/archive/2008/05/19/GrayCSS.html</link><dc:creator>ξσ Dicky σξ</dc:creator><author>ξσ Dicky σξ</author><pubDate>Mon, 19 May 2008 14:13:00 GMT</pubDate><guid>http://www.cnblogs.com/Dicky/archive/2008/05/19/GrayCSS.html</guid><wfw:comment>http://www.cnblogs.com/Dicky/comments/1202855.html</wfw:comment><comments>http://www.cnblogs.com/Dicky/archive/2008/05/19/GrayCSS.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/Dicky/comments/commentRss/1202855.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/Dicky/services/trackbacks/1202855.html</trackback:ping><description><![CDATA[<p>根据国务院文件，5.19-5.21为全国哀悼日，在此期间，全国和各驻外机构下半旗志哀，停止公共娱乐活动，外交部和我国驻外使领馆设立吊唁簿。5月19日14时28分起，全国人民默哀3分钟，届时汽车、火车、舰船鸣笛，防空警报鸣响。<br />
<br />
为方便站点哀悼，特提供css滤镜代码，以表哀悼。以下为全站CSS代码。<br />
1.支持的标准协议为：<font style="background-color: #cce8cf" face="Verdana">&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;请用：</font><br />
<font style="background-color: #cce8cf" face="Verdana"><span style="background-color: yellow"><font face="Verdana">body { filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); }或body {filter:gray}</font></span><br />
2.支持的标准协议为：<font style="background-color: #cce8cf" face="Verdana">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;</font>请用：<br />
<font style="background-color: yellow" face="Verdana">html { filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); }或html {filter:gray}<br />
<br />
</font></font>有一些网站FLASH动画的颜色不能被CSS滤镜控制，可以在FLASH代码的&lt;object &#8230;&gt;和&lt;/object&gt;之间插入：<br />
<font style="background-color: yellow" face="Verdana">&lt;param value="false" name="menu"/&gt;<br />
&lt;param value="opaque" name="wmode"/&gt; <br />
</font><br />
使用方法：这2段代码可以变网页为灰白风格，将上面的代码加到CSS文件最顶端或在文件的head区域添加<font style="background-color: #cce8cf" face="Verdana"><span style="background-color: yellow"><font face="Verdana">&lt;style type="text/css"&gt;上面提供的2种方法的代码内容&lt;/</font>style&gt;</span></font>就可以实现素装。建议全国站长动起来。为在地震中遇难的同胞哀悼。</p><img src ="http://www.cnblogs.com/Dicky/aggbug/1202855.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42827/" target="_blank">[新闻]史上九大最强网络黑客</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>我的eWork，我能赚钱的SOHO空间</title><link>http://www.cnblogs.com/Dicky/archive/2008/03/17/eWork.html</link><dc:creator>ξσ Dicky σξ</dc:creator><author>ξσ Dicky σξ</author><pubDate>Mon, 17 Mar 2008 10:00:00 GMT</pubDate><guid>http://www.cnblogs.com/Dicky/archive/2008/03/17/eWork.html</guid><wfw:comment>http://www.cnblogs.com/Dicky/comments/1110284.html</wfw:comment><comments>http://www.cnblogs.com/Dicky/archive/2008/03/17/eWork.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/Dicky/comments/commentRss/1110284.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/Dicky/services/trackbacks/1110284.html</trackback:ping><description><![CDATA[摘要: 我的eWork，我能赚钱的SOHO空间&nbsp;&nbsp;<a href='http://www.cnblogs.com/Dicky/archive/2008/03/17/eWork.html'>阅读全文</a><img src ="http://www.cnblogs.com/Dicky/aggbug/1110284.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42826/" target="_blank">[新闻]微软拟2010年推新版SQL 强化商业智能功能</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>［上海］招聘.Net高级软件工程师＆BI数据仓库工程师（急）</title><link>http://www.cnblogs.com/Dicky/archive/2008/03/04/InbetweenJob.html</link><dc:creator>ξσ Dicky σξ</dc:creator><author>ξσ Dicky σξ</author><pubDate>Tue, 04 Mar 2008 03:29:00 GMT</pubDate><guid>http://www.cnblogs.com/Dicky/archive/2008/03/04/InbetweenJob.html</guid><wfw:comment>http://www.cnblogs.com/Dicky/comments/1089902.html</wfw:comment><comments>http://www.cnblogs.com/Dicky/archive/2008/03/04/InbetweenJob.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cnblogs.com/Dicky/comments/commentRss/1089902.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/Dicky/services/trackbacks/1089902.html</trackback:ping><description><![CDATA[摘要: 招聘.Net高级开发工程师和BI数据仓库工程师&nbsp;&nbsp;<a href='http://www.cnblogs.com/Dicky/archive/2008/03/04/InbetweenJob.html'>阅读全文</a><img src ="http://www.cnblogs.com/Dicky/aggbug/1089902.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42825/" target="_blank">[新闻]GMail Labs 新功能 - 做数学题确认是否发出邮件</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>SQL Server 2005数据挖掘开发者指南[转]</title><link>http://www.cnblogs.com/Dicky/archive/2007/12/04/SQL_Server_2005_Data_Mining_Development_Guide.html</link><dc:creator>ξσ Dicky σξ</dc:creator><author>ξσ Dicky σξ</author><pubDate>Tue, 04 Dec 2007 02:55:00 GMT</pubDate><guid>http://www.cnblogs.com/Dicky/archive/2007/12/04/SQL_Server_2005_Data_Mining_Development_Guide.html</guid><wfw:comment>http://www.cnblogs.com/Dicky/comments/982007.html</wfw:comment><comments>http://www.cnblogs.com/Dicky/archive/2007/12/04/SQL_Server_2005_Data_Mining_Development_Guide.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/Dicky/comments/commentRss/982007.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/Dicky/services/trackbacks/982007.html</trackback:ping><description><![CDATA[摘要: 作者： Bogdan Crivat，微软公司时间：2005年3月适用于： 微软 SQL Server 2005 SQL Server 数据挖掘（SQL Server Data Mining）摘要：介绍SQL Server 2005数据挖掘的新API以及几种常用的开发场景。版权在这篇文章中所包含的信息代表了从发布日起微软对所讨论的问题的当前观点。因为微软必须对市场的变换做出响应，它不应该被理解为微软&nbsp;&nbsp;<a href='http://www.cnblogs.com/Dicky/archive/2007/12/04/SQL_Server_2005_Data_Mining_Development_Guide.html'>阅读全文</a><img src ="http://www.cnblogs.com/Dicky/aggbug/982007.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42824/" target="_blank">[新闻]OpenOffice四处创造纪录 占有全球25%办公软件市场</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>小教练教MM如何去掉你的小肚子</title><link>http://www.cnblogs.com/Dicky/archive/2007/08/23/CuteCoachTeachMMHowToRemoveBeerBelly.html</link><dc:creator>ξσ Dicky σξ</dc:creator><author>ξσ Dicky σξ</author><pubDate>Thu, 23 Aug 2007 15:30:00 GMT</pubDate><guid>http://www.cnblogs.com/Dicky/archive/2007/08/23/CuteCoachTeachMMHowToRemoveBeerBelly.html</guid><wfw:comment>http://www.cnblogs.com/Dicky/comments/867540.html</wfw:comment><comments>http://www.cnblogs.com/Dicky/archive/2007/08/23/CuteCoachTeachMMHowToRemoveBeerBelly.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/Dicky/comments/commentRss/867540.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/Dicky/services/trackbacks/867540.html</trackback:ping><description><![CDATA[<span class="javascript" id="text818071">大肚男们应该也适用吧,呵呵^_^<a href="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735104281.gif" target="_blank"><br />
<img alt="" src="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735104281.gif" border="0" /></a> <br />
<br />
<a href="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735112812.gif" target="_blank"><img alt="" src="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735112812.gif" border="0" /></a> <br />
<br />
<a href="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735119718.gif" target="_blank"><img alt="" src="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735119718.gif" border="0" /></a> <br />
<br />
<a href="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735126296.gif" target="_blank"><img alt="" src="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735126296.gif" border="0" /></a> <br />
<br />
<a href="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735134546.gif" target="_blank"><img alt="" src="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735134546.gif" border="0" /></a> <br />
<br />
<a href="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735143031.gif" target="_blank"><img alt="" src="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735143031.gif" border="0" /></a> <br />
<br />
<a href="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735167671.gif" target="_blank"><img alt="" src="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735167671.gif" border="0" /></a> <br />
<br />
<a href="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735183000.gif" target="_blank"><img alt="" src="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735183000.gif" border="0" /></a> <br />
<br />
<a href="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735188875.gif" target="_blank"><img alt="" src="http://bbsimg.qianlong.com/upload/01/18/44/12/1184412_1146735188875.gif" border="0" /></a></span> 
<img src ="http://www.cnblogs.com/Dicky/aggbug/867540.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42823/" target="_blank">[新闻]云计算硝烟四起 IBM携Bluehouse参战</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>跨越域的Cookie(转)</title><link>http://www.cnblogs.com/Dicky/archive/2007/05/26/761154.html</link><dc:creator>ξσ Dicky σξ</dc:creator><author>ξσ Dicky σξ</author><pubDate>Sat, 26 May 2007 15:04:00 GMT</pubDate><guid>http://www.cnblogs.com/Dicky/archive/2007/05/26/761154.html</guid><wfw:comment>http://www.cnblogs.com/Dicky/comments/761154.html</wfw:comment><comments>http://www.cnblogs.com/Dicky/archive/2007/05/26/761154.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/Dicky/comments/commentRss/761154.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/Dicky/services/trackbacks/761154.html</trackback:ping><description><![CDATA[摘要: 所有的网站开发者都会非常喜欢cookie的强大特性和易用性，它在跟踪用户信息，建设人性化、个性化的网站方面，有着强大的作用，而且，又避免了使用数据库的昂贵开销。但是，cookie却不能跨越域传递，只有那些创建它的域才能访问；这里，我们讨论如何利用ASP突破这个限制。&nbsp;&nbsp;<a href='http://www.cnblogs.com/Dicky/archive/2007/05/26/761154.html'>阅读全文</a><img src ="http://www.cnblogs.com/Dicky/aggbug/761154.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42822/" target="_blank">[新闻]唱片商解密缘何反百度：态度强硬 人工干预明显</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>如何网上炒股</title><link>http://www.cnblogs.com/Dicky/archive/2007/05/23/757570.html</link><dc:creator>ξσ Dicky σξ</dc:creator><author>ξσ Dicky σξ</author><pubDate>Wed, 23 May 2007 11:48:00 GMT</pubDate><guid>http://www.cnblogs.com/Dicky/archive/2007/05/23/757570.html</guid><wfw:comment>http://www.cnblogs.com/Dicky/comments/757570.html</wfw:comment><comments>http://www.cnblogs.com/Dicky/archive/2007/05/23/757570.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/Dicky/comments/commentRss/757570.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/Dicky/services/trackbacks/757570.html</trackback:ping><description><![CDATA[首先凭身份证到当地的证券登记公司（有的券商也代办）办理一个沪深交易所的股东账户卡，选择一家证券营业部开户，签订一份合同，领取资金账户卡，存入一定现金（支票）。 <br><br>如何买卖股票: <br>买卖股票时必须指明买进或卖出，买卖股票的名称(或代码)、数量、价格。并且这一委托只在下达委托的当日有效。委托的内容包括你要买卖股票的简称(代码)，数量及买进或卖出股票的价格。股票的简称通常为四至三个汉字，股票的代码为六位数，委托买卖时股票的代码和简称一定要一致。同时，买卖股票的数量也有一定的规定：即委托买人股票的数量必须是100的整倍数，但委托卖出股票的数量则可以不是100的整倍。 <br><br>委托的方式有四种：柜台递单委托、电话自动委托、电脑自动委托和远程终端委托。 <br><br>1. 柜台递单委托就是你带上自己的身份证和帐户卡，到你开设资金帐户的证券营业部柜台填写买进或卖出股票的委托书，然后由柜台的工作人员审核后执行。 <br><br>2. 电脑自动委托就是你在证券营业部大厅里的电脑上亲自输入买进或卖出股票的代码、数量和价格，由电脑来执行你的委托指令。 <br><br>3. 电话自动委托就是用电话拨通你开设资金帐户的证券营业部柜台的电话自动委托系统，用电话上的数字和符号键输入你想买进或卖出股票的代码、数量和价格从而完成委托。 <br><br>4. 远程终端委托就是你通过与证券柜台电脑系统连网的远程终端或互联网下达买进或卖出指令。 <br><br>除了柜台递单委托方式是由柜台的工作人员确认你的身份外，其余3种委托方式则是通过你的交易密码来确认你的身份，所以一定要好好保管你的交易密码，以免泄露，给你带来不必要的损失。当确认你的身份后，便将委托传送到交易所电脑交易的撮合主机。交易所的撮合主机对接收到的委托进行合法性的检测，然后按竞价规则，确定成交价，自动撮合成交，并立刻将结果传送给证券商，这样你就能知道你的委托是否已经成交。不能成交的委托按"价格优先，时间优先"的原则排队，等候与其后进来的委托成交。当天不能成交的委托自动失效，第二天用以上的方式重新委托。 <br><br>交易费用： <br>每一笔交易收取印花税千分之一。 <br>佣金千分之二至三，最高三（有的券商略低）。各券商标准不一，网上和现场不同但相差不大，一般现场交易共千分之四左右的费用，双向收取，共约千分之八。网上交易佣金一般都在千分之二以内（各券商不一） <br>沪市还收取每千股内一元的过户费，累加。 <br>上海、深圳证券交易所的交易时间是每周一至五，上午9：30至11：30，下午1：00至3：00。法定假日除外。 <br><br><br><br>网上交易： <br><br>上述开户结束后，与营业部签订一个网上交易合同，下载一个该营业部的网上实时动态交易软件，就可以了。具体细节在你办理此项手续的同时，营业部会给你一个文本，怎样操作一目了然，不明白的地方还可当面咨询。</ca>
<img src ="http://www.cnblogs.com/Dicky/aggbug/757570.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42821/" target="_blank">[新闻]国外媒体评出史上十大悬疑网络犯罪</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>一岁半宝宝不肯吃饭怎么办</title><link>http://www.cnblogs.com/Dicky/archive/2007/05/23/757555.html</link><dc:creator>ξσ Dicky σξ</dc:creator><author>ξσ Dicky σξ</author><pubDate>Wed, 23 May 2007 11:36:00 GMT</pubDate><guid>http://www.cnblogs.com/Dicky/archive/2007/05/23/757555.html</guid><wfw:comment>http://www.cnblogs.com/Dicky/comments/757555.html</wfw:comment><comments>http://www.cnblogs.com/Dicky/archive/2007/05/23/757555.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnblogs.com/Dicky/comments/commentRss/757555.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/Dicky/services/trackbacks/757555.html</trackback:ping><description><![CDATA[<p>你好. <br>&nbsp; 宝宝一岁了.现在却越来越不喜欢吃饭了.请问一岁的宝宝吃什么好?一天吃几餐</p>
<p>好?谢谢!&nbsp; <br>&nbsp;<br>&nbsp;<br>&nbsp;<br>&nbsp;<br>&nbsp; 专家回答&nbsp; <br>&nbsp;<br>&nbsp;<br>&nbsp;&nbsp; 您好！宝宝不爱吃饭，父母应避免以下几种情况： </p>
<p>　 1、家中存放过多的零食： </p>
<p>　 如果孩子无时无刻都在吃零食，一到应该吃饭的时间，孩子自然就吃不下饭，</p>
<p>更严重的会造成孩子营养不良。 </p>
<p>　 2、放任孩子边吃边玩： </p>
<p>　 孩子边吃边玩的结果，便会延长吃饭的时间，等到下一顿吃饭的时刻到了，宝</p>
<p>宝却因此而还不饿，当然就不肯乖乖地坐下来吃饭了。 </p>
<p>　 3、不愉快地吃饭时刻： </p>
<p>　 许多的职业父母在自己赶着去上班或是工作忙碌的时候，便会不自觉地要求宝</p>
<p>宝吃快一点，如此便会使孩子对&#8220;吃饭&#8221;这件事产生不愉快的经验，因而排斥吃</p>
<p>饭。 </p>
<p>　 4、以利诱的方式对待： </p>
<p>　 父母如果以利诱的方式叫孩子吃饭，久而久之，便会让孩子以&#8220;吃饭&#8221;这件事</p>
<p>当作交换条件，造成孩子成就的价值观。 <br>　 培养宝宝养成良好的饮食习惯： <br>　&nbsp; <br>　 1、大人本身养成正确的饮食习惯。<br>　 2、固定的开饭时刻。<br>　 3、减少正餐之外的食物。<br>　 4、促进孩子的食欲。<br>　 5、选购孩子喜爱的餐具。<br>　 6、多花心思在菜色上做变化。<br>　 7、让孩子参与做饭的过程。<br>　 8、为吃饭增添趣味性。 </p>
<p>一般宝宝从6个月以后至6岁左右是容易感冒(上呼吸道感染),小儿反复呼吸道感染，简称&#8220;复感儿&#8221;，是指体质较弱的孩子在较长时间内反复不断地发生感冒、发热、咳嗽、流涕、咽喉肿痛等呼吸道感染。这主要与孩子免疫功能低下、营 养不良或不合理、吸入了烟尘、粉尘、虫螨等有关。那么，面对这样体弱的&#8220;复感儿&#8221;，家长该怎么办呢？体质较弱时期,孩子为什么容易感冒,这是很多家长普遍的问题,这是因为这阶段孩子本身的抵抗力就弱,当然相对有的孩子好一点,每个孩子生出来对病菌是没有抵抗力的,所以当他接触到病菌后容易感染,但感染后下次再碰到同一类型的病菌他就有免疫力了,所以大人比孩子少感冒也是这原因,大人接触过的病菌多了自身也有免疫力了,不过现在变异的病菌比以前要多,所以要增强孩子抵抗力有以下几点:一、宝宝随着年龄的增长抵抗力也会好些,二、平时注意均衡营养,若想提升宝宝的免疫力，请拒绝给宝宝吃高油、高糖的精致化加工食品。1、多吃天然食品，多吃富含维他命和矿物质的蔬菜、水果，2、五谷类是人类的主食，在宝宝4个月后添加副食品时，首先要尝试的是米粉、麦粉。断乳之后，替代食物也是谷类。全谷类含胚芽和多醣，维生素B和E都丰富，这些抗氧化剂能增强免疫力，加强免疫细胞的功能。3、天天五份蔬果，不只是成人饮食的信条，也适合推广到幼儿身上。如蕃茄红素、胡萝卜素、含丰富的维生素C与E等，纤维质可预防便秘，提供肠道通畅良好的吸收环境。水果的果寡糖帮助肠道益菌生长，就像在小肠大肠铺一层免疫地毯一般。孩子若不喜欢蔬菜，可以将它剁碎，混合谷类或肉类做成丸子、饺子或馄饨，就容易接受了。4、婴幼儿正值身体快速增长及脑神经发育期，对蛋白质及钙质的需求量相当高。所以乳类制品为婴幼儿期最佳的营养来源。优酪乳是乳制品中，可以兼顾营养与改善肠道环境的饮品，很适合儿童期的需要，幼儿则要到满一岁以后才能喝。5、人体最重要的成分是什么？不是硬梆梆的骨头，而是柔柔软软的水。婴幼儿体表面积相对于体重比成人更高，水分蒸散流失多，更需要补充水分。水分充沛，新陈代谢旺盛，免疫力自然提高。6、此外，不要让宝宝偏食而导致营养失调。均衡、优质的营养，才能造就宝宝优质的免疫力，轻轻松松远离病菌。三、多参加户外运动,这是预防呼吸道感染的最好方法。要让孩子经常到室外活动，晒阳光和呼吸新鲜空气。四、平时注意冷暖,五、可以去医院检测一下宝宝的免疫功能是否达标,如果不达标医生会用药物调节的,单调节的话还是建议中药调节,西药对孩子伤害大,六、家长一定要注意别让宝宝反复感冒这样大大降低宝宝的抵抗力,药物(特别是抗生素药物)也会损害宝宝的抵抗力的,让宝宝少去公共场所,少接触病菌......七、现在市场上所谓的提高免疫力的保健品其实效果都不佳.建议您家宝宝还是多参加户外运动,注意平时的营养搭配,这也是最好的方法了. </p>
<p><br>至于宝宝吃饭不乖，怎么办?许多父母常会发现，一顿饭下来孩子没吃几口、吃饭时不专心，尽管爸妈们用尽了所有的方法威胁利诱，宝宝还是一口饭也不肯吞进嘴里，看在父母的眼中除了生气之外，更多了一些怜惜。 </p>
<p>关乎&#8220;权利之争&#8221;的问题 </p>
<p>家中的宝宝不肯在吃饭的时间里乖乖地吃饭，与父母本身的态度有密不可分的关系。&#8220;肚子饿了，便想吃饭&#8221;这是每个人与生俱来的本能，如果孩子的肚子真的很饿了，就不会有不肯吃饭的问题，因此，宝宝&#8220;拒绝吃饭&#8221;的理由多数来自想与父母做&#8220;权利之争&#8221;。由于父母对孩子不肯吃饭的行为不了解及不放心，聪明的孩子们便会抓住父母的弱点，以不吃饭的行为做为与父母交换条件的筹码，欧姿秀老师表示，面对这样的问题父母应该具有：知道孩子的真正需要及理解孩子的行为能力，如此才能正确的因应孩子不肯乖乖吃饭的问题。 </p>
<p>父母应该避免的态度 </p>
<p>父母除了不要让孩子察觉自己对他不肯吃饭的行为产生担心及焦虑的心态之外，也应该避免出现以下的态度： </p>
<p>1、家中存放过多的零食： </p>
<p>如果孩子无时无刻都在吃零食，一到应该吃饭的时间，孩子自然就吃不下饭，更严重的会造成孩子营养不良。 </p>
<p>2、放任孩子边吃边玩： </p>
<p>孩子边吃边玩的结果，便会延长吃饭的时间，等到下一顿吃饭的时刻到了，宝宝却因此而还不饿，当然就不肯乖乖地坐下来吃饭了。 </p>
<p>3、不愉快地吃饭时刻： </p>
<p>许多的职业父母在自己赶着去上班或是工作忙碌的时候，便会不自觉地要求宝宝吃快一点，如此便会使孩子对&#8220;吃饭&#8221;这件事产生不愉快的经验，因而排斥吃饭。 </p>
<p>4、以利诱的方式对待： </p>
<p>父母如果以利诱的方式叫孩子吃饭，久而久之，便会让孩子以&#8220;吃饭&#8221;这件事当作交换条件，造成孩子成就的价值观。 </p>
<p>让孩子喜欢吃饭的秘诀 </p>
<p>1、大人本身养成正确的饮食习惯 </p>
<p>&#8220;言教不如身教&#8221;。小孩子的模仿能力极强，如果大人们本身的饮食习惯不正常，或者常常随便以零食裹腹，自然没有理由去要求孩子遵守定时吃饭习惯。 </p>
<p>2、固定的开饭时刻 </p>
<p>尽量做到吃饭的时间一到，全家人一同在餐桌上用餐的习惯，并规定孩子须吃完自己的那一份餐，如果孩子不吃完，就算他等一下饿了，也不要再给他任何零食，久而久之，孩子便会养成定时、定量的习惯。 </p>
<p>3、减少正餐之外的食物 </p>
<p>虽然零食的给予有其必要性，然而却不可过量，尤其垃圾食物尽量不要给予，才能避免孩子因多吃了一些零食，造成&#8220;本末倒置&#8221;吃不下正餐。 </p>
<p>4、促进孩子的食欲 </p>
<p>孩子肚子不饿当然吃不下饭，若父母只一味地强迫孩子进食，反而会造成反效果，试着促进孩子的食欲，如：增加他的活动量，他的肚子真正感到饿了，自然不会抗拒吃饭。 </p>
<p>5、选购孩子喜爱的餐具 </p>
<p>孩子都喜欢拥有属于自己独有的东西，替孩子买一些图案可爱的餐具，可提高孩子用餐的欲望，如能与孩子一起选购更能达到好效果。 </p>
<p>6、多花心思在菜色上做变化 </p>
<p>在饮食均衡的条件下，父母可以多种类的食物取代平日所吃单纯的米饭、面条。例如：有时以马铃薯当成主菜，再配上一些蔬菜，也能拥有一顿既营养又丰盛的餐点。 </p>
<p>7、让孩子参与做饭的过程 </p>
<p>例如：上市场买菜、帮忙提回家、一起清洗水果&#8230;&#8230;等等，甚至可询问孩子的意见，请孩子协助您一起做饭，孩子不但能有参与感，同时也能因而了解做一道菜之前的每样步骤，进而更喜爱吃饭这件事。 </p>
<p>8、为吃饭增添趣味性 </p>
<p>在喂孩子吃饭时，加入一些轻松、活泼的语气，让吃饭不再只是吃饭而已，将吃饭时刻与方式变成有趣的事情。其实在宝宝的成长过程中会碰到很多问题的,关键在于如何解决,不要随意的根据自己或宝宝的需要而改变什么. </p>
<p><br>巧治小儿积食消化不良食欲不振的方法有哪些？ </p>
<p>1、酸牛奶。先将牛奶加5～10％蔗糖煮沸消毒，待奶液冷却后，徐徐滴入乳酸液（按每100毫升牛奶加5％的乳酸液5毫升），边加边搅，使成细颗粒状即成。酸牛奶易于消化，适用于胃肠炎的患儿。 </p>
<p>2、脱脂奶。将牛奶煮沸，待冷却后除去脂肪膜，再煮沸余乳，再冷却后去脂肪膜，如此反复3次即可。脱脂奶适用于呕吐、腹泻、痢疾等患儿。 </p>
<p>3、炒奶糕。将奶糕炒至淡黄色，炒后淀粉变为炭化糊精，可吸收水分。有止泻和帮助消化的作用。 </p>
<p>4、焦米汤。将大米洗干净，晾至半干炒成焦黄色，100毫升水中加炒焦米6克，用文火煮1小时，过滤去渣，再加0．4％的食盐煮沸后即可。焦米汤中淀粉变成糊精，易于消化。适用于严重腹泻及消化不良的患儿。 </p>
<p>5、胡萝卜汁。先用胡萝卜500克，洗净捣碎，加入少许水煮10～15分钟，用纱布过滤，加水至1000毫升，再加3～5％的蔗糖煮沸倒入瓶中，煮5～10分钟消毒后饮用。 </p>
<p>6、苹果泥汤。取熟透苹果500～700克，洗净后捣成泥状，放入淡茶水中。苹果纤维较细，对肠道的刺激小，并富含碱性及果胶，有吸附、收敛作用，适用于1岁以上的腹泻患儿。 </p>
<p>7、淡茶水。取红茶少许用开水冲泡，每日4次，因茶内含咖啡因、鞣酸等，具有兴奋、强心、利尿、收敛、杀菌、消炎等作用，对急性胃肠炎有疗效。以上几点仅供参考,其实孩子在在成长过程中会碰到很多类似的问题,让我们一起探讨吧,祝宝宝健康快乐!<br></p>
<p>宝宝一岁半老不爱吃饭怎么办? <br>&nbsp; <br>&nbsp;<br>我家宝宝一岁半了,老不爱吃饭,每天最多吃两餐饭而且还吃不多,奶粉喝的量还可以,但是只是晚上喝的多.请大家想想办法,焦急的妈妈等待您的回答. <br>&nbsp;<br>&nbsp;<br>宝宝不爱吃饭是常有的。可能有这么几个原因：<br>1、正常的发育减速，吃的要求也少了，大约在一岁末会出现这个情况；<br>2、一种自主的萌芽。这种自主可以出现在吃饭的时候，也可以出现在穿衣服，洗澡、睡觉之前等，不愿意任人摆布（喂食也是一种摆布）；<br>3、玩兴正浓，比如敲打玩具、搭积木，撕纸、扔东西等，不愿意停下来；<br>4、某一次被烫过、被&#8220;凉&#8221;过。被噎过&#8230;&#8230;，有记忆，不愿吃东西；<br>5、饭菜做得不合口味，或过咸或过淡、或块儿太大或太硬等，也影响食欲；<br>6、吃饭的环境有太多分心的人或东西；<br>7、生病、疲倦情绪不佳刚睡醒、也会不想吃。</p>
<p>要解决这个问题，可以试试以下的方法：</p>
<p>1、对于正常发展的短时减速以及自主性格的萌芽，可以等待，思想上知道了就行了。<br>2、吃饭以前三五分钟给他洗手、戴围嘴，离开玩玩具的地方，坐在一个安静的，很少分心的地方喂他吃，也不要有别人看着他吃。<br>3、要耐心，把吃的东西切碎，撕小，一次喂一小口，等他吃完了，再喂第二口，不要让他噎住，给他可怕的经验。<br>4、饭菜的口味要掌握好，不要太淡或太咸，不要用味精，要注意色、香、味。<br>5、他坐的位子要适合你喂食的高度，最好能有一点约束，比如坐在前面带横板的高脚椅子、有圈的小椅子里面等。<br>6、不要催赶，不要让他产生厌恶吃饭的心理。<br>7、不要太固守吃饭的时间，灵活掌握，在你认为他应该吃饭的时候（比如距上一次吃饭三个小时）给他吃，他不想吃，可以推迟半小时到一小时试试，或者反之，也可以提前给他吃。<br>8、要做爱吃饭的榜样。当你吃饭时，兴致勃勃，什么都爱吃，让他看在眼里，记在心上。<br>9、在他疲倦，情绪不好时，不要勉强他吃，可以等待他恢复精神，情绪正常时再吃。<br>10、如果怀疑他有病，可带他到医院检查，吃一点帮助消化的药也好。<br>11、只要孩子身长，体重合乎标准，吃得少一点也不要紧，不必太耽心，过一段时间他会好的。</p>
<p>另外，可以带宝宝去医院做微量元素测定，了解宝宝有否缺锌或缺铁。一般缺少锌、铁等微量元素的宝宝食欲不好。面食和饭有不同的营养成分，可以交替吃，但不宜每餐均吃面食。 <br>&nbsp;<br>&nbsp;<br>呵呵 现看看是不是因为厌食引起的！ <br>饭前给他喝些酸甜的果汁，不要吃什么药物，孩子啊还小的很，尽量不要总是带他看医生！<br>不要总是喂奶粉阿！不营养的，孩子缺少妈妈母乳中的抗体会得病的！！<br>多喂一些鸡蛋羹之类的好入口的东西，还有蛋白质一定要跟上，孩子的大脑在成长中，需要充足的营养，少吃油炸的食品，高热量的食品都尽量不接触<br>你就买一本婴儿食谱就好了！！！ <br>&nbsp;<br></p>
<p><br>孩子出现厌食的情况一般出现再1-2岁的幼儿。面对孩子的厌食家长可以作到：<br>1、给孩子限定一个时间的限制，若吃不完，便不动声色的将食物拿走。在此基础上，定时定量让孩子进食，以培养孩子的饮食习惯。<br>2、控制餐间零食。当孩子在非正常进餐时间喊饿时，不要随便给零食吃，可以适当吃一些水果。<br>3、要求家庭成员统一行动。偶尔一次的迁就或让步，以后便很难弥补。<br>4、用色香味具佳的食物吸引孩子。注意食物搭配，色彩丰富，保证其新鲜和多样化。<br>5、选择一些图案生动、大小合适，适合幼儿抓握的餐具。这些辅助材料也是刺激儿童食欲的方式之一。<br>6、适当增加孩子的户外活动量。为其多安排一些户外活动，这样可以促进儿童的新陈代谢，加快食物的消化和吸收。<br>7、保证充足的睡眠，不要让孩子长时间看电视、玩游戏机。<br>8、为孩子创造一个轻松的进餐气氛。不要在吃饭的过程中教训孩子以免给孩子造成心理负担。<br>9、当孩子说&#8220;够了&#8221;的时候要尊重他们的意见。当孩子说&#8220;不要&#8221;时可以拿走食物。少吃或多吃一点其实对孩子并没有太大的影响。</p>
<p>家长只要记住：讥饿是最好的厨师。家长要采取一种顺其自然的态度！ </p>
<p>&nbsp;</p>
<p>一岁宝宝不爱吃饭属正常，父母注意巧安排<br>　　时间：2005年4月15日　14:00－17：00<br>　　提问：guest<br>　　回答：郭志平（上海复旦大学附属儿科医院教授，儿童营养专家）</p>
<p>　　guest：我家宝宝以前胃口很好的，但1岁后，他的食欲明显就不如从前了，对饭菜没有兴趣，我该怎么办？〖13:50:12〗</p>
<p>　　郭志平：不要心急。1岁后，孩子的食欲有所减少，是由于幼儿生长速度减缓造成的。这个时候，1岁孩子一般一天进食5~6次。注意在吃饭前一个半小时之内，不要给孩子吃任何其他食物。另外，父母还要训练让孩子学习自己吃饭，这会大大增加孩子的进食兴趣。〖13:54:20〗</p>
<p>　　<br>自己动手，学会技巧 </p>
<p>1岁左右，宝宝会喜欢跟成人在一起上桌吃饭，不能因为怕他&#8220;捣乱&#8221;而剥夺了他的权利，可以用一个小碟子盛上适合他吃的各种饭菜，让他尽情地用手或用勺子喂自己，即使吃得一塌糊涂也无所谓。其实，宝宝在自己动手的过程中，慢慢就学会了吃饭技巧。当然，你也可以在这个过程中帮助宝宝。 </p>
<p>1.如果宝宝总喜欢抢勺子的话，妈妈可以准备两把勺子，一把给宝宝，另一把自己拿着，让他既可以练习用勺子，也不耽误把他喂饱。 </p>
<p>2.教宝宝用拇指和食指拿东西。 </p>
<p>3.给宝宝做一些能够用手拿着吃的东西或一些切成条或片的蔬菜，以便他能够感受到自己吃饭的怎么回事。如：土豆、红薯、胡萝卜、豆角等，还可以准备香蕉、梨、苹果和西瓜(把籽去掉)、熟米饭、软的烤面包等。 </p>
<p>妈妈也要学&#8220;技巧&#8221; </p>
<p>1.1岁左右的宝宝最不能容忍的就是妈妈一边将其双手紧束，一边一勺一勺地喂他。这对宝宝生活能力的培养和自尊心的建立有极大的危害，宝宝常常报以反抗或拒食。 </p>
<p>2.宝宝并不见得一定是想要自己吃饱饭，他的注意力是在&#8220;自己吃&#8221;这一过程，如果只是为训练他自己吃饭，不妨先喂饱了他，再由着他去满足学习和尝试的乐趣。 </p>
<p>3.当宝宝自己吃饭时，要及时给予表扬，即使他把饭吃得乱七八糟，还是应当鼓励他。如果妈妈确实担心宝宝把饭吃得满地都是，可以在宝宝坐着的椅下铺几张报纸，这样一来等他吃完饭后，只要收拾一下弄脏了的报纸就行了。 </p>
<p>4.1岁的宝宝可以吃成人吃的饭菜了。妈妈做饭时，在准备放盐和其他调料之前，应该把宝宝的那份饭菜留出来。 </p>
<p>5.千万不要给宝宝吃可能会呛着他的东西，最好也别让他接触到这些东西，如：圆形、光滑的食物或硬的食物，如爆米花、花生粒、糖块、葡萄或葡萄干等。 </p>
<p>6.给宝宝选择一个自己就餐的座位，最好让他坐在安静不受干扰的固定地方，不玩、不看电视以免吃饭时分散注意力。 </p>
<p>7.餐桌上，成人谈话的内容最好与宝宝吃饭有关，以吸引他的兴趣。 </p>
<p>8.吃饭时最忌责骂宝宝，唠叨不停，经他进行一天行为的&#8220;总结&#8221;，说他这不好那不好，这样做会引起宝宝反感而不肯吃饭。 </p>
<p>9.允许宝宝吃完饭后先离开饭桌，但不能拿着食物离开，边玩边吃，这样他才会明白，吃和玩是两回事，要分开来做，否则不安全，也不快乐。 </p>
<p>10.宝宝比大人容易饿，但因为能力有限吃得比较慢，所以可以让他先上饭桌吃。 </p>
<p>良好习惯不能少 </p>
<p>良好的饮食习惯直接关系到宝宝的身体健康，所以不仅要保持宝宝进餐环境的清洁、整齐、安静、愉快，还有必须从刚学习吃饭那天起就培养宝宝良好的进食习惯。 </p>
<p>1.注意培养宝宝对食物的兴趣和好感，尽量能引起他旺盛的食欲。 </p>
<p>2.大人不要在孩子面前议论某种食物不好吃，某种食物好吃，以免造成宝宝对食物的偏见，这可是挑食的前提，几乎所有的孩子都会认为爸爸妈妈认为不好吃的东西一定不好吃。 </p>
<p>3.培养良好的进餐习惯。如饭前、便后要洗手；吃饭时安静不说话，不大笑，以免食物呛入气管内等。 </p>
<p>4.要适时地、循序渐进地训练宝宝自己握奶瓶喝水、喝奶，自己用勺、筷、碗进餐，熟悉每件餐具的用途，尽早养成独立进餐的习惯。 </p>
<p>5.宝宝进餐时间不宜过长，即使是吃零食，也不能养成边吃边玩，边吃边看电视的习惯。 </p>
<p>6.饭前不吃零食，尤其不要吃糖果、巧克力等甜食，以免影响食欲。 </p>
<p>&#8220;手抓饭&#8221;有好处 </p>
<p>1岁宝宝吃饭时往往喜欢用手抓，许多家长都会竭力纠正这样&#8220;没规矩&#8221;的动作。但是，最近却有育儿专家提出，只要将手洗干净，家长应该让1岁的宝宝用手抓食物来吃，因为这样有利于宝宝以后形成良好的进食习惯。 </p>
<p>1.&#8220;亲手&#8221;接触食物才会熟悉食物。宝宝学&#8220;吃饭&#8221;实质上也是一种兴趣的培养，这和看书、玩耍没有什么两样。起初的时候，他们往往都喜欢用手来拿食物、用手来抓食物，通过抚触、接触等初步熟悉食物。用手拿、用手抓，就可以掌握食物的形状和特性。从科学角度而言，根本就没有孩子不喜欢吃的食物，只是在于接触次数的频繁与否。而只有这样反复&#8220;亲手&#8221;接触，他们对食物才会越来越熟悉，将来就不太可能挑食。 </p>
<p>2.手抓饭让宝宝对进食信心百倍。1岁宝宝手抓食物的过程对他们来说就是一种愉悦。专家建议，只要将手洗干净，1岁左右的孩子甚至可以&#8220;玩&#8221;食物，比如米糊、蔬菜、土豆等，到18个月左右再逐步教宝宝用工具吃饭，培养宝宝自己挑选、自己动手的愿望。这样做会使他们对食物和进食信心百倍、更有兴趣，促进良好的食欲。 <br></p>
<p><br>&nbsp;</p>
<img src ="http://www.cnblogs.com/Dicky/aggbug/757555.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42821/" target="_blank">[新闻]国外媒体评出史上十大悬疑网络犯罪</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>Building High Performance HTML Pages</title><link>http://www.cnblogs.com/Dicky/archive/2007/05/19/752477.html</link><dc:creator>ξσ Dicky σξ</dc:creator><author>ξσ Dicky σξ</author><pubDate>Sat, 19 May 2007 08:12:00 GMT</pubDate><guid>http://www.cnblogs.com/Dicky/archive/2007/05/19/752477.html</guid><wfw:comment>http://www.cnblogs.com/Dicky/comments/752477.html</wfw:comment><comments>http://www.cnblogs.com/Dicky/archive/2007/05/19/752477.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/Dicky/comments/commentRss/752477.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/Dicky/services/trackbacks/752477.html</trackback:ping><description><![CDATA[<div class=title>Building High Performance HTML Pages</div>
<!--content type: SDKML. Transform: wc2mtps.xslt.-->
<div class=clsDocBody>
<p>The Internet, intranets, and extranets carry millions of packets of data. Today, many of those packets contain HTML.</p>
<p>The features delivered with Microsoft Internet Explorer 4.0 and later have helped make the Web a compelling space in which to work and to play. The quantity and complexity of pages as well as the number of consumers of those pages has significantly increased the traffic on the Web. For all the merit that the Web brings to application developers, it introduces a host of problems. Among these problems are:</p>
<ul>
    <li>Delivering content across the wire.
    <li>Once delivered, getting that content to render quickly. </li>
</ul>
<p>This article presents some tips on how you can get the most performance out of your pages.</p>
<ul>
    <li><a href="#Reuse_HTML_Components_and_External_Scripts">Reuse HTML Components and External Scripts</a>
    <li><a href="#DEFER_Your_Scripts">DEFER Your Scripts</a>
    <li><a href="#Author_Hyperlinks_Consistently">Author Hyperlinks Consistently</a>
    <li><a href="#Use_Fixed-Size_Tables">Use Fixed-Size Tables</a>
    <li><a href="#Optimize_Your_Scripts">Optimize Your Scripts</a>
    <li><a href="#Scope_Your_Object_References_Wisely">Scope Your Object References Wisely</a>
    <li><a href="#Close_Your_Tags">Close Your Tags</a>
    <li><a href="#Leverage_the_HTTP_Expires_Header">Leverage the HTTP Expires Header</a>
    <li><a href="#Use_Cache-Control_Extensions">Use Cache-Control Extensions</a>
    <li><a href="#related_topics">Related Topics</a> </li>
</ul>
<h2><a name=Reuse_HTML_Components_and_External_Scripts><!----></a>Reuse HTML Components and External Scripts</h2>
<p>In his <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl02',this);" href="http://msdn.microsoft.com/library/en-us/dndude/html/dude1201.asp">Frequent Flyers: Boosting Performance on DHTML Pages</a> column, Michael Wallent recommended the use of .js files to consolidate commonly used scripts. The ability to reference external script files, both Microsoft JScript and Microsoft Visual Basic Scripting Edition (VBScript), has been around since Internet Explorer 3.02. By using this feature, the client only has to download the .js file the first time a page containing a reference to that .js file is requested. When Internet Explorer loads additional pages that refer to that .js file, it can retrieve the resource from the local cache. An additional benefit to using external .js files is ease of maintenance. A routine that is encapsulated in a single .js file only has to be modified in a single location. All pages that refer to that routine are automatically synchronized with the change in the script the next time those pages are reloaded.</p>
<p>If you are building a site containing different types of pages and each page type exhibits unique functionality, it makes sense to break up that .js file into a set of smaller .js files. That way the browser only loads into memory the scripts that are needed.</p>
<p>Here's a final tip on code reuse: use <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl03',this);" href="http://msdn2.microsoft.com/en-us/library/ms531079.aspx">Dynamic HTML (DHTML) behaviors</a>. DHTML behaviors, introduced in Internet Explorer 5, are the next logical step in the direction of code reuse. Like .js files, DHTML behaviors are implemented independent of the page in which they are used. Unlike .js files, they make code reuse easier through the use of a simple declarative syntax that is more natural for the HTML author. Developers concerned with down-level compatibility will appreciate the ability to seamlessly add functionality without having to protect their code from down-level browsers with conditional statements.</p>
<p>Today most Web developers are accustomed to writing code that checks the version of the browser before executing subsequent code, like so:</p>
<div class=code id=ctl00_LibFrame_ctl04_>
<div class=CodeSnippetTitleBar>
<div class=CodeDisplayLanguage></div>
<div class=CopyCodeButton><a class=copyCode href="javascript:CopyCode('ctl00_LibFrame_ctl04');"><img height=9 src="http://msdn2.microsoft.com/msdn/Controls/CodeSnippet/en-us/copy_off.gif" align=middle border=0> Copy Code</a></div>
</div>
<pre class=code id=ctl00_LibFrame_ctl04 space="preserve">var sUA = window.navigator.userAgent;
var bIsIE4 = -1 != sUA.indexOf("MSIE 4");
if (bIsIE4)
{
// execute some Internet Explorer 4.x-specific functionality
}</pre>
</div>
<p>By designing behaviors carefully to capture events and associating those behaviors with elements using the STYLE and <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl06',this);" href="http://msdn2.microsoft.com/en-us/library/ms533560.aspx">CLASS</a> attributes, it is possible to enhance the user experience safely and efficiently. For more information, see <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl07',this);" href="http://msdn2.microsoft.com/en-us/library/ms532146.aspx">Using HTML Components to Implement DHTML Behaviors in Script</a>.</p>
<h2><a name=DEFER_Your_Scripts><!----></a>DEFER Your Scripts</h2>
<p><a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl08',this);" href="http://msdn2.microsoft.com/en-us/library/ms533719.aspx">DEFER</a> is a relatively obscure attribute of the <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl09',this);" href="http://msdn2.microsoft.com/en-us/library/ms535892.aspx">script</a> element, but the performance-minded page author can use it to indicate to Internet Explorer 4.0 or later that the <strong>script</strong> tag contains no immediately executing code that impacts the document before the <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl10',this);" href="http://msdn2.microsoft.com/en-us/library/ms536942.aspx">load</a> event fires. Combined with the <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl11',this);" href="http://msdn2.microsoft.com/en-us/library/ms534642.aspx">SRC</a> attribute, the <strong>DEFER</strong> attribute can be used on a <strong>script</strong> tag to indicate to Internet Explorer that the associated code should be downloaded in the background while the rest of the components of the page are downloaded and parsed. </p>
<p>The <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl12',this);" href="http://www.w3.org/tr/rec-html40/">HTML 4.0 Specification</a>&nbsp;<img height=11 alt="World Wide Web link" src="http://msdn2.microsoft.com/en-us/library/ms533020.leave-site(en-us,VS.85).gif" width=17 border=0> makes specific reference to the <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl13',this);" href="http://msdn2.microsoft.com/en-us/library/ms536782.aspx">write</a> method of the <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl14',this);" href="http://msdn2.microsoft.com/en-us/library/ms531073.aspx">document</a> object. When you mark your scripts as deferred, you should not include any calls to <strong>document</strong>.<strong>write</strong> because these are typically executed immediately as the page is loading. In addition, you shouldn't defer any global variables or functions that are accessed by immediately executing script. </p>
<div class=code id=ctl00_LibFrame_ctl15_>
<div class=CodeSnippetTitleBar>
<div class=CodeDisplayLanguage></div>
<div class=CopyCodeButton><a class=copyCode href="javascript:CopyCode('ctl00_LibFrame_ctl15');"><img height=9 src="http://msdn2.microsoft.com/msdn/Controls/CodeSnippet/en-us/copy_off.gif" align=middle border=0> Copy Code</a></div>
</div>
<pre class=code id=ctl00_LibFrame_ctl15 space="preserve">&lt;SCRIPT DEFER&gt;
function UsedLater()
{
// utility function called when the user interacts with the page
}
&lt;/SCRIPT&gt;
&lt;SCRIPT&gt;
// Can't defer this block. It runs immediately and affects the shape of the document.
document.write("&lt;H1&gt;Immediate Gratification&lt;/H1&gt;");
&lt;/SCRIPT&gt;</pre>
</div>
<h2><a name=Author_Hyperlinks_Consistently><!----></a>Author Hyperlinks Consistently</h2>
<p>The Internet Explorer cache is case-sensitive. That means that you should author your hyperlinks with case-sensitivity in mind. Take the following example.</p>
<div class=code id=ctl00_LibFrame_ctl16_>
<div class=CodeSnippetTitleBar>
<div class=CodeDisplayLanguage></div>
<div class=CopyCodeButton><a class=copyCode href="javascript:CopyCode('ctl00_LibFrame_ctl16');"><img height=9 src="http://msdn2.microsoft.com/msdn/Controls/CodeSnippet/en-us/copy_off.gif" align=middle border=0> Copy Code</a></div>
</div>
<pre class=code id=ctl00_LibFrame_ctl16 space="preserve">&lt;A HREF="/workshop/author/dhtml/reference/dhtmlrefs.asp"&gt;DHTML References&lt;/A&gt;
&lt;A HREF="/Workshop/Author/DHTML/Reference/DHTMLRefs.asp"&gt;DHTML References</pre>
</div>
<p>Both hyperlinks refer to the same page. Or do they? On a UNIX system these hyperlinks might refer to two distinct pages; thus, Internet Explorer treats them distinctly by making separate requests to the server, allowing the server to decide how to resolve the request. </p>
<p>By authoring your hyperlinks consistently, you'll be saving space in the user's cache, and you'll be reducing the number of times Internet Explorer has to request the same resource from the server.</p>
<h2><a name=Use_Fixed-Size_Tables><!----></a>Use Fixed-Size Tables</h2>
<p>Tables are a great way of organizing information. Before <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl17',this);" href="http://msdn2.microsoft.com/en-us/library/ms530301.aspx">CSS positioning</a> was implemented in Internet Explorer 4.0, many HTML authors even used tables to lay out elements on their page. Now, if you're still using tables to achieve the latter, you ought to be using Cascading Style Sheets (CSS) positioning instead. Internet Explorer 5 offers even better performance to those who have embraced CSS. </p>
<p>Of course that doesn't rule out using tables altogether. Tables still have a place, and when you use them, you should specify the <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl18',this);" href="http://msdn2.microsoft.com/en-us/library/ms531161.aspx">table-layout</a>&nbsp;CSS attribute to achieve optimal performance out of Internet Explorer 5 or later. By doing the following, you'll allow Internet Explorer to start rendering the table before it has received all the data.</p>
<ul>
    <li>Set the <strong>table-layout</strong>&nbsp;CSS attribute to <code>fixed</code> on the <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl19',this);" href="http://msdn2.microsoft.com/en-us/library/ms535901.aspx">table</a>.
    <li>Explicitly define <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl20',this);" href="http://msdn2.microsoft.com/en-us/library/ms535225.aspx">col</a> objects for each column.
    <li>Set the <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl21',this);" href="http://msdn2.microsoft.com/en-us/library/ms535145.aspx">WIDTH</a> attribute on each <strong>col</strong>. </li>
</ul>
<p>See <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl22',this);" href="http://msdn2.microsoft.com/en-us/library/ms533002.aspx">Enhancing Table Presentation</a> for more information on this feature.</p>
<h2><a name=Optimize_Your_Scripts><!----></a>Optimize Your Scripts</h2>
<p>Not enough can be said about writing solid code regardless of the platform or language. When targeting Internet Explorer 4.0 or later, a thorough understanding of the features provided by the DHTML Object Model will help you achieve that goal. The DHTML Object Model is immense, and a complete discussion of it is beyond the scope of this article. To address the topic of optimization, let's look at a typical operation in DHTML: accessing a collection.</p>
<p>In DHTML, iteration through a collection of objects is a typical operation. Let's say you're writing an HTML application that indexes content. Your task is to collect all the <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl23',this);" href="http://msdn2.microsoft.com/en-us/library/ms535253.aspx">H1</a> elements on a given page and to use them as index entries. </p>
<p>Here's an example of how one might go about this: </p>
<div class=code id=ctl00_LibFrame_ctl24_>
<div class=CodeSnippetTitleBar>
<div class=CodeDisplayLanguage></div>
<div class=CopyCodeButton><a class=copyCode href="javascript:CopyCode('ctl00_LibFrame_ctl24');"><img height=9 src="http://msdn2.microsoft.com/msdn/Controls/CodeSnippet/en-us/copy_off.gif" align=middle border=0> Copy Code</a></div>
</div>
<pre class=code id=ctl00_LibFrame_ctl24 space="preserve">function Iterate(aEntries)
{
for (var i=0; i &lt; document.all.length; i++)
{
if (document.all(i).tagName == "H1")
{
aEntries[aEntries.length] = document.all(i).innerText;
}
}
}</pre>
</div>
<p>What's wrong with the previous code? The code contains three calls through the <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl25',this);" href="http://msdn2.microsoft.com/en-us/library/ms537434.aspx">all</a> collection of the document. During each iteration through the loop, the scripting engine will: </p>
<ul>
    <li>Get the length of the collection.
    <li>Get the <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl26',this);" href="http://msdn2.microsoft.com/en-us/library/ms534657.aspx">tagName</a> of the current object in the collection.
    <li>Get the <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl27',this);" href="http://msdn2.microsoft.com/en-us/library/ms533899.aspx">innerText</a> of the current object in the collection. </li>
</ul>
<p>That's not particularly efficient. The overhead amounts to numerous unnecessary calls to the DHTML Object Model for information that we already know about. Here's version two: </p>
<div class=code id=ctl00_LibFrame_ctl28_>
<div class=CodeSnippetTitleBar>
<div class=CodeDisplayLanguage></div>
<div class=CopyCodeButton><a class=copyCode href="javascript:CopyCode('ctl00_LibFrame_ctl28');"><img height=9 src="http://msdn2.microsoft.com/msdn/Controls/CodeSnippet/en-us/copy_off.gif" align=middle border=0> Copy Code</a></div>
</div>
<pre class=code id=ctl00_LibFrame_ctl28 space="preserve">function Iterate2(aEntries)
{
var oAll = document.all;
var iLength = oAll.length;
for (var i=0; i &lt; iLength; i++)
{
if (oAll(i).tagName == "H1")
{
aEntries[aEntries.length] = oAll(i).innerText;
}
}
}</pre>
</div>
<p>This version assumes the overhead of creating two local variables to cache the <strong>all</strong> collection as well as the length of that collection. We can do better: </p>
<div class=code id=ctl00_LibFrame_ctl29_>
<div class=CodeSnippetTitleBar>
<div class=CodeDisplayLanguage></div>
<div class=CopyCodeButton><a class=copyCode href="javascript:CopyCode('ctl00_LibFrame_ctl29');"><img height=9 src="http://msdn2.microsoft.com/msdn/Controls/CodeSnippet/en-us/copy_off.gif" align=middle border=0> Copy Code</a></div>
</div>
<pre class=code id=ctl00_LibFrame_ctl29 space="preserve">function Iterate3(aEntries)
{
var oH1Coll = document.all.tags("H1");
var iLength = oH1Coll.length;
for (var i=0; i &lt; iLength; i++)
{
aEntries[aEntries.length] = oH1Coll(i).innerText;
}
}</pre>
</div>
<p>Using the <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl30',this);" href="http://msdn2.microsoft.com/en-us/library/ms536776.aspx">tags</a> method of the <strong>all</strong> collection puts the burden on the DHTML Object Model to do the filtering and allows for the elimination of the if condition on every iteration of the scripted loop. </p>
<div class=clsNote><strong>Note</strong>&nbsp;&nbsp;Beware the ramifications of caching DHTML collections. DHTML collections are truly dynamic, and any code you author that creates new elements and inserts them into the document may cause the collection to grow or shrink.</div>
<h2><a name=Scope_Your_Object_References_Wisely><!----></a>Scope Your Object References Wisely</h2>
<p>JScript and VBScript are interpreted languages. Because all the work is done at execution time, relative to compiled languages, these languages are slow. Within a script, every reference to an object amounts to two calls from the scripting engine to the DHTML Object Model. For those unfamiliar with or interested in the intimate details of Automation, refer to the documentation on <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl31',this);" href="http://msdn2.microsoft.com/en-us/library/ms221306.aspx">IDispatch::GetIDsOfNames</a> and <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl32',this);" href="http://msdn2.microsoft.com/en-us/library/ms221479.aspx">IDispatch::Invoke</a> in the Microsoft Platform software development kit (SDK). </p>
<p>The following example defines a <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl33',this);" href="http://msdn2.microsoft.com/en-us/library/ms535240.aspx">div</a> with an <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl34',this);" href="http://msdn2.microsoft.com/en-us/library/ms533880.aspx">ID</a> of div1. </p>
<div class=code id=ctl00_LibFrame_ctl35_>
<div class=CodeSnippetTitleBar>
<div class=CodeDisplayLanguage></div>
<div class=CopyCodeButton><a class=copyCode href="javascript:CopyCode('ctl00_LibFrame_ctl35');"><img height=9 src="http://msdn2.microsoft.com/msdn/Controls/CodeSnippet/en-us/copy_off.gif" align=middle border=0> Copy Code</a></div>
</div>
<pre class=code id=ctl00_LibFrame_ctl35 space="preserve">&lt;DIV ID="div1"&gt;</pre>
</div>
<p>When Internet Explorer parses a page it accounts for all the objects on the page for which <strong>ID</strong> attributes have been explicitly specified. It adds them to the global namespace of the scripting engine, allowing you to refer to them directly. That means that the following is excessive.</p>
<div class=code id=ctl00_LibFrame_ctl36_>
<div class=CodeSnippetTitleBar>
<div class=CodeDisplayLanguage></div>
<div class=CopyCodeButton><a class=copyCode href="javascript:CopyCode('ctl00_LibFrame_ctl36');"><img height=9 src="http://msdn2.microsoft.com/msdn/Controls/CodeSnippet/en-us/copy_off.gif" align=middle border=0> Copy Code</a></div>
</div>
<pre class=code id=ctl00_LibFrame_ctl36 space="preserve">&lt;SCRIPT&gt;
var sText = document.all.div1.innerText;
&lt;/SCRIPT&gt;</pre>
</div>
<p>In addition to the extra bytes that are passed across the network and parsed by the scripting engine, four extra calls are made by the script engine back to Internet Explorer in order to retrieve the <strong>innerText</strong> property of the <strong>div</strong>. The following is all that's required to retrieve the <strong>innerText</strong> of the <strong>div</strong>. </p>
<div class=code id=ctl00_LibFrame_ctl37_>
<div class=CodeSnippetTitleBar>
<div class=CodeDisplayLanguage></div>
<div class=CopyCodeButton><a class=copyCode href="javascript:CopyCode('ctl00_LibFrame_ctl37');"><img height=9 src="http://msdn2.microsoft.com/msdn/Controls/CodeSnippet/en-us/copy_off.gif" align=middle border=0> Copy Code</a></div>
</div>
<pre class=code id=ctl00_LibFrame_ctl37 space="preserve">&lt;SCRIPT&gt;
var sText = div1.innerText;
&lt;/SCRIPT&gt;</pre>
</div>
<p>Notable exceptions to this minimalist approach include the following: </p>
<ul>
    <li>Accessing elements contained within a <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl38',this);" href="http://msdn2.microsoft.com/en-us/library/ms535249.aspx">form</a>.
    <li>Accessing properties of an <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl39',this);" href="http://msdn2.microsoft.com/en-us/library/ms535258.aspx">iframe</a>.
    <li>Accessing properties of the <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl40',this);" href="http://msdn2.microsoft.com/en-us/library/ms535873.aspx">window</a> object. </li>
</ul>
<p>Elements contained within a <strong>form</strong> are hidden within the form's namespace. For example: </p>
<div class=code id=ctl00_LibFrame_ctl41_>
<div class=CodeSnippetTitleBar>
<div class=CodeDisplayLanguage></div>
<div class=CopyCodeButton><a class=copyCode href="javascript:CopyCode('ctl00_LibFrame_ctl41');"><img height=9 src="http://msdn2.microsoft.com/msdn/Controls/CodeSnippet/en-us/copy_off.gif" align=middle border=0> Copy Code</a></div>
</div>
<pre class=code id=ctl00_LibFrame_ctl41 space="preserve">&lt;FORM ID=form1&gt;
&lt;INPUT TYPE="txtUrl"&gt;
&lt;/FORM&gt;
&lt;SCRIPT&gt;
txtUrl.value = ... // yields a scripting error
form1.txtUrl.value = ... // behaves as expected
&lt;/SCRIPT&gt;</pre>
</div>
<p>For cross-frame security reasons, <strong>iframe</strong> properties must be fully scoped as shown in the following example.</p>
<div class=code id=ctl00_LibFrame_ctl42_>
<div class=CodeSnippetTitleBar>
<div class=CodeDisplayLanguage></div>
<div class=CopyCodeButton><a class=copyCode href="javascript:CopyCode('ctl00_LibFrame_ctl42');"><img height=9 src="http://msdn2.microsoft.com/msdn/Controls/CodeSnippet/en-us/copy_off.gif" align=middle border=0> Copy Code</a></div>
</div>
<pre class=code id=ctl00_LibFrame_ctl42 space="preserve">&lt;IFRAME ID="oFrame1" SRC="http://www.msn.com"&gt;
&lt;/IFRAME&gt;
&lt;SCRIPT&gt;
// document.all is require to modify the SRC property of an IFRAME
document.all.oFrame1.src =  form1.txtUrl.value;
&lt;/SCRIPT&gt;</pre>
</div>
<p>When a scripting engine encounters a scoped object model reference in your code, the engine needs to resolve the reference by looking up the left-most piece of that reference in a look-up table. Two factors influence the scripting engine's ability to perform the look-up: </p>
<ul>
    <li>The number of entries in the look-up table.
    <li>The scope of the reference. </li>
</ul>
<p>The number of entries in the table corresponds to the number of global variables, named objects, and functions that you have defined on your page. Thus, you should only declare the <strong>ID</strong> attribute on those elements that you explicitly wish to manipulate through script. </p>
<p>As mentioned above, there's a right way and a wrong way to scope references. When you've assigned an <strong>ID</strong> attribute to an element, there's no reason to access the corresponding object through <strong>document</strong>.<strong>all</strong>. Armed with this information, you might think that you should minimize your object model references in all cases. Let's look at another common example where this rule doesn't apply: </p>
<div class=code id=ctl00_LibFrame_ctl43_>
<div class=CodeSnippetTitleBar>
<div class=CodeDisplayLanguage></div>
<div class=CopyCodeButton><a class=copyCode href="javascript:CopyCode('ctl00_LibFrame_ctl43');"><img height=9 src="http://msdn2.microsoft.com/msdn/Controls/CodeSnippet/en-us/copy_off.gif" align=middle border=0> Copy Code</a></div>
</div>
<pre class=code id=ctl00_LibFrame_ctl43 space="preserve">var sUA = navigator.userAgent;</pre>
</div>
<p>The code works. It stores the HTTP_USER_AGENT string in the variable <em>sUA</em>. In order for the scripting engine to resolve this reference, however, it first attempts to find an object named <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl44',this);" href="http://msdn2.microsoft.com/en-us/library/ms535867.aspx">navigator</a> in the global look-up table. After looking through the entire table and not finding such a named item, the engine has to walk through the table again asking each of the global objects if it supports the <strong>navigator</strong> object. When it finally encounters the global window object, the object that exposes the <strong>navigator</strong> property, it can then retrieve the <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl45',this);" href="http://msdn2.microsoft.com/en-us/library/ms534712.aspx">userAgent</a> property. A better way to handle this situation, especially on a page containing many globally named items, is to fully scope the reference as follows: </p>
<div class=code id=ctl00_LibFrame_ctl46_>
<div class=CodeSnippetTitleBar>
<div class=CodeDisplayLanguage></div>
<div class=CopyCodeButton><a class=copyCode href="javascript:CopyCode('ctl00_LibFrame_ctl46');"><img height=9 src="http://msdn2.microsoft.com/msdn/Controls/CodeSnippet/en-us/copy_off.gif" align=middle border=0> Copy Code</a></div>
</div>
<pre class=code id=ctl00_LibFrame_ctl46 space="preserve">var sUA = window.navigator.userAgent;</pre>
</div>
<p>If all this talk about look-up tables and global objects has your head spinning, just remember this simple rule: fully scope your references to members of the window object. A list of these members is provided in the <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl47',this);" href="http://msdn2.microsoft.com/en-us/library/ms535873.aspx">DHTML Reference</a>. </p>
<h2><a name=Close_Your_Tags><!----></a>Close Your Tags</h2>
<p>Unlike XML, HTML has the notion of implicitly closed tags. This includes <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl48',this);" href="http://msdn2.microsoft.com/en-us/library/ms535250.aspx">frame</a>, <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl49',this);" href="http://msdn2.microsoft.com/en-us/library/ms535259.aspx">img</a>, <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl50',this);" href="http://msdn2.microsoft.com/en-us/library/ms535847.aspx">li</a>, and <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl51',this);" href="http://msdn2.microsoft.com/en-us/library/ms535878.aspx">p</a>. If you don't close these tags, Internet Explorer renders your pages just fine. If you do close your tags, Internet Explorer will render your pages even faster. </p>
<p>It is tempting to author in the following way.</p>
<div class=code id=ctl00_LibFrame_ctl52_>
<div class=CodeSnippetTitleBar>
<div class=CodeDisplayLanguage></div>
<div class=CopyCodeButton><a class=copyCode href="javascript:CopyCode('ctl00_LibFrame_ctl52');"><img height=9 src="http://msdn2.microsoft.com/msdn/Controls/CodeSnippet/en-us/copy_off.gif" align=middle border=0> Copy Code</a></div>
</div>
<pre class=code id=ctl00_LibFrame_ctl52 space="preserve">&lt;P&gt;The following is a list of ingredients.
&lt;UL&gt;
&lt;LI&gt;flour
&lt;LI&gt;sugar
&lt;LI&gt;butter
&lt;/UL&gt;</pre>
</div>
<p>But the following will be parsed more quickly because it is well-formed and Internet Explorer doesn't need to look ahead to decide where the paragraph or list items end. </p>
<div class=code id=ctl00_LibFrame_ctl53_>
<div class=CodeSnippetTitleBar>
<div class=CodeDisplayLanguage></div>
<div class=CopyCodeButton><a class=copyCode href="javascript:CopyCode('ctl00_LibFrame_ctl53');"><img height=9 src="http://msdn2.microsoft.com/msdn/Controls/CodeSnippet/en-us/copy_off.gif" align=middle border=0> Copy Code</a></div>
</div>
<pre class=code id=ctl00_LibFrame_ctl53 space="preserve">&lt;P&gt;The following is a list of ingredients.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;flour&lt;/LI&gt;
&lt;LI&gt;sugar&lt;/LI&gt;
&lt;LI&gt;butter&lt;/LI&gt;
&lt;/UL&gt;</pre>
</div>
<h2><a name=Leverage_the_HTTP_Expires_Header><!----></a>Leverage the HTTP Expires Header</h2>
<p>The expires header is part of the HTTP 1.0 specification. When an HTTP server sends a resource such as an HTML page or an image down to a browser, the server has the option of sending this header and an associated time stamp as part of the transaction. Browsers typically store the resource along with the expiry information in a local cache. On subsequent user requests for the same resource, the browser can first compare the current time and the expires time stamp. If the time stamp indicates a time in the future, the browser may simply load the resource from the cache rather than retrieving the resource from the server.</p>
<p>Even when a resource would advertise an expiration date still to come, browsers—including Internet Explorer 4.0—would still perform a conditional GET to determine that the version of the object in the cache was the same as the version on the server. Upon careful analysis, the designers of Internet Explorer determined that this extra round trip was neither optimal nor necessary. For that reason, the behavior of Internet Explorer 5 has been modified in the following way: if the expiry of a cached resource is later than the time of the request, Internet Explorer will load the resource directly from the cache without contacting the server. Sites using the expires header on commonly used but infrequently updated resources will experience lower traffic volumes, and customers using Internet Explorer 5 will see pages render more quickly. </p>
<p>For more information on the expires header see <a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl54',this);" href="http://www.ietf.org/rfc/rfc2068.txt">RFC 2068</a>&nbsp;<img height=11 alt="World Wide Web link" src="http://msdn2.microsoft.com/en-us/library/ms533020.leave-site(en-us,VS.85).gif" width=17 border=0>. For specific information on how to specify the expires header for a resource on your HTTP server, see your HTTP server documentation.</p>
<h2><a name=Use_Cache-Control_Extensions><!----></a>Use Cache-Control Extensions</h2>
<p>When building a Web site, pages will change with varying frequency. Some pages will change daily, while others will never change once they are posted. To allow the Web site manager to indicate to a client browser how frequently an HTTP server should be queried for changes to a resource, Internet Explorer 5 introduces support for two extensions to the cache-control HTTP response header: pre-check and post-check.</p>
<p>By supporting these extensions, Internet Explorer reduces network traffic by sending fewer requests to the server. In addition, Internet Explorer improves the user experience by rendering resources from the cache and by fetching updates in the background after a specified interval.</p>
<p>The post-check and pre-check cache-control extensions are defined as follows:</p>
<ul>
    <li>post-check
    <ul>
        <li>Defines an interval in seconds after which an entity must be checked for freshness. The check may happen after the user is shown the resource but ensures that on the next roundtrip the cached copy will be up-to-date. </li>
    </ul>
    <li>pre-check
    <ul>
        <li>Defines an interval in seconds after which an entity must be checked for freshness prior to showing the user the resource. </li>
    </ul>
    </li>
</ul>
<p><img height=264 src="http://msdn2.microsoft.com/en-us/library/ms533020.lazy(en-us,VS.85).jpg" width=575></p>
<p>When the browser is asked to fetch a resource which is in the cache and the cache entry includes the cache-control extensions (sent by the server to the client as an HTTP response header), the browser uses those extensions and the following logic to decide when to get the latest version of the page from the server.</p>
<ul>
    <li>If the post-check interval has not yet elapsed, simply retrieve the page from the cache.
    <li>If the elapsed time since the last request is between the post-check and the pre-check intervals, display the page from the cache, and in the background, ask the HTTP server if the page has been modified since it was last requested by the browser. If the page has been modified, fetch the updated page and store it in the cache.
    <li>If the pre-check interval has elapsed by the time the user next requests the page, first ask the HTTP server if the page has been modified since it was last requested by the browser. If the page has been modified, fetch and display the updated page. </li>
</ul>
<p>Note that the Refresh button (including the F5 key) will not trigger this logic because Refresh always sends the <em>if-modified-since</em> request to the server. Hyperlinks do trigger this logic. </p>
<p>In the following example the server is indicating to Internet Explorer that the content will not change for one hour (pre-check=3600) and that it should retrieve the content directly from the local cache. On the off chance that the content is modified, if the user has requested the page after 15 minutes have elapsed, Internet Explorer should still display the content found in the local cache, but it should also perform a background check and optional fetch of the content if the server indicates that the content has changed.</p>
<div class=code id=ctl00_LibFrame_ctl55_>
<div class=CodeSnippetTitleBar>
<div class=CodeDisplayLanguage></div>
<div class=CopyCodeButton><a class=copyCode href="javascript:CopyCode('ctl00_LibFrame_ctl55');"><img height=9 src="http://msdn2.microsoft.com/msdn/Controls/CodeSnippet/en-us/copy_off.gif" align=middle border=0> Copy Code</a></div>
</div>
<pre class=code id=ctl00_LibFrame_ctl55 space="preserve">Cache-Control: post-check=900,pre-check=3600</pre>
</div>
<p>Try this:</p>
<ol>
    <li>On a machine running Microsoft Internet Information Server (IIS) 4.0 or later, create a file containing the following content.
    <div class=code id=ctl00_LibFrame_ctl56_>
    <div class=CodeSnippetTitleBar>
    <div class=CodeDisplayLanguage></div>
    <div class=CopyCodeButton><a class=copyCode href="javascript:CopyCode('ctl00_LibFrame_ctl56');"><img height=9 src="http://msdn2.microsoft.com/msdn/Controls/CodeSnippet/en-us/copy_off.gif" align=middle border=0> Copy Code</a></div>
    </div>
    <pre class=code id=ctl00_LibFrame_ctl56 space="preserve">&lt;%@ LANGUAGE="jscript" %&gt;
    &lt;%
    Response.AddHeader("Cache-Control", "post-check=120,pre-check=240");
    %&gt;
    &lt;H1&gt;Hello, world!&lt;/H1&gt;</pre>
    </div>
    <p>This feature is language-independent and works in both JScript and VBScript.</p>
    <li>Save the content to a file, call it check.pl, in a directory in which Internet Information Server has permissions to execute scripts.
    <li>Launch Internet Explorer 5, and load the page using the HTTP protocol. You should see the string "Hello, world!" render in the browser. Close the browser.
    <li>On the server, modify the .asp file by changing the content contained within the <strong>H1</strong> to "Adios, mundo!". Save the file.
    <li>Relaunch the browser, and reenter the URL corresponding to the .asp file. When the page renders, you should see the original text, "Hello, world!".
    <li>Two minutes after having first retrieved the file you should still see the same content. The next time you load the page, however, Internet Explorer will have downloaded the page in the background, and you will see the updates. If four minutes had passed since you last requested the page, Internet Explorer would have sent an <em>if-modified-since</em> request to the server and, upon receiving a response that the page had changed, would have fetched the latest version and would have rendered it in the browser. </li>
</ol>
<p>While the previous example shows you how to add the cache-control extensions to an individual page, you can add the header to a set of pages by embedding the script in a server-side include referenced by all your pages. Using a server-side include allows you to tune the settings without having to update each page individually. IIS 4.0 introduces the ability for an administrator to specify additional response headers through the Microsoft Management Console. See the latest IIS documentation for details.</p>
<h2><a name=related_topics>Related Topics</a></h2>
<p>
<ul>
    <li><a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl57',this);" href="http://msdn.microsoft.com/library/en-us/dndude/html/dude1201.asp">Frequent Flyers: Boosting Performance on DHTML Pages</a>
    <li><a onclick="javascript:Track('ctl00_LibFrame_ctl01|ctl00_LibFrame_ctl58',this);" href="http://msdn.microsoft.com/library/en-us/dndude/html/dude092298.asp">Asynchrony: Loved Your Performance</a> </li>
</ul>
</div>
<img src ="http://www.cnblogs.com/Dicky/aggbug/752477.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42820/" target="_blank">[新闻]AMD拆分方案已确认 获阿联酋84亿美元投资</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>加快 DHTML 的一组技巧(转)</title><link>http://www.cnblogs.com/Dicky/archive/2007/05/19/752463.html</link><dc:creator>ξσ Dicky σξ</dc:creator><author>ξσ Dicky σξ</author><pubDate>Sat, 19 May 2007 07:59:00 GMT</pubDate><guid>http://www.cnblogs.com/Dicky/archive/2007/05/19/752463.html</guid><wfw:comment>http://www.cnblogs.com/Dicky/comments/752463.html</wfw:comment><comments>http://www.cnblogs.com/Dicky/archive/2007/05/19/752463.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/Dicky/comments/commentRss/752463.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/Dicky/services/trackbacks/752463.html</trackback:ping><description><![CDATA[摘要: 加快 DHTML 的一组技巧&nbsp;&nbsp;<a href='http://www.cnblogs.com/Dicky/archive/2007/05/19/752463.html'>阅读全文</a><img src ="http://www.cnblogs.com/Dicky/aggbug/752463.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42820/" target="_blank">[新闻]AMD拆分方案已确认 获阿联酋84亿美元投资</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>儿童身高体重健康对照表</title><link>http://www.cnblogs.com/Dicky/archive/2007/05/19/752226.html</link><dc:creator>ξσ Dicky σξ</dc:creator><author>ξσ Dicky σξ</author><pubDate>Sat, 19 May 2007 01:41:00 GMT</pubDate><guid>http://www.cnblogs.com/Dicky/archive/2007/05/19/752226.html</guid><wfw:comment>http://www.cnblogs.com/Dicky/comments/752226.html</wfw:comment><comments>http://www.cnblogs.com/Dicky/archive/2007/05/19/752226.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/Dicky/comments/commentRss/752226.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/Dicky/services/trackbacks/752226.html</trackback:ping><description><![CDATA[摘要: 儿童身高体重健康对照表&nbsp;&nbsp;<a href='http://www.cnblogs.com/Dicky/archive/2007/05/19/752226.html'>阅读全文</a><img src ="http://www.cnblogs.com/Dicky/aggbug/752226.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42820/" target="_blank">[新闻]AMD拆分方案已确认 获阿联酋84亿美元投资</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>JavaScript: Create Advanced Web Applications With Object-Oriented Techniques</title><link>http://www.cnblogs.com/Dicky/archive/2007/05/12/744001.html</link><dc:creator>ξσ Dicky σξ</dc:creator><author>ξσ Dicky σξ</author><pubDate>Sat, 12 May 2007 07:50:00 GMT</pubDate><guid>http://www.cnblogs.com/Dicky/archive/2007/05/12/744001.html</guid><wfw:comment>http://www.cnblogs.com/Dicky/comments/744001.html</wfw:comment><comments>http://www.cnblogs.com/Dicky/archive/2007/05/12/744001.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/Dicky/comments/commentRss/744001.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/Dicky/services/trackbacks/744001.html</trackback:ping><description><![CDATA[摘要: This article discusses: JavaScript as a prototype-based language Object-oriented programming with JavaScript Coding tricks with JavaScript The future of JavaScript This article uses the following tech&nbsp;&nbsp;<a href='http://www.cnblogs.com/Dicky/archive/2007/05/12/744001.html'>阅读全文</a><img src ="http://www.cnblogs.com/Dicky/aggbug/744001.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42817/" target="_blank">[新闻]雅虎新闻首页改版，宽屏、共享、组件</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>JavaScript:使用面向对象的技术创建高级 Web 应用程序(转)</title><link>http://www.cnblogs.com/Dicky/archive/2007/05/12/743997.html</link><dc:creator>ξσ Dicky σξ</dc:creator><author>ξσ Dicky σξ</author><pubDate>Sat, 12 May 2007 07:45:00 GMT</pubDate><guid>http://www.cnblogs.com/Dicky/archive/2007/05/12/743997.html</guid><wfw:comment>http://www.cnblogs.com/Dicky/comments/743997.html</wfw:comment><comments>http://www.cnblogs.com/Dicky/archive/2007/05/12/743997.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/Dicky/comments/commentRss/743997.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/Dicky/services/trackbacks/743997.html</trackback:ping><description><![CDATA[<span class=clsSearchBox>本文讨论:</span>
<table cellSpacing=0 cellPadding=0 border=0>
    <tbody>
        <tr>
            <td width="55%">
            <div class=clsDiscuss>
            <ul>
                <li class=clsInfoBox>JavaScript 是基于原型的语言
                <li class=clsInfoBox>用 JavaScript 进行面向对象的编程
                <li class=clsInfoBox>JavaScript 编码技巧
                <li class=clsInfoBox>JavaScript 的未来</li>
            </ul>
            </div>
            </td>
            <td>
            <div class=clsInfoBox><span class=clsSmWhite><strong>本文使用了以下技术:</strong><br>JavaScript</span><br></div>
            </td>
        </tr>
    </tbody>
</table>
<hr>
<table cellSpacing=0 cellPadding=0 width="100%" border=0>
    <tbody>
        <tr>
            <td width="50%"><img class=clsImgButton id=contentbtn onclick="ToggleMenu(contentbtn, contentmenu);" height=9 alt="" hspace=5 src="http://msdn.microsoft.com/msdnmag/images/minus.gif" width=9 align=absMiddle vspace=2><a onclick="ToggleMenu(contentbtn, contentmenu);" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#void" target=_self name=contents><strong>目录</strong></a><br>
            <div id=contentmenu style="MARGIN-TOP: 10px; DISPLAY: block; MARGIN-LEFT: 20px"><a href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#S1" target=_self>JavaScript 对象是词典</a><br><a href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#S2" target=_self>JavaScript 函数是最棒的</a><br><a href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#S3" target=_self>构造函数而不是类</a><br><a href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#S4" target=_self>原型</a><br><a href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#S5" target=_self>静态属性和方法</a><br><a href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#S6" target=_self>闭包</a><br><a href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#S7" target=_self>模拟私有属性</a><br><a href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#S8" target=_self>从类继承</a><br><a href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#S9" target=_self>模拟命名空间</a><br><a href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#S10" target=_self>应当这样编写 JavaScript 代码吗？</a><br><a href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#S11" target=_self>展望</a><br></div>
            </td>
        </tr>
    </tbody>
</table>
<hr>
<br>
<div class=articletext>
<p font="minionmmroman" xmlid="PARA001"></p>
<div class=dropcap>最</div>
近，我面试了一个有五年 Web 应用程序开发经验的软件开发人员。四年半来她一直在从事 JavaScript 相关的工作，她自认为 JavaScript 技能非常好，但在不久之后我就发现实际上她对 JavaScript 知之甚少。话虽这样说，但我确实没有责备她的意思。JavaScript 真的是很有趣。很多人（包括我自己，直到最近！）都认为自己很擅长 JavaScript 语言，因为他们都知道 C/C++/C#，或者有一些以前的编程经验。
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA002">在某种程度上，这种假设并不是完全没有根据的。用 JavaScript 很容易做些简单的事情。入门的门槛很低，该语言很宽松，它不需要您知道很多细节就可以开始用它进行编码。甚至非编程人员也可能用它在几个小时内为主页编写一些有用的脚本。</p>
<p font="minionmmroman" xmlid="PARA003">的确，直到最近，仅仅凭借 MSDN<sup class=clsSmall>&#174;</sup> DHTML 参考资料和我的 C++/C# 经验，我也总能勉强利用这点 JavaScript 知识完成一些任务。只是当我开始编写真实的 AJAX 应用程序时，我才意识到实际上我的 JavaScript 知识还非常不够。这个新一代的 Web 应用程序的复杂性和交互性需要程序员以完全不同的方法来编写 JavaScript 代码。它们是真正的 JavaScript 应用程序！我们在编写一次性脚本时一直采用的方法已完全不再有效。</p>
<p font="minionmmroman" xmlid="PARA004">面向对象编程 (OOP) 是一种流行的编程方法，很多 JavaScript 库中都使用这种方法，以便更好地管理和维护基本代码。JavaScript 支持 OOP，但与诸如 C++、C# 或 Visual Basic<sup class=clsSmall>&#174;</sup> 等流行的 Microsoft<sup class=clsSmall>&#174;</sup> .NET Framework 兼容语言相比，它支持 OOP 的方式非常不同，因此主要使用这些语言的开发人员开始可能会觉得在 JavaScript 中使用 OOP 很奇怪而且不直观。我写本文就是为了深入讨论 JavaScript 语言实际上如何支持面向对象编程，以及您如何使用这一支持在 JavaScript 中高效地进行面向对象开发。下面首先讨论对象（还能先讨论其他别的什么呢？）。</p>
<br><a name=S1></a><span class=clsSubhead>JavaScript 对象是词典</span><br>
<p font="minionmmroman" xmlid="PARA005">在 C++ 或 C# 中，在谈论对象时，是指类或结构的实例。对象有不同的属性和方法，具体取决于将它们实例化的模板（即类）。而 JavaScript 对象却不是这样。在 JavaScript 中，对象只是一组名称/值对，就是说，将 JavaScript 对象视为包含字符串关键字的词典。我们可以使用熟悉的&#8220;.&#8221;（点）运算符或&#8220;[]&#8221;运算符，来获得和设置对象的属性，这是在处理词典时通常采用的方法。以下代码段</p>
<p font="mscoderegular" xmlid="PARA006">
<pre class=clsCode>var userObject = new Object();
userObject.lastLoginTime = new Date();
alert(userObject.lastLoginTime);
</pre>
的功能与下面的代码段完全相同：
<p>&#160;</p>
<p font="mscoderegular" xmlid="PARA007">
<pre class=clsCode>var userObject = {}; // equivalent to new Object()
userObject[&#8220;lastLoginTime&#8221;] = new Date();
alert(userObject[&#8220;lastLoginTime&#8221;]);
</pre>
我们还可以直接在 userObject 的定义中定义 lastLoginTime 属性，如下所示：
<p>&#160;</p>
<p font="mscoderegular" xmlid="PARA008">
<pre class=clsCode>var userObject = { &#8220;lastLoginTime&#8221;: new Date() };
alert(userObject.lastLoginTime);
</pre>
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA009">注意，它与 C# 3.0 对象初始值非常相似。而且，熟悉 Python 的人会发现在第二和第三个代码段中实例化 userObject 的方法与在 Python 中指定词典的方法完全相同。唯一的差异是 JavaScript 对象/词典只接受字符串关键字，而不是像 Python 词典那样接受可哈希化的对象。</p>
<p font="minionmmroman" xmlid="PARA010">这些示例还显示 JavaScript 对象比 C++ 或 C# 对象具有更大的可延展性。您不必预先声明属性 lastLoginTime — 如果 userObject 没有该名称的属性，该属性将被直接添加到 userObject。如果记住 JavaScript 对象是词典，您就不会对此感到吃惊了，毕竟，我们一直在向词典添加新关键字（和其各自的值）。</p>
<p font="minionmmroman" xmlid="PARA011">这样，我们就有了对象属性。对象方法呢？同样，JavaScript 与 C++/C# 不同。若要理解对象方法，首先需要仔细了解一下 JavaScript 函数。</p>
<div style="MARGIN-TOP: 5px" align=right><a class=clsSmall onclick="OpenMenu(contentbtn, contentmenu);" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#contents" target=_self><img style="MARGIN-LEFT: 5px" height=8 alt="Back to top" src="http://msdn.microsoft.com/msdnmag/images/top.gif" width=18 align=bottom border=0></a></div>
<br><a name=S2></a><span class=clsSubhead>JavaScript 函数是最棒的</span><br>
<p font="minionmmroman" xmlid="PARA012">在很多编程语言中，函数和对象通常被视为两样不同的东西。在 JavaScript 中，其差别很模糊 — JavaScript 函数实际上是具有与它关联的可执行代码的对象。请如此看待普通函数：</p>
<p font="mscoderegular" xmlid="PARA013">
<pre class=clsCode>function func(x) {
alert(x);
}
func(&#8220;blah&#8221;);
</pre>
这就是通常在 JavaScript 中定义函数的方法。但是，还可以按以下方法定义该函数，您在此创建匿名函数对象，并将它赋给变量 func
<p>&#160;</p>
<p font="mscoderegular" xmlid="PARA014">
<pre class=clsCode>var func = function(x) {
alert(x);
};
func(&#8220;blah2&#8221;);
</pre>
甚至也可以像下面这样，使用 Function 构造函数：
<p>&#160;</p>
<p font="mscoderegular" xmlid="PARA015">
<pre class=clsCode>var func = new Function(&#8220;x&#8221;, &#8220;alert(x);&#8221;);
func(&#8220;blah3&#8221;);
</pre>
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA016">此示例表明函数实际上只是支持函数调用操作的对象。最后一个使用 Function 构造函数来定义函数的方法并不常用，但它展示的可能性非常有趣，因为您可能注意到，该函数的主体正是 Function 构造函数的 String 参数。这意味着，您可以在运行时构造任意函数。</p>
<p font="minionmmroman" xmlid="PARA017">为了进一步演示函数是对象，您可以像对其他任何 JavaScript 对象一样，在函数中设置或添加属性：</p>
<p font="mscoderegular" xmlid="PARA018">
<pre class=clsCode>function sayHi(x) {
alert(&#8220;Hi, &#8220; + x + &#8220;!&#8221;);
}
sayHi.text = &#8220;Hello World!&#8221;;
sayHi[&#8220;text2&#8221;] = &#8220;Hello World... again.&#8221;;
alert(sayHi[&#8220;text&#8221;]); // displays &#8220;Hello World!&#8221;
alert(sayHi.text2); // displays &#8220;Hello World... again.&#8221;
</pre>
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA019">作为对象，函数还可以赋给变量、作为参数传递给其他函数、作为其他函数的值返回，并可以作为对象的属性或数组的元素进行存储等等。<a class=clsFigs onclick="OpenUrl('default.aspx?loc=zh/&amp;fig=true#fig1'); return false;" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh/&amp;fig=true#fig1" target=_self xmlns:user="http://msdn.microsoft.com">图&nbsp;1</a> 提供了这样一个示例。</p>
<p font="minionmmroman" xmlid="PARA020">记住这一点后，向对象添加方法将是很容易的事情：只需选择名称，然后将函数赋给该名称。因此，我通过将匿名函数分别赋给相应的方法名称，在对象中定义了三个方法：</p>
<p font="mscoderegular" xmlid="PARA021">
<pre class=clsCode>var myDog = {
&#8220;name&#8221; : &#8220;Spot&#8221;,
&#8220;bark&#8221; : function() { alert(&#8220;Woof!&#8221;); },
&#8220;displayFullName&#8221; : function() {
alert(this.name + &#8220; The Alpha Dog&#8221;);
},
&#8220;chaseMrPostman&#8221; : function() {
// implementation beyond the scope of this article
}
};
myDog.displayFullName();
myDog.bark(); // Woof!
</pre>
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA022">C++/C# 开发人员应当很熟悉 displayFullName 函数中使用的&#8220;this&#8221;关键字 — 它引用一个对象，通过对象调用方法（使用 Visual Basic 的开发人员也应当很熟悉它，它在 Visual Basic 中叫做&#8220;Me&#8221;）。因此在上面的示例中，displayFullName 中的&#8220;this&#8221;的值是 myDog 对象。但是，&#8220;this&#8221;的值不是静态的。通过不同对象调用&#8220;this&#8221;时，它的值也会更改以便指向相应的对象，如<a class=clsFigs onclick="OpenUrl('default.aspx?loc=zh/&amp;fig=true#fig2'); return false;" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh/&amp;fig=true#fig2" target=_self xmlns:user="http://msdn.microsoft.com">图&nbsp;2</a> 所示。</p>
<p font="minionmmroman" xmlid="PARA023"><a class=clsFigs onclick="OpenUrl('default.aspx?loc=zh/&amp;fig=true#fig2'); return false;" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh/&amp;fig=true#fig2" target=_self xmlns:user="http://msdn.microsoft.com">图&nbsp;2</a> 中的最后一行表示的是将函数作为对象的方法进行调用的另一种方式。请记住，JavaScript 中的函数是对象。每个函数对象都有一个名为 call 的方法，它将函数作为第一个参数的方法进行调用。就是说，作为函数第一个参数传递给 call 的任何对象都将在函数调用中成为&#8220;this&#8221;的值。这一技术对于调用基类构造函数来说非常有用，稍后将对此进行介绍。</p>
<p font="minionmmroman" xmlid="PARA024">有一点需要记住，绝不要调用包含&#8220;this&#8221;（却没有所属对象）的函数。否则，将违反全局命名空间，因为在该调用中，&#8220;this&#8221;将引用全局对象，而这必然会给您的应用程序带来灾难。例如，下面的脚本将更改 JavaScript 的全局函数 isNaN 的行为。一定不要这样做！</p>
<p font="mscoderegular" xmlid="PARA025">
<pre class=clsCode>alert(&#8220;NaN is NaN: &#8220; + isNaN(NaN));
function x() {
this.isNaN = function() {
return &#8220;not anymore!&#8221;;
};
}
// alert!!! trampling the Global object!!!
x();
alert(&#8220;NaN is NaN: &#8220; + isNaN(NaN));
</pre>
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA026">到这里，我们已经介绍了如何创建对象，包括它的属性和方法。但如果注意上面的所有代码段，您会发现属性和方法是在对象定义本身中进行硬编码的。但如果需要更好地控制对象的创建，该怎么做呢？例如，您可能需要根据某些参数来计算对象的属性值。或者，可能需要将对象的属性初始化为仅在运行时才能获得的值。也可能需要创建对象的多个实例（此要求非常常见）。</p>
<p font="minionmmroman" xmlid="PARA027">在 C# 中，我们使用类来实例化对象实例。但 JavaScript 与此不同，因为它没有类。您将在下一节中看到，您可以充分利用这一情况：函数在与&#8220;new&#8221;运算符一起使用时，函数将充当构造函数。</p>
<div style="MARGIN-TOP: 5px" align=right><a class=clsSmall onclick="OpenMenu(contentbtn, contentmenu);" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#contents" target=_self><img style="MARGIN-LEFT: 5px" height=8 alt="Back to top" src="http://msdn.microsoft.com/msdnmag/images/top.gif" width=18 align=bottom border=0></a></div>
<br><a name=S3></a><span class=clsSubhead>构造函数而不是类</span><br>
<p font="minionmmroman" xmlid="PARA028">前面提到过，有关 JavaScript OOP 的最奇怪的事情是，JavaScript 不像 C# 或 C++ 那样，它没有类。在 C# 中，在执行类似下面的操作时：</p>
<p font="mscoderegular" xmlid="PARA029">
<pre class=clsCode>Dog spot = new Dog();
</pre>
将返回一个对象，该对象是 Dog 类的实例。但在 JavaScript 中，本来就没有类。与访问类最近似的方法是定义构造函数，如下所示：
<p>&#160;</p>
<p font="mscoderegular" xmlid="PARA030">
<pre class=clsCode>function DogConstructor(name) {
this.name = name;
this.respondTo = function(name) {
if(this.name == name) {
alert(&#8220;Woof&#8221;);
}
};
}
var spot = new DogConstructor(&#8220;Spot&#8221;);
spot.respondTo(&#8220;Rover&#8221;); // nope
spot.respondTo(&#8220;Spot&#8221;); // yeah!
</pre>
那么，结果会怎样呢？暂时忽略 DogConstructor 函数定义，看一看这一行：
<p>&#160;</p>
<p font="mscoderegular" xmlid="PARA031">
<pre class=clsCode>var spot = new DogConstructor(&#8220;Spot&#8221;);
</pre>
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA032">&#8220;new&#8221;运算符执行的操作很简单。首先，它创建一个新的空对象。然后执行紧随其后的函数调用，将新的空对象设置为该函数中&#8220;this&#8221;的值。换句话说，可以认为上面这行包含&#8220;new&#8221;运算符的代码与下面两行代码的功能相当：</p>
<p font="mscoderegular" xmlid="PARA033">
<pre class=clsCode>// create an empty object
var spot = {};
// call the function as a method of the empty object
DogConstructor.call(spot, &#8220;Spot&#8221;);
</pre>
正如在 DogConstructor 主体中看到的那样，调用此函数将初始化对象，在调用期间关键字&#8220;this&#8221;将引用此对象。这样，就可以为对象创建模板！只要需要创建类似的对象，就可以与构造函数一起调用&#8220;new&#8221;，返回的结果将是一个完全初始化的对象。这与类非常相似，不是吗？实际上，在 JavaScript 中构造函数的名称通常就是所模拟的类的名称，因此在上面的示例中，可以直接命名构造函数 Dog：
<p>&#160;</p>
<p font="mscoderegular" xmlid="PARA034">
<pre class=clsCode>// Think of this as class Dog
function Dog(name) {
// instance variable
this.name = name;
// instance method? Hmmm...
this.respondTo = function(name) {
if(this.name == name) {
alert(&#8220;Woof&#8221;);
}
};
}
var spot = new Dog(&#8220;Spot&#8221;);
</pre>
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA035">在上面的 Dog 定义中，我定义了名为 name 的实例变量。使用 Dog 作为其构造函数所创建的每个对象都有它自己的实例变量名称副本（前面提到过，它就是对象词典的条目）。这就是希望的结果。毕竟，每个对象都需要它自己的实例变量副本来表示其状态。但如果看看下一行，就会发现每个 Dog 实例也都有它自己的 respondTo 方法副本，这是个浪费；您只需要一个可供各个 Dog 实例共享的 respondTo 实例！通过在 Dog 以外定义 respondTo，可以避免此问题，如下所示：</p>
<p font="mscoderegular" xmlid="PARA036">
<pre class=clsCode>function respondTo() {
// respondTo definition
}
function Dog(name) {
this.name = name;
// attached this function as a method of the object
this.respondTo = respondTo;
}
</pre>
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA037">这样，所有 Dog 实例（即用构造函数 Dog 创建的所有实例）都可以共享 respondTo 方法的一个实例。但随着方法数的增加，维护工作将越来越难。最后，基本代码中将有很多全局函数，而且随着&#8220;类&#8221;的增加，事情只会变得更加糟糕（如果它们的方法具有相似的名称，则尤甚）。但使用原型对象可以更好地解决这个问题，这是下一节的主题。</p>
<div style="MARGIN-TOP: 5px" align=right><a class=clsSmall onclick="OpenMenu(contentbtn, contentmenu);" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#contents" target=_self><img style="MARGIN-LEFT: 5px" height=8 alt="Back to top" src="http://msdn.microsoft.com/msdnmag/images/top.gif" width=18 align=bottom border=0></a></div>
<br><a name=S4></a><span class=clsSubhead>原型</span><br>
<p font="minionmmroman" xmlid="PARA038">在使用 JavaScript 的面向对象编程中，原型对象是个核心概念。在 JavaScript 中对象是作为现有示例（即原型）对象的副本而创建的，该名称就来自于这一概念。此原型对象的任何属性和方法都将显示为从原型的构造函数创建的对象的属性和方法。可以说，这些对象从其原型继承了属性和方法。当您创建如下所示的新 Dog 对象时：</p>
<p font="mscoderegular" xmlid="PARA039">
<pre class=clsCode>var buddy = new Dog(&#8220;Buddy&#8220;);
</pre>
buddy 所引用的对象将从它的原型继承属性和方法，尽管仅从这一行可能无法明确判断原型来自哪里。对象 buddy 的原型来自构造函数（在这里是函数 Dog）的属性。
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA040">在 JavaScript 中，每个函数都有名为&#8220;prototype&#8221;的属性，用于引用原型对象。此原型对象又有名为&#8220;constructor&#8221;的属性，它反过来引用函数本身。这是一种循环引用，<span class=clsFigs xmlns:user="http://msdn.microsoft.com">图&nbsp;3</span> 更好地说明了这种循环关系。</p>
<div id=101335002 style="DISPLAY: block; MARGIN: 5px 0px 10px 5px; WIDTH: 335px"><img height=101 alt="图 3 每个函数的原型都有一个 Constructor 属性" src="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/zh/fig03.gif" width=335 border=0><br><span class=clsCap>图 3</span>&nbsp;<span class=clsCaptxt>每个函数的原型都有一个 Constructor 属性</span></div>
<p font="minionmmroman" xmlid="PARA041">现在，通过&#8220;new&#8221;运算符用函数（上面示例中为 Dog）创建对象时，所获得的对象将继承 Dog.prototype 的属性。在<span class=clsFigs xmlns:user="http://msdn.microsoft.com">图&nbsp;3</span> 中，可以看到 Dog.prototype 对象有一个回指 Dog 函数的构造函数属性。这样，每个 Dog 对象（从 Dog.prototype 继承而来）都有一个回指 Dog 函数的构造函数属性。<a class=clsFigs onclick="OpenUrl('default.aspx?loc=zh/&amp;fig=true#fig4'); return false;" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh/&amp;fig=true#fig4" target=_self xmlns:user="http://msdn.microsoft.com">图&nbsp;4</a> 中的代码证实了这一点。<span class=clsFigs xmlns:user="http://msdn.microsoft.com">图&nbsp;5</span> 显示了构造函数、原型对象以及用它们创建的对象之间的这一关系。</p>
<div id=266295004 style="DISPLAY: block; MARGIN: 5px 0px 10px 5px; WIDTH: 295px"><img height=266 alt="图 5 实例继承其原型" src="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/zh/fig05.gif" width=295 border=0><br><span class=clsCap>图 5</span>&nbsp;<span class=clsCaptxt>实例继承其原型</span></div>
<p font="minionmmroman" xmlid="PARA042">某些读者可能已经注意到<a class=clsFigs onclick="OpenUrl('default.aspx?loc=zh/&amp;fig=true#fig4'); return false;" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh/&amp;fig=true#fig4" target=_self xmlns:user="http://msdn.microsoft.com">图&nbsp;4</a> 中对 hasOwnProperty 和 isPrototypeOf 方法的调用。这些方法是从哪里来的呢？它们不是来自 Dog.prototype。实际上，在 Dog.prototype 和 Dog 实例中还可以调用其他方法，比如 toString、toLocaleString 和 valueOf，但它们都不来自 Dog.prototype。您会发现，就像 .NET Framework 中的 System.Object 充当所有类的最终基类一样，JavaScript 中的 Object.prototype 是所有原型的最终基础原型。（Object.prototype 的原型是 null。）</p>
<p font="minionmmroman" xmlid="PARA043">在此示例中，请记住 Dog.prototype 是对象。它是通过调用 Object 构造函数创建的（尽管它不可见）：</p>
<p font="mscoderegular" xmlid="PARA044">
<pre class=clsCode>Dog.prototype = new Object();
</pre>
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA045">因此，正如 Dog 实例继承 Dog.prototype 一样，Dog.prototype 继承 Object.prototype。这使得所有 Dog 实例也继承了 Object.prototype 的方法和属性。</p>
<p font="minionmmroman" xmlid="PARA046">每个 JavaScript 对象都继承一个原型链，而所有原型都终止于 Object.prototype。注意，迄今为止您看到的这种继承是活动对象之间的继承。它不同于继承的常见概念，后者是指在声明类时类之间的发生的继承。因此，JavaScript 继承动态性更强。它使用简单算法实现这一点，如下所示：当您尝试访问对象的属性/方法时，JavaScript 将检查该属性/方法是否是在该对象中定义的。如果不是，则检查对象的原型。如果还不是，则检查该对象的原型的原型，如此继续，一直检查到 Object.prototype。<span class=clsFigs xmlns:user="http://msdn.microsoft.com">图&nbsp;6</span> 说明了此解析过程。</p>
<div id=495525006 style="DISPLAY: none; WIDTH: 525px"><a href="javascript:ToggleImages('495525006', '303321006');"><img height=495 alt="图 6 在原型链中解析 toString() 方法" src="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/zh/fig06_L.gif" width=525 border=0></a><br><span class=clsCap>图 6</span>&nbsp;<span class=clsCaptxt>在原型链中解析 toString() 方法 (单击该图像获得较小视图) </span></div>
<div id=303321006 style="DISPLAY: block; MARGIN: 5px 0px 10px 5px; WIDTH: 321px"><a href="javascript:ToggleImages('303321006', '495525006');"><img height=303 alt="图 6 在原型链中解析 toString() 方法" src="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/zh/fig06.gif" width=321 border=0></a><br><span class=clsCap>图 6</span>&nbsp;<span class=clsCaptxt>在原型链中解析 toString() 方法 (单击该图像获得较大视图) </span></div>
<p font="minionmmroman" xmlid="PARA047">JavaScript 动态地解析属性访问和方法调用的方式产生了一些特殊效果：
<ul>
    <li>继承原型对象的对象上可以立即呈现对原型所做的更改，即使是在创建这些对象之后。
    <li>如果在对象中定义了属性/方法 X，则该对象的原型中将隐藏同名的属性/方法。例如，通过在 Dog.prototype 中定义 toString 方法，可以改写 Object.prototype 的 toString 方法。
    <li>更改只沿一个方向传递，即从原型到它的派生对象，但不能沿相反方向传递。</li>
</ul>
<p>&#160;</p>
<p font="franklingothiccondensed" xmlid="PARA048"><a class=clsFigs onclick="OpenUrl('default.aspx?loc=zh/&amp;fig=true#fig7'); return false;" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh/&amp;fig=true#fig7" target=_self xmlns:user="http://msdn.microsoft.com">图&nbsp;7</a> 说明了这些效果。<a class=clsFigs onclick="OpenUrl('default.aspx?loc=zh/&amp;fig=true#fig7'); return false;" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh/&amp;fig=true#fig7" target=_self xmlns:user="http://msdn.microsoft.com">图&nbsp;7</a> 还显示了如何解决前面遇到的不需要的方法实例的问题。通过将方法放在原型内部，可以使对象共享方法，而不必使每个对象都有单独的函数对象实例。在此示例中，rover 和 spot 共享 getBreed 方法，直至在 spot 中以任何方式改写 toString 方法。此后，spot 有了它自己版本的 getBreed 方法，但 rover 对象和用新 GreatDane 创建的后续对象仍将共享在 GreatDane.prototype 对象中定义的那个 getBreed 方法实例。</p>
<div style="MARGIN-TOP: 5px" align=right><a class=clsSmall onclick="OpenMenu(contentbtn, contentmenu);" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#contents" target=_self><img style="MARGIN-LEFT: 5px" height=8 alt="Back to top" src="http://msdn.microsoft.com/msdnmag/images/top.gif" width=18 align=bottom border=0></a></div>
<br><a name=S5></a><span class=clsSubhead>静态属性和方法</span><br>
<p font="minionmmroman" xmlid="PARA049">有时，您需要绑定到类而不是实例的属性或方法，也就是，静态属性和方法。在 JavaScript 中很容易做到这一点，因为函数是可以按需要设置其属性和方法的对象。由于在 JavaScript 中构造函数表示类，因此可以通过在构造函数中设置静态方法和属性，直接将它们添加到类中，如下所示：</p>
<p font="mscoderegular" xmlid="PARA050">
<pre class=clsCode>    function DateTime() { }
// set static method now()
DateTime.now = function() {
return new Date();
};
alert(DateTime.now());
</pre>
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA051">在 JavaScript 中调用静态方法的语法与在 C# 中几乎完全相同。这不应当让人感到吃惊，因为构造函数的名称实际上是类的名称。这样，就有了类、公用属性/方法，以及静态属性/方法。还需要其他什么吗？当然，私有成员。但 JavaScript 本身并不支持私有成员（同样，也不支持受保护成员）。任何人都可以访问对象的所有属性和方法。但我们有办法让类中包含私有成员，但在此之前，您首先需要理解闭包。</p>
<div style="MARGIN-TOP: 5px" align=right><a class=clsSmall onclick="OpenMenu(contentbtn, contentmenu);" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#contents" target=_self><img style="MARGIN-LEFT: 5px" height=8 alt="Back to top" src="http://msdn.microsoft.com/msdnmag/images/top.gif" width=18 align=bottom border=0></a></div>
<br><a name=S6></a><span class=clsSubhead>闭包</span><br>
<p font="minionmmroman" xmlid="PARA052">我没有自觉地学习过 JavaScript。我必须快点了解它，因为我发现如果没有它，在实际工作中编写 AJAX 应用程序的准备就会不充分。开始，我感到我的编程水平好像降了几个级别。（JavaScript！我的 C++ 朋友会怎么说？）但一旦我克服最初的障碍，我就发现 JavaScript 实际上是功能强大、表现力强而且非常简练的语言。它甚至具有其他更流行的语言才刚刚开始支持的功能。</p>
<p font="minionmmroman" xmlid="PARA053">JavaScript 的更高级功能之一是它支持闭包，这是 C# 2.0 通过它的匿名方法支持的功能。闭包是当内部函数（或 C# 中的内部匿名方法）绑定到它的外部函数的本地变量时所发生的运行时现象。很明显，除非此内部函数以某种方式可被外部函数访问，否则它没有多少意义。示例可以更好说明这一点。</p>
<p font="minionmmroman" xmlid="PARA054">假设需要根据一个简单条件筛选一个数字序列，这个条件是：只有大于 100 的数字才能通过筛选，并忽略其余数字。为此，可以编写类似<a class=clsFigs onclick="OpenUrl('default.aspx?loc=zh/&amp;fig=true#fig8'); return false;" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh/&amp;fig=true#fig8" target=_self xmlns:user="http://msdn.microsoft.com">图&nbsp;8</a> 中的函数。</p>
<p font="minionmmroman" xmlid="PARA055">但是，现在要创建不同的筛选条件，假设这次只有大于 300 的数字才能通过筛选，则可以编写下面这样的函数：</p>
<p font="mscoderegular" xmlid="PARA056">
<pre class=clsCode>var greaterThan300 = filter(
function(x) { return (x &gt; 300) ? true : false; },
someRandomNumbers);
</pre>
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA057">然后，也许需要筛选大于 50、25、10、600 如此等等的数字，但作为一个聪明人，您会发现它们全部都有相同的谓词&#8220;greater than&#8221;，只有数字不同。因此，可以用类似下面的函数分开各个数字：</p>
<p font="mscoderegular" xmlid="PARA058">
<pre class=clsCode>function makeGreaterThanPredicate(lowerBound) {
return function(numberToCheck) {
return (numberToCheck &gt; lowerBound) ? true : false;
};
}
</pre>
这样，您就可以编写以下代码：
<p>&#160;</p>
<p font="mscoderegular" xmlid="PARA059">
<pre class=clsCode>var greaterThan10 = makeGreaterThanPredicate(10);
var greaterThan100 = makeGreaterThanPredicate(100);
alert(filter(greaterThan10, someRandomNumbers));
alert(filter(greaterThan100, someRandomNumbers));
</pre>
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA060">通过观察函数 makeGreaterThanPredicate 返回的内部匿名函数，可以发现，该匿名内部函数使用 lowerBound，后者是传递给 makeGreaterThanPredicate 的参数。按照作用域的一般规则，当 makeGreaterThanPredicate 退出时，lowerBound 超出了作用域！但在这里，内部匿名函数仍然携带 lowerBound，甚至在 makeGreaterThanPredicate 退出之后的很长时间内仍然如此。这就是我们所说的闭包：因为内部函数关闭了定义它的环境（即外部函数的参数和本地变量）。</p>
<p font="minionmmroman" xmlid="PARA061">开始可能感觉不到闭包的功能很强大。但如果应用恰当，它们就可以非常有创造性地帮您将想法转换成代码，这个过程非常有趣。在 JavaScript 中，闭包最有趣的用途之一是模拟类的私有变量。</p>
<div style="MARGIN-TOP: 5px" align=right><a class=clsSmall onclick="OpenMenu(contentbtn, contentmenu);" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#contents" target=_self><img style="MARGIN-LEFT: 5px" height=8 alt="Back to top" src="http://msdn.microsoft.com/msdnmag/images/top.gif" width=18 align=bottom border=0></a></div>
<br><a name=S7></a><span class=clsSubhead>模拟私有属性</span><br>
<p font="minionmmroman" xmlid="PARA062">现在介绍闭包如何帮助模拟私有成员。正常情况下，无法从函数以外访问函数内的本地变量。函数退出之后，由于各种实际原因，该本地变量将永远消失。但是，如果该本地变量被内部函数的闭包捕获，它就会生存下来。这一事实是模拟 JavaScript 私有属性的关键。假设有一个 Person 类：</p>
<p font="mscoderegular" xmlid="PARA063">
<pre class=clsCode>function Person(name, age) {
this.getName = function() { return name; };
this.setName = function(newName) { name = newName; };
this.getAge = function() { return age; };
this.setAge = function(newAge) { age = newAge; };
}
</pre>
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA064">参数 name 和 age 是构造函数 Person 的本地变量。Person 返回时，name 和 age 应当永远消失。但是，它们被作为 Person 实例的方法而分配的四个内部函数捕获，实际上这会使 name 和 age 继续存在，但只能严格地通过这四个方法访问它们。因此，您可以：</p>
<p font="mscoderegular" xmlid="PARA065">
<pre class=clsCode>var ray = new Person(&#8220;Ray&#8221;, 31);
alert(ray.getName());
alert(ray.getAge());
ray.setName(&#8220;Younger Ray&#8221;);
// Instant rejuvenation!
ray.setAge(22);
alert(ray.getName() + &#8220; is now &#8220; + ray.getAge() +
&#8220; years old.&#8221;);
</pre>
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA066">未在构造函数中初始化的私有成员可以成为构造函数的本地变量，如下所示：</p>
<p font="mscoderegular" xmlid="PARA067">
<pre class=clsCode>function Person(name, age) {
var occupation;
this.getOccupation = function() { return occupation; };
this.setOccupation = function(newOcc) { occupation =
newOcc; };
// accessors for name and age
}
</pre>
注意，这些私有成员与我们期望从 C# 中产生的私有成员略有不同。在 C# 中，类的公用方法可以访问它的私有成员。但在 JavaScript 中，只能通过在其闭包内拥有这些私有成员的方法来访问私有成员（由于这些方法不同于普通的公用方法，它们通常被称为特权方法）。因此，在 Person 的公用方法中，仍然必须通过私有成员的特权访问器方法才能访问私有成员：
<p>&#160;</p>
<p font="mscoderegular" xmlid="PARA068">
<pre class=clsCode>Person.prototype.somePublicMethod = function() {
// doesn&#8217;t work!
// alert(this.name);
// this one below works
alert(this.getName());
};
</pre>
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA069">Douglas Crockford 是著名的发现（或者也许是发布）使用闭包来模拟私有成员这一技术的第一人。他的网站 <a href="http://javascript.crockford.com/">javascript.crockford.com</a> 包含有关 JavaScript 的丰富信息，任何对 JavaScript 感兴趣的开发人员都应当仔细研读。</p>
<div style="MARGIN-TOP: 5px" align=right><a class=clsSmall onclick="OpenMenu(contentbtn, contentmenu);" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#contents" target=_self><img style="MARGIN-LEFT: 5px" height=8 alt="Back to top" src="http://msdn.microsoft.com/msdnmag/images/top.gif" width=18 align=bottom border=0></a></div>
<br><a name=S8></a><span class=clsSubhead>从类继承</span><br>
<p font="minionmmroman" xmlid="PARA070">到这里，我们已经了解了构造函数和原型对象如何使您在 JavaScript 中模拟类。您已经看到，原型链可以确保所有对象都有 Object.prototype 的公用方法，以及如何使用闭包来模拟类的私有成员。但这里还缺少点什么。您尚未看到如何从类派生，这在 C# 中是每天必做的工作。遗憾的是，在 JavaScript 中从类继承并非像在 C# 中键入冒号即可继承那样简单，它需要进行更多操作。另一方面，JavaScript 非常灵活，可以有很多从类继承的方式。</p>
<p font="minionmmroman" xmlid="PARA071">例如，有一个基类 Pet，它有一个派生类 Dog，如<span class=clsFigs xmlns:user="http://msdn.microsoft.com">图&nbsp;9</span> 所示。这个在 JavaScript 中如何实现呢？Pet 类很容易。您已经看见如何实现它了：</p>
<div id=410145008 style="DISPLAY: block; MARGIN: 5px 0px 10px 5px; WIDTH: 145px"><img height=410 alt="图 9 类" src="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/zh/fig09.gif" width=145 border=0><br><span class=clsCap>图 9</span>&nbsp;<span class=clsCaptxt>类</span></div>
<p font="mscoderegular" xmlid="PARA072">
<pre class=clsCode>// class Pet
function Pet(name) {
this.getName = function() { return name; };
this.setName = function(newName) { name = newName; };
}
Pet.prototype.toString = function() {
return &#8220;This pet&#8217;s name is: &#8220; + this.getName();
};
// end of class Pet
var parrotty = new Pet(&#8220;Parrotty the Parrot&#8221;);
alert(parrotty);
</pre>
<p>&#160;</p>
<p font="minionmmroman" xmlid="PARA073">现在，如何创建从 Pet 派生的类 Dog 呢？在<span class=clsFigs xmlns:user="http://msdn.microsoft.com">图&nbsp;9</span> 中可以看到，Dog 有另一个属性 breed，它改写了 Pet 的 toString 方法（注意，JavaScript 的约定是方法和属性名称使用 camel 大小写，而不是在 C# 中建议的 Pascal 大小写）。<a class=clsFigs onclick="OpenUrl('default.aspx?loc=zh/&amp;fig=true#fig10'); return false;" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh/&amp;fig=true#fig10" target=_self xmlns:user="http://msdn.microsoft.com">图&nbsp;10</a> 显示如何这样做。</p>
<p font="minionmmroman" xmlid="PARA074">所使用的原型 — 替换技巧正确设置了原型链，因此假如使用 C#，测试的实例将按预期运行。而且，特权方法仍然会按预期运行。</p>
<div style="MARGIN-TOP: 5px" align=right><a class=clsSmall onclick="OpenMenu(contentbtn, contentmenu);" href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=zh#contents" target=_self><img style="MARGIN-LEFT: 5px" height=8 alt="Back to top" src="http://msdn.microsoft.com/msdnmag/images/top.gif" width=18 align=bottom border=0></a></div>
<br><a name=S9></a><span class=clsSubhead>模拟命名空间</span><br>
<p font="minionmmroman" xmlid="PARA075">在 C++ 