<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>dudo博客 &#187; JavaScript</title> <atom:link href="http://dudo.org/archives/tag/javascript/feed" rel="self" type="application/rss+xml" /><link>http://dudo.org</link> <description>华彩绽放，我最绚烂</description> <lastBuildDate>Mon, 21 May 2012 10:44:58 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>Javascript的错还是浏览器的问题——2009年为何显示为109年</title><link>http://dudo.org/archives/2009010415265.html</link> <comments>http://dudo.org/archives/2009010415265.html#comments</comments> <pubDate>Sun, 04 Jan 2009 12:50:39 +0000</pubDate> <dc:creator>dudo</dc:creator> <category><![CDATA[CSS与JS]]></category> <category><![CDATA[Internet Explorer]]></category> <category><![CDATA[JavaScript]]></category> <guid
isPermaLink="false">http://dudo.limewebs.com/?p=264</guid> <description><![CDATA[&#160;&#160;&#160; 在浏览几个网页时，发现有几个网站在显示时间时存在问题，比如今天是2009年1月4日，但是有的网站上却赫然写着今天是109年1月4日（这里有个例子就是中国银行的网站首页）。这是一个奇怪的问题，可看这些网站的代码，大致如下：
var today;
<span
class="readmore"><a
href="http://dudo.org/archives/2009010415265.html" title="Javascript的错还是浏览器的问题——2009年为何显示为109年">阅读全文——共945字</a></span><table
class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;"><tr><td
colspan="5"><b><font
size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td></tr><tr><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important;"> <a
target="_blank" title="Godaddy 2012年5域名优惠码：.com .net 30%优惠" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2012050915855.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2009010415265.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Godaddy 2012年5域名优惠码：.com .net 30%优惠</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="Apple将推出Windows版Safari浏览器？" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F200701161395.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2009010415265.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Apple将推出Windows版Safari浏览器？</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="Godaddy主机优惠码：截止2011年1月22日" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2011010916698.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2009010415265.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/01/09/1991257.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Godaddy主机优惠码：截止2011年1月22日</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="说话间，两年就这样匆匆从指间流走，毕业了！" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2007071821161.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2009010415265.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721534.jpg" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">说话间，两年就这样匆匆从指间流走，毕业了！</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="脑子真的出问题了我" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008030115189.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2009010415265.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">脑子真的出问题了我</font> </a></td></tr><tr><td
colspan="5" align="right"> <a
style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"> <font
size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font> </a></td></tr></table>]]></description> <content:encoded><![CDATA[<p>&nbsp;&nbsp;&nbsp; 在浏览几个网页时，发现有几个网站在显示时间时存在问题，比如今天是2009年1月4日，但是有的网站上却赫然写着今天是<strong>109年1月4日</strong>（这里有个例子就是<a
href="http://www.boc.cn" target="_blank">中国银行</a>的网站首页）。这是一个奇怪的问题，可看这些网站的代码，大致如下：</p><pre name="code" class="js">
var today;
today = new Date();
document.write(today.getYear());</pre><p>从上面的代码来看并不存在任何问题！但是当我们运行这段代码时却发现，在不同的浏览器中返回的结果并不同：在Internet Explorer中返回的是2009，在Firefox、<a
target="_blank" href="http://www.google.com/chrome">Chrome</a>等浏览器中返回的是109。由于目前使用Internet Explorer的用户依然占居绝对多数，因为这个问题很难被发现。不过这足以说明IE和其它浏览器对于getYear()的解释并不一致（这也是Internet Explorer的一贯作风），但是问题究竟出现在哪里呢？是浏览器本身的问题还是Javascript出现了问题呢？我们姑且不去讨论这个，我们先来看看getYear()的具体作用：</p><p><em>在非Internet Explorer浏览器中，getYear()函数返回的是1900到1999间的两位十进制数字，比如1999年，返回是99，这和实际年份正好相同；但是如果年份走出了1999,那么就会一个3位的十进制数字，比如2000年，返回的就是100（99+1），2009返回的就是109（99+10）；</em></p><p><strong>如何解决这个问题？</strong></p><p>很简单，使用getFullYear()这个函数。</p><p><em>在所有的浏览器中，getFullYear()返回的一个四位数的十进制数字。</em></p><p>因此，如果时间不超过9999年，那么就会一直有效。</p><p><a
href="http://www.plus2net.com/javascript_tutorial/getyear.php" target="_blank">getYear()和getFullYear()的区别</a></p><p><strong>几点建议：</strong></p><ol><li>使用多个浏览器测试你的网站。这一点已经不用多说了，这里指的多个浏览器不仅仅是不同类别的浏览器，更包括了浏览器的不同版本；</li><li>获得时间使用服务器端还是客户端。在多数情况下，我建议直接在服务器端获得时间然后再输送到用户浏览器，这样不会因为用户机器时间设置不同而出现问题。但是这也存在一个问题，那就是不同时区内的访问者可能看到的是同一个时间。如果你的网站访问者人群相对固定，那么建议直接在服务器端直接获得时间（这不会浪费太多的解析时间）。</li></ol><table
class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;"><tr><td
colspan="5"><b><font
size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td></tr><tr><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important;"> <a
target="_blank" title="Godaddy 2012年5域名优惠码：.com .net 30%优惠" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2012050915855.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2009010415265.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Godaddy 2012年5域名优惠码：.com .net 30%优惠</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="Apple将推出Windows版Safari浏览器？" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F200701161395.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2009010415265.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Apple将推出Windows版Safari浏览器？</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="Godaddy主机优惠码：截止2011年1月22日" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2011010916698.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2009010415265.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/01/09/1991257.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Godaddy主机优惠码：截止2011年1月22日</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="说话间，两年就这样匆匆从指间流走，毕业了！" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2007071821161.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2009010415265.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721534.jpg" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">说话间，两年就这样匆匆从指间流走，毕业了！</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="脑子真的出问题了我" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008030115189.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2009010415265.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">脑子真的出问题了我</font> </a></td></tr><tr><td
colspan="5" align="right"> <a
style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"> <font
size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font> </a></td></tr></table>]]></content:encoded> <wfw:commentRss>http://dudo.org/archives/2009010415265.html/feed</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>CSS Dock Menu：JS+CSS 仿苹果MAC机桌面导航菜单</title><link>http://dudo.org/archives/2008061911251.html</link> <comments>http://dudo.org/archives/2008061911251.html#comments</comments> <pubDate>Thu, 19 Jun 2008 08:17:00 +0000</pubDate> <dc:creator>dudo</dc:creator> <category><![CDATA[CSS与JS]]></category> <category><![CDATA[css]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[Jquery]]></category> <guid
isPermaLink="false">http://dudo.limewebs.com/?p=250</guid> <description><![CDATA[如果你是苹果机的疯狂粉丝，那么你一定会喜欢我设计的这款CSS Dock Menu。它采用了Jquery的JavaScript库和Fisheye的界面，其中一些图标是我自己设计的。这里有两种样式：底部和顶部。下面我演示一下如何在你的Web页面中使用它：
1、下载源文件
点击下载此文件
<span
class="readmore"><a
href="http://dudo.org/archives/2008061911251.html" title="CSS Dock Menu：JS+CSS 仿苹果MAC机桌面导航菜单">阅读全文——共624字</a></span><table
class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;"><tr><td
colspan="5"><b><font
size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td></tr><tr><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important;"> <a
target="_blank" title="快速认识CSS中的overflow属性" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2009052819289.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008061911251.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/09/07/28864441.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">快速认识CSS中的overflow属性</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="谨慎使用CSS中的星号(*)通配符" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2010050520544.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008061911251.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721345.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">谨慎使用CSS中的星号(*)通配符</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="css教程–十步学会用css建站(全)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F200611090185.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008061911251.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721579.jpg" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">css教程–十步学会用css建站(全)</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="使用CSS简单实现垂直居中" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008062123252.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008061911251.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721571.jpg" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用CSS简单实现垂直居中</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="就 CSS3 向 Eric Meyer 请教的 6 个问题" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008121321264.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008061911251.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721465.jpg" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">就 CSS3 向 Eric Meyer 请教的 6 个问题</font> </a></td></tr><tr><td
colspan="5" align="right"> <a
style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"> <font
size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font> </a></td></tr></table>]]></description> <content:encoded><![CDATA[<p><img
src="http://dudo.org/attachments/month_0806/d200862092722.jpg" border="0" alt="仿苹果机桌面菜单" /><br
/> 如果你是苹果机的疯狂粉丝，那么你一定会喜欢我设计的这款CSS Dock Menu。它采用了<a
href="http://jquery.com/" target="_blank">Jquery</a>的<a
href="http://www.dudo.org/default.asp?tag=JavaScript" target="_blank">JavaScript库</a>和Fisheye的界面，其中一些图标是我自己设计的。这里有两种样式：底部和顶部。下面我演示一下如何在你的Web页面中使用它：</p><p><strong>1、下载源文件</strong></p><p><a
href="http://dudo.org/attachments/month_0806/b200861911438.zip" target="_blank">点击下载此文件</a></p><p><strong>2、插入代码</strong><br
/> 在HTML中的标签中插入如下代码：</p><pre class="HTML" title="code">%MINIFYHTMLe20083765dbd4fd008d21514414d99b80%%MINIFYHTMLe20083765dbd4fd008d21514414d99b81%</pre><pre class="HTML" title="code"><!--[if lt IE 7]>
<mce:style type=&#34;text/css&#34;><!  .dock img { behavior: url(iepngfix.htc) } --></pre><p>第一部分是需要用到的Javascript代码，第二部分是用到的CSS样式表，最后一个是用于<a
href="http://www.dudo.org/article.asp?id=233" target="_blank">Internet Explorer 6中PNG图片的Hack处理</a>。</p><p><strong>3、配置</strong><br
/> 且记要把下面的代码放到HTML中的标签内</p><pre class="JavaScrip" title="code">%MINIFYHTMLe20083765dbd4fd008d21514414d99b82%</pre><p><strong>4 添加或者删除项目</strong><br
/> 向顶部菜单中增加新的项目（注：&lt;span&gt;标签位于&lt;img alt=”" /&gt;之后）：</p><pre class="HTML" title="code"><a class="&quot;dock-item&quot;" href="&quot;#&quot;"><img src="&quot;images/home.png&quot;" alt="&quot;home&quot;" /><span>Home</span></a></pre><p>向底部菜单中增加新项目（注：&lt;span&gt;标签位于&lt;img alt=”" /&gt;之前）：</p><pre class="HTML" title="code"><a class="&quot;dock-item2&quot;" href="&quot;#&quot;"><span>Home</span><img src="&quot;images/home.png&quot;" alt="&quot;home&quot;" /></a></pre><p><strong>浏览器兼容性</strong><br
/> 我在Internet Explorer 6、Internet Explorer 7、<a
href="http://www.dudo.org/default.asp?tag=Opera" target="_blank">Opera 9</a>、Firefox 2以及Safari 2（尽管在Safari中存在一些小问题）中测试通过。<br
/> P.S. FireFox 3中也测试通过（<a
href="http://www.dudo.org/" target="_blank">dudo注</a>）</p><p>演示：<a
href="http://dudo.org/attachments/month_0806/css-dock-menu/css-dock.html" target="_blank">CSS Dock Menu</a><br
/> <a
href="http://dudo.org/attachments/month_0806/css-dock-menu/css-dock-top.html" target="_blank">CSS Dock Memu:top</a><br
/> <a
href="http://dudo.org/attachments/month_0806/css-dock-menu/css-dock-bottom.html" target="_blank">CSS Dock Meu: Bottom </a></p><p>原作者：http://www.ndesign-studio.com/blog/mac/css-dock-menu<br
/> 翻译：<a
href="http://dudo.org/?p=251">http://dudo.org/?p=251</a><br
/> <span
style="color: red;">转载请注意出处，至少保留原作者链接，谢谢！</span></p><table
class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;"><tr><td
colspan="5"><b><font
size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td></tr><tr><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important;"> <a
target="_blank" title="快速认识CSS中的overflow属性" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2009052819289.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008061911251.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/09/07/28864441.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">快速认识CSS中的overflow属性</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="谨慎使用CSS中的星号(*)通配符" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2010050520544.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008061911251.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721345.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">谨慎使用CSS中的星号(*)通配符</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="css教程–十步学会用css建站(全)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F200611090185.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008061911251.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721579.jpg" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">css教程–十步学会用css建站(全)</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="使用CSS简单实现垂直居中" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008062123252.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008061911251.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721571.jpg" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用CSS简单实现垂直居中</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="就 CSS3 向 Eric Meyer 请教的 6 个问题" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008121321264.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008061911251.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721465.jpg" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">就 CSS3 向 Eric Meyer 请教的 6 个问题</font> </a></td></tr><tr><td
colspan="5" align="right"> <a
style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"> <font
size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font> </a></td></tr></table>]]></content:encoded> <wfw:commentRss>http://dudo.org/archives/2008061911251.html/feed</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Yahoo!网站性能最佳体验的34条黄金守则——JavaScript和CSS</title><link>http://dudo.org/archives/2008051417218.html</link> <comments>http://dudo.org/archives/2008051417218.html#comments</comments> <pubDate>Wed, 14 May 2008 14:47:26 +0000</pubDate> <dc:creator>dudo</dc:creator> <category><![CDATA[网站开发]]></category> <category><![CDATA[css]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[tips]]></category> <category><![CDATA[网站性能]]></category> <category><![CDATA[雅虎]]></category> <guid
isPermaLink="false">http://dudo.limewebs.com/?p=216</guid> <description><![CDATA[英文地址：http://developer.yahoo.com/performance/rules.html
中文地址：http://www.dudo.org/article.asp?id=216
&#160;&#160;&#160;&#160;&#160; 在第一部分和第二部分中我们分别介绍了改善网站性能中页面内容和服务器的几条守则，除此之外，JavaScript和CSS也是我们页面中经常用到的内容，对它们的优化也提高网站性能的重要方面：
<span
class="readmore"><a
href="http://dudo.org/archives/2008051417218.html" title="Yahoo!网站性能最佳体验的34条黄金守则——JavaScript和CSS">阅读全文——共4611字</a></span><table
class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;"><tr><td
colspan="5"><b><font
size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td></tr><tr><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important;"> <a
target="_blank" title="Yahoo!网站性能最佳体验的34条黄金守则——图片、Coockie与移动应用" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008051511220.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008051417218.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Yahoo!网站性能最佳体验的34条黄金守则——图片、Coockie与移动应用</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="Yahoo!网站性能最佳体验的34条黄金守则——服务器" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008051322217.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008051417218.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Yahoo!网站性能最佳体验的34条黄金守则——服务器</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="Yahoo!网站性能最佳体验的34条黄金守则——内容" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008051211216.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008051417218.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Yahoo!网站性能最佳体验的34条黄金守则——内容</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="20个优秀网站助你征服CSS" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008083118258.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008051417218.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721469.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">20个优秀网站助你征服CSS</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="提高网站流量：向Google、MSN、Yahoo（雅虎）提交你的SiteMap" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2007052422133.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008051417218.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721516.gif" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">提高网站流量：向Google、MSN、Yahoo（雅虎）提交你的SiteMap</font> </a></td></tr><tr><td
colspan="5" align="right"> <a
style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"> <font
size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font> </a></td></tr></table>]]></description> <content:encoded><![CDATA[<p>英文地址：<a
target="_blank" href="http://developer.yahoo.com/performance/rules.html">http://developer.yahoo.com/performance/rules.html</a><br
/> 中文地址：<a
href="http://www.dudo.org/article.asp?id=214" target="_blank">http://www.dudo.org/article.asp?id=216</a><br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在<a
href="http://www.dudo.org/article.asp?id=214" target="_blank">第一部</a>分和<a
href="http://www.dudo.org/article.asp?id=215" target="_blank">第二部分</a>中我们分别介绍了改善网站性能中<a
href="http://www.dudo.org/article.asp?id=214" target="_blank">页面内容</a>和<a
href="http://www.dudo.org/article.asp?id=215" target="_blank">服务器</a>的几条守则，除此之外，JavaScript和CSS也是我们页面中经常用到的内容，对它们的优化也提高网站性能的重要方面：<br
/> <strong>CSS：</strong></p><ol><li><a
href="#csstop">把样式表置于顶部</a></li><li><a
href="#expression">避免使用CSS表达式（Expression）</a></li><li><a
href="#external">使用外部JavaScript和CSS</a></li><li><a
href="#minify">削减JavaScript和CSS</a></li><li><a
href="#link">用&lt;link&gt;代替@import</a></li><li><a
href="#nofilter">避免使用滤镜</a></li></ol><p><strong>JavaScript</strong></p><ol><li><a
href="#bt_js">把脚本置于页面底部</a></li><li><a
href="#external">使用外部JavaScript和CSS</a></li><li><a
href="#minify">削减JavaScript和CSS</a></li><li><a
href="#js_dupes">剔除重复脚本</a></li><li><a
href="#dom_access">减少DOM访问</a></li><li><a
href="#event">开发智能事件处理程序</a></li></ol><p> <a
name="csstop"><span
style="font-size: 16px;"><strong>17、把样式表置于顶部</strong></span></a><br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在研究Yahoo!的性能表现时，我们发现把样式表放到文档的&lt;head /&gt;内部似乎会加快页面的下载速度。这是因为把样式表放到&lt;head /&gt;内会使页面有步骤的加载显示。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 注重性能的前端服务器往往希望页面有秩序地加载。同时，我们也希望浏览器把已经接收到内容尽可能显示出来。这对于拥有较多内容的页面和网速较慢的用户来说特别重要。向用户返回可视化的反馈，比如进程指针，已经有了较好的研究并形成了<a
target="_blank" href="http://www.useit.com/papers/responsetime.html">正式文档</a>。在我们的研究中HTML页面就是进程指针。当浏览器有序地加载文件头、导航栏、顶部的logo等对于等待页面加载的用户来说都可以作为可视化的反馈。这从整体上改善了用户体验。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 把样式表放在文档底部的问题是在包括Internet Explorer在内的很多浏览器中这会中止内容的有序呈现。浏览器中止呈现是为了避免样式改变引起的页面元素重绘。用户不得不面对一个空白页面。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a
target="_blank" href="http://www.w3.org/TR/html4/struct/links.html#h-12.3">HTML规范</a>清楚指出样式表要放包含在页面的&lt;head /&gt;区域内：&ldquo;和&lt;a /&gt;不同，&lt;link /&gt;只能出现在文档的&lt;head /&gt;区域内，尽管它可以多次使用它&rdquo;。无论是引起白屏还是出现没有样式化的内容都不值得去尝试。最好的方案就是按照HTML规范在文档&lt;head /&gt;内加载你的样式表。</p><p><a
name="expression"></a><strong><a>18、避免使用CSS表达式（Expression）</a> </strong><br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CSS表达式是动态设置CSS属性的强大（但危险）方法。Internet Explorer从<a
traget="_blank" href="http://msdn.microsoft.com/workshop/author/dhtml/overview/recalc.asp">第5个版本</a>开始支持CSS表达式。下面的例子中，使用CSS表达式可以实现隔一个小时切换一次背景颜色：<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; background-color: expression( (new Date()).getHours()%2 ? &quot;#B8D4FF&quot; : &quot;#F08A00&quot; ); <br
/> 如上所示，expression中使用了JavaScript表达式。CSS属性根据JavaScript表达式的计算结果来设置。expression方法在其它浏览器中不起作用，因此在跨浏览器的设计中单独针对Internet Explorer设置时会比较有用。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 表达式的问题就在于它的计算频率要比我们想象的多。不仅仅是在页面显示和缩放时，就是在页面滚动、乃至移动鼠标时都会要重新计算一次。给CSS表达式增加一个计数器可以跟踪表达式的计算频率。在页面中随便移动鼠标都可以轻松达到10000次以上的计算量。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一个减少CSS表达式计算次数的方法就是使用一次性的表达式，它在第一次运行时将结果赋给指定的样式属性，并用这个属性来代替CSS表达式。如果样式属性必须在页面周期内动态地改变，使用事件句柄来代替CSS表达式是一个可行办法。如果必须使用CSS表达式，一定要记住它们要计算成千上万次并且可能会对你页面的性能产生影响。</p><p><a
name="external"><span
style="font-size: 16px;"><strong>19、使用外部JavaScript和CSS </strong></span></a><br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 很多性能规则都是关于如何处理外部文件的。但是，在你采取这些措施前你可能会问到一个更基本的问题：JavaScript和CSS是应该放在外部文件中呢还是把它们放在页面本身之内呢？<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在实际应用中使用外部文件可以提高页面速度，因为JavaScript和CSS文件都能在浏览器中产生缓存。内置在HTML文档中的JavaScript和CSS则会在每次请求中随HTML文档重新下载。这虽然减少了HTTP请求的次数，却增加了HTML文档的大小。从另一方面来说，如果外部文件中的JavaScript和CSS被浏览器缓存，在没有增加HTTP请求次数的同时可以减少HTML文档的大小。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 关键问题是，外部JavaScript和CSS文件缓存的频率和请求HTML文档的次数有关。虽然有一定的难度，但是仍然有一些指标可以一测量它。如果一个会话中用户会浏览你网站中的多个页面，并且这些页面中会重复使用相同的脚本和样式表，缓存外部文件就会带来更大的益处。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 许多网站没有功能建立这些指标。对于这些网站来说，最好的坚决方法就是把JavaScript和CSS作为外部文件引用。比较适合使用内置代码的例外就是网站的主页，如<a
target="_blank" href="http://www.yahoo.com/">Yahoo!主页</a>和<a
target="_blank" href="http://my.yahoo.com/">My Yahoo!</a>。主页在一次会话中拥有较少（可能只有一次）的浏览量，你可以发现内置JavaScript和CSS对于终端用户来说会加快响应时 间。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 对于拥有较大浏览量的首页来说，有一种技术可以平衡内置代码带来的HTTP请求减少与通过使用外部文件进行缓存带来的好处。其中一个就是在首页中内置JavaScript和CSS，但是在页面下载完成后动态下载外部文件，在子页面中使用到这些文件时，它们已经缓存到浏览器了。</p><p><a
name="minify"><span
style="font-size: 16px;"><strong>20、削减JavaScript和CSS </strong></span></a><br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 精简是指从去除代码不必要的字符减少文件大小从而节省下载时间。消减代码时，所有的注释、不需要的空白字符（空格、换行、tab缩进）等都要去掉。在JavaScript中，由于需要下载的文件体积变小了从而节省了响应时间。精简JavaScript中目前用到的最广泛的两个工具是<a
target="_blank" href="http://crockford.com/javascript/jsmin">JSMin</a>和<a
target="_blank" href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a>。YUI Compressor还可用于精简CSS。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 混淆是另外一种可用于源代码优化的方法。这种方法要比精简复杂一些并且在混淆的过程更易产生问题。在对美国前10大网站的调查中发现，精简也可以缩小原来代码体积的21%，而混淆可以达到25%。尽管混淆法可以更好地缩减代码，但是对于JavaScript来说精简的风险更小。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 除消减外部的脚本和样式表文件外，&lt;script&gt;和&lt;style&gt;代码块也可以并且应该进行消减。即使你用Gzip压缩过脚本和样式表，精简这些文件仍然可以节省5%以上的空间。由于JavaScript和CSS的功能和体积的增加，消减代码将会获得益处。</p><p><a
name="link"><span
style="font-size: 16px;"><strong>21、用&lt;link&gt;代替@import</strong></span></a><br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 前面的最佳实现中提到CSS应该放置在顶端以利于有序加载呈现。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在IE中，页面底部@import和使用&lt;link&gt;作用是一样的，因此最好不要使用它。</p><p><a
name="nofilter"><span
style="font-size: 16px;"><strong>22、避免使用滤镜</strong></span></a><br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IE独有属性AlphaImageLoader用于修正7.0以下版本中显示PNG图片的半透明效果。这个滤镜的问题在于浏览器加载图片时它会终止内容的呈现并且冻结浏览器。在每一个元素（不仅仅是图片）它都会运算一次，增加了内存开支，因此它的问题是多方面的。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 完全避免使用AlphaImageLoader的最好方法就是使用PNG8格式来代替，这种格式能在IE中很好地工作。如果你确实需要使用AlphaImageLoader，请使用下划线_filter又使之对IE7以上版本的用户无效。</p><p><a
name="bt_js"><span
style="font-size: 16px;"><strong>23、把脚本置于页面底部</strong></span></a><br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 脚本带来的问题就是它阻止了页面的平行下载。<a
target="_blank" href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.1.4">HTTP/1.1 规范</a>建议，浏览器每个主机名的并行下载内容不超过两个。如果你的图片放在多个主机名上，你可以在每个并行下载中同时下载2个以上的文件。但是当下载脚本时，浏览器就不会同时下载其它文件了，即便是主机名不相同。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在某些情况下把脚本移到页面底部可能不太容易。比如说，如果脚本中使用了document.write来插入页面内容，它就不能被往下移动了。这里可能还会有作用域的问题。很多情况下，都会遇到这方面的问题。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一个经常用到的替代方法就是使用延迟脚本。DEFER属性表明脚本中没有包含document.write，它告诉浏览器继续显示。不幸的是，Firefox并不支持DEFER属性。在Internet Explorer中，脚本可能会被延迟但效果也不会像我们所期望的那样。如果脚本可以被延迟，那么它就可以移到页面的底部。这会让你的页面加载的快一点。</p><p><a
name="js_dupes"><span
style="font-size: 16px;"><strong>24、剔除重复脚本</strong></span></a><br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在同一个页面中重复引用JavaScript文件会影响页面的性能。你可能会认为这种情况并不多见。对于美国前10大网站的调查显示其中有两家存在重复引用脚本的情况。有两种主要因素导致一个脚本被重复引用的奇怪现象发生：团队规模和脚本数量。如果真的存在这种情况，重复脚本会引起不必要的HTTP请求和无用的JavaScript运算，这降低了网站性能。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在Internet Explorer中会产生不必要的HTTP请求，而在Firefox却不会。在Internet Explorer中，如果一个脚本被引用两次而且它又不可缓存，它就会在页面加载过程中产生两次HTTP请求。即时脚本可以缓存，当用户重载页面时也会产生额外的HTTP请求。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 除增加额外的HTTP请求外，多次运算脚本也会浪费时间。在Internet Explorer和Firefox中不管脚本是否可缓存，它们都存在重复运算JavaScript的问题。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一个避免偶尔发生的两次引用同一脚本的方法是在模板中使用脚本管理模块引用脚本。在HTML页面中使用&lt;script /&gt;标签引用脚本的最常见方法就是： <br
/> <em> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;script type=&quot;text/javascript&quot; src=&quot;menu_1.0.17.js&quot;&gt;&lt;/script&gt; </em><br
/> 在PHP中可以通过创建名为ins&#101;rtScript的方法来替代： <br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em> &lt;?php ins&#101;rtScript(&quot;menu.js&quot;) ?&gt; </em><br
/> 为了防止多次重复引用脚本，这个方法中还应该使用其它机制来处理脚本，如检查所属目录和为脚本文件名中增加版本号以用于Expire文件头等。</p><p><a
name="dom_access"><span
style="font-size: 16px;"><strong>25、减少DOM访问</strong></span></a><br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 使用JavaScript访问DOM元素比较慢，因此为了获得更多的应该页面，应该做到：</p><ul><li>缓存已经访问过的有关元素</li><li>线下更新完节点之后再将它们添加到文档树中</li><li>避免使用JavaScript来修改页面布局</li></ul><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 有关此方面的更多信息请查看Julien Lecomte在YUI专题中的文章<a
target="_blank" href="http://yuiblog.com/blog/2007/12/20/video-lecomte/">&ldquo;高性能Ajax应该程序&rdquo;</a>。</p><p><a
name="event"><span
style="font-size: 16px;"><strong>26、开发智能事件处理程序</strong></span></a><br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 有时候我们会感觉到页面反应迟钝，这是因为DOM树元素中附加了过多的事件句柄并且些事件句病被频繁地触发。这就是为什么说使用event delegation（事件代理）是一种好方法了。如果你在一个div中有10个按钮，你只需要在div上附加一次事件句柄就可以了，而不用去为每一个按钮增加一个句柄。事件冒泡时你可以捕捉到事件并判断出是哪个事件发出的。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 你同样也不用为了操作DOM树而等待onload事件的发生。你需要做的就是等待树结构中你要访问的元素出现。你也不用等待所有图像都加载完毕。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 你可能会希望用DOMContentLoaded事件来代替onload，但是在所有浏览器都支持它之前你可使用<a
target="_blank" href="http://developer.yahoo.com/yui/event/">YUI 事件</a>应用程序中的<a
target="_blank" href="http://developer.yahoo.com/yui/event/#onavailable">onAvailable</a>方法。<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 有关此方面的更多信息请查看Julien Lecomte在YUI专题中的文章<a
target="_blank" href="http://yuiblog.com/blog/2007/12/20/video-lecomte/">&ldquo;高性能Ajax应该程序&rdquo;</a>。</p><table
class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;"><tr><td
colspan="5"><b><font
size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td></tr><tr><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important;"> <a
target="_blank" title="Yahoo!网站性能最佳体验的34条黄金守则——图片、Coockie与移动应用" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008051511220.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008051417218.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Yahoo!网站性能最佳体验的34条黄金守则——图片、Coockie与移动应用</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="Yahoo!网站性能最佳体验的34条黄金守则——服务器" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008051322217.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008051417218.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Yahoo!网站性能最佳体验的34条黄金守则——服务器</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="Yahoo!网站性能最佳体验的34条黄金守则——内容" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008051211216.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008051417218.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Yahoo!网站性能最佳体验的34条黄金守则——内容</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="20个优秀网站助你征服CSS" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008083118258.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008051417218.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721469.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">20个优秀网站助你征服CSS</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="提高网站流量：向Google、MSN、Yahoo（雅虎）提交你的SiteMap" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2007052422133.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F2008051417218.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721516.gif" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">提高网站流量：向Google、MSN、Yahoo（雅虎）提交你的SiteMap</font> </a></td></tr><tr><td
colspan="5" align="right"> <a
style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"> <font
size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font> </a></td></tr></table>]]></content:encoded> <wfw:commentRss>http://dudo.org/archives/2008051417218.html/feed</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>top、clientTop、scrollTop、offsetTop</title><link>http://dudo.org/archives/200611010280.html</link> <comments>http://dudo.org/archives/200611010280.html#comments</comments> <pubDate>Tue, 31 Oct 2006 18:31:42 +0000</pubDate> <dc:creator>dudo</dc:creator> <category><![CDATA[CSS与JS]]></category> <category><![CDATA[JavaScript]]></category> <guid
isPermaLink="false">http://dudo.limewebs.com/?p=80</guid> <description><![CDATA[以下示例代码：
&#60;html&#62;
&#60;head&#62;
<span
class="readmore"><a
href="http://dudo.org/archives/200611010280.html" title="top、clientTop、scrollTop、offsetTop">阅读全文——共837字</a></span><table
class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;"><tr><td
colspan="5"><b><font
size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td></tr><tr><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important;"> <a
target="_blank" title="[诡异油画]搓麻将的女人" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F200605310939.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200611010280.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721561.jpg" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">[诡异油画]搓麻将的女人</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title=".co域名价格降至与.com相同价位" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2011021411785.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200611010280.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/02/14/2709494.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">.co域名价格降至与.com相同价位</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="极客公园，打造新的信息分享模式" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2010061311569.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200611010280.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721298.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">极客公园，打造新的信息分享模式</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="dudo博客被DMOZ收录" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2011041507828.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200611010280.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/15/5611243.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">dudo博客被DMOZ收录</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="快速认识CSS中的overflow属性" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2009052819289.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200611010280.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/09/07/28864441.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">快速认识CSS中的overflow属性</font> </a></td></tr><tr><td
colspan="5" align="right"> <a
style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"> <font
size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font> </a></td></tr></table>]]></description> <content:encoded><![CDATA[<p><img
alt="" border="0" src="http://dudo.org/attachments/month_0611/p200611123030.gif" /> <span
style="font-weight: bold; color: rgb(255,0,0)">以下示例代码：</span></p><div
id="myCode" style="overflow: auto; height: 300px">&lt;html&gt;<br
/> &lt;head&gt;<br
/> &lt;title&gt;51windows.Net &lt;/title&gt;<br
/> &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gb2312&quot;&gt;<br
/> &lt;style type=&quot;text/css&quot;&gt;<br
/> &lt;/style&gt;<br
/> &lt;/head&gt;<br
/> &lt;body&gt;<br
/> &lt;SCRIPT LANGUAGE=&quot;JavaScript&quot;&gt;<br
/> var&nbsp; s = &quot;&quot;;<br
/> s += &quot;\r\n网页可见区域宽：&quot;+ document.body.clientWidth;<br
/> s += &quot;\r\n网页可见区域高：&quot;+ document.body.clientHeight;<br
/> s += &quot;\r\n网页可见区域宽：&quot;+ document.body.offsetWidth&nbsp; +&quot; (包括边线的宽)&quot;;<br
/> s += &quot;\r\n网页可见区域高：&quot;+ document.body.offsetHeight +&quot; (包括边线的宽)&quot;;<br
/> s += &quot;\r\n网页正文全文宽：&quot;+ document.body.scrollWidth;<br
/> s += &quot;\r\n网页正文全文高：&quot;+ document.body.scrollHeight;<br
/> s += &quot;\r\n网页被卷去的高：&quot;+ document.body.scrollTop;<br
/> s += &quot;\r\n网页被卷去的左：&quot;+ document.body.scrollLeft;<br
/> s += &quot;\r\n网页正文部分上：&quot;+ window.screenTop;<br
/> s += &quot;\r\n网页正文部分左：&quot;+ window.screenLeft;<br
/> s += &quot;\r\n屏幕分辨率的高：&quot;+ window.screen.height;<br
/> s += &quot;\r\n屏幕分辨率的宽：&quot;+ window.screen.width;<br
/> s += &quot;\r\n屏幕可用工作区高度：&quot;+ window.screen.availHeight;<br
/> s += &quot;\r\n屏幕可用工作区宽度：&quot;+ window.screen.availWidth;<br
/> alert(s);<br
/> &lt;/SCRIPT&gt;<br
/> &lt;/body&gt;<br
/> &lt;/html&gt;</div> <input
type="button" onclick="document.write(myCode.innerHTML)" value="运行代码" /><table
class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;"><tr><td
colspan="5"><b><font
size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td></tr><tr><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important;"> <a
target="_blank" title="我的台湾这旅（三）——鼎泰丰、何润东、故宫博物院、101大厦" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2007091901167.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200611010280.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721425.jpg" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">我的台湾这旅（三）——鼎泰丰、何润东、故宫博物院、101大厦</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="越狱归来——PrisonBreak" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2007012312102.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200611010280.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721500.jpg" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">越狱归来——PrisonBreak</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="遥相呼应:IE Developer Toolbar Beta 3 – Now Available" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F200701201997.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200611010280.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721409.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">遥相呼应:IE Developer Toolbar Beta 3 – Now Available</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="发几张手机图片" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2007042415114.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200611010280.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721497.jpg" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">发几张手机图片</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="《精通CSS（CSS Mastery）》T楼结果公布" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2010081921643.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200611010280.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721282.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">《精通CSS（CSS Mastery）》T楼结果公布</font> </a></td></tr><tr><td
colspan="5" align="right"> <a
style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"> <font
size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font> </a></td></tr></table>]]></content:encoded> <wfw:commentRss>http://dudo.org/archives/200611010280.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>用JS实现“左中DIV”和“右中DIV”等高</title><link>http://dudo.org/archives/200609210265.html</link> <comments>http://dudo.org/archives/200609210265.html#comments</comments> <pubDate>Wed, 20 Sep 2006 18:38:37 +0000</pubDate> <dc:creator>dudo</dc:creator> <category><![CDATA[CSS与JS]]></category> <category><![CDATA[css]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[tips]]></category> <guid
isPermaLink="false">http://dudo.limewebs.com/?p=63</guid> <description><![CDATA[&#60;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#34;&#62;
&#60;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&#62;
&#60;head&#62;
<span
class="readmore"><a
href="http://dudo.org/archives/200609210265.html" title="用JS实现“左中DIV”和“右中DIV”等高">阅读全文——共1351字</a></span><table
class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;"><tr><td ><b><font
size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td></tr><tr><td
style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"> <img
border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"> <a
target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F200606211951.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200609210265.html"> <font
size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">实现DIV布局中多列等高的JS代码</font> </a></td></tr><tr><td
style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"> <img
border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"> <a
target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008060321237.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200609210265.html"> <font
size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">说说CSS+Div布局中的结构与表现</font> </a></td></tr><tr><td
style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"> <img
border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"> <a
target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008060122236.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200609210265.html"> <font
size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">CSS在页面布局中实现div垂直居中的方法总结</font> </a></td></tr><tr><td
style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"> <img
border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"> <a
target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008061911251.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200609210265.html"> <font
size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">CSS Dock Menu：JS+CSS 仿苹果MAC机桌面导航菜单</font> </a></td></tr><tr><td
style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"> <img
border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"> <a
target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F200605282038.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200609210265.html"> <font
size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">XHTML中多Div并排的问题解决</font> </a></td></tr><tr><td
align="right"> <a
style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"> <font
size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font> </a></td></tr></table>]]></description> <content:encoded><![CDATA[<p
class="code"><font
size="3" face="Times New Roman">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;</font><a
href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><font
size="3" face="Times New Roman">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</font></a><font
size="3" face="Times New Roman">&quot;&gt;<br
/> &lt;html xmlns=&quot;</font><a
href="http://www.w3.org/1999/xhtml"><font
size="3" face="Times New Roman">http://www.w3.org/1999/xhtml</font></a><font
size="3" face="Times New Roman">&quot;&gt;<br
/> &lt;head&gt;<br
/> &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gb2312&quot; /&gt;<br
/> &lt;title&gt;练习文档01&lt;/title&gt;<br
/> &lt;style type=&quot;text/css&quot;&gt;<br
/> &lt;!&#8211;<br
/> body{<br
/> &nbsp;&nbsp;&nbsp; margin:0px;padding:0px;<br
/> }<br
/> .Div_top{<br
/> &nbsp;width:100%;<br
/> &nbsp;background:#93beff;<br
/> }<br
/> .Div_bottom{<br
/> &nbsp;width:100%;<br
/> &nbsp;background:#ff00fc;<br
/> }<br
/> .Div_Left{<br
/> &nbsp;position:absolute;<br
/> &nbsp;width:200px;<br
/> &nbsp;background:#ff6000;<br
/> &nbsp;left:0px;<br
/> }<br
/> .Div_Right{<br
/> &nbsp;margin-left: 200px;<br
/> &nbsp;background:#00c17b;<br
/> }<br
/> &#8211;&gt;<br
/> &lt;/style&gt;</font><br
/> &lt;script&gt;<br
/> function SameH(leftDiv,rightDiv)<br
/> {<br
/> var a=document.getElementById(leftDiv);<br
/> var b=document.getElementById(rightDiv);</p><div
class="code">document.write(a.clientHeight+&#8217;px&#8217;);<br
/> document.write(b.clientHeight+&#8217;px&#8217;);<br
/> document.write(a.scrollHeight+&#8217;px&#8217;);<br
/> document.write(b.scrollHeight+&#8217;px&#8217;);</div><div
class="code">if (a.scrollHeight &lt; b.scrollHeight)<br
/> {<br
/> a.style.height= b.scrollHeight;<br
/> }<br
/> else<br
/> {<br
/> b.style.height= a.scrollHeight;<br
/> }<br
/> }</div><div
class="code"> &lt;/script&gt;</div><div
class="code">&lt;/head&gt;<br
/> &lt;body&gt;<br
/> &lt;div class=&quot;Div_top&quot;&gt;这是顶部的div&lt;/div&gt;<br
/> &lt;div id=&quot;Div1&quot; class=&quot;Div_Left&quot;&gt;11111&lt;br&gt;222222&lt;br&gt;33333333&lt;br&gt;444444444&lt;br&gt;555555555&lt;/div&gt;<br
/> &lt;div id=&quot;Div2&quot; class=&quot;Div_Right&quot;&gt;22222&lt;br&gt;dsaf&lt;/div&gt;<br
/> &lt;div class=&quot;Div_bottom&quot;&gt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;这是底部的DIV，在左中右中DIV不等高的情况下会跑上去重叠了&lt;br&gt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-我现在想用一个JavaScript代码来令左右两半的Div等高&lt;br&gt;&lt;br&gt;(注意:中左中右两个DIV的高度是无法事先确定的)&lt;br&gt;为什么这个JavaScript在FireFox无效呢？&lt;/div&gt;<br
/> &lt;script&gt;<br
/> SameH(&quot;Div1&quot;,&quot;Div2&quot;);<br
/> &lt;/script&gt;<br
/> &lt;/body&gt;</div><table
class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;"><tr><td ><b><font
size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td></tr><tr><td
style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"> <img
border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"> <a
target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F200606211951.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200609210265.html"> <font
size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">实现DIV布局中多列等高的JS代码</font> </a></td></tr><tr><td
style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"> <img
border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"> <a
target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008060321237.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200609210265.html"> <font
size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">说说CSS+Div布局中的结构与表现</font> </a></td></tr><tr><td
style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"> <img
border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"> <a
target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008060122236.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200609210265.html"> <font
size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">CSS在页面布局中实现div垂直居中的方法总结</font> </a></td></tr><tr><td
style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"> <img
border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"> <a
target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008061911251.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200609210265.html"> <font
size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">CSS Dock Menu：JS+CSS 仿苹果MAC机桌面导航菜单</font> </a></td></tr><tr><td
style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"> <img
border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"> <a
target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F200605282038.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200609210265.html"> <font
size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">XHTML中多Div并排的问题解决</font> </a></td></tr><tr><td
align="right"> <a
style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"> <font
size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font> </a></td></tr></table>]]></content:encoded> <wfw:commentRss>http://dudo.org/archives/200609210265.html/feed</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>常用的匹配正则表达式和实例</title><link>http://dudo.org/archives/200607202356.html</link> <comments>http://dudo.org/archives/200607202356.html#comments</comments> <pubDate>Thu, 20 Jul 2006 15:30:18 +0000</pubDate> <dc:creator>dudo</dc:creator> <category><![CDATA[CSS与JS]]></category> <category><![CDATA[JavaScript]]></category> <guid
isPermaLink="false">http://dudo.limewebs.com/?p=54</guid> <description><![CDATA[匹配中文字符的正则表达式： [\u4e00-\u9fa5]
匹配双字节字符(包括汉字在内)：[^\x00-\xff]
应用：计算字符串的长度（一个双字节字符长度计2，ASCII字符计1）
<span
class="readmore"><a
href="http://dudo.org/archives/200607202356.html" title="常用的匹配正则表达式和实例">阅读全文——共2018字</a></span><table
class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;"><tr><td
colspan="5"><b><font
size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td></tr><tr><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important;"> <a
target="_blank" title="用SugarSync管理你的Email附件" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2010051323555.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200607202356.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721342.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">用SugarSync管理你的Email附件</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="QQ概念版试用手记（附下载）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2010041923515.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200607202356.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721326.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">QQ概念版试用手记（附下载）</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="说话间，两年就这样匆匆从指间流走，毕业了！" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2007071821161.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200607202356.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721534.jpg" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">说话间，两年就这样匆匆从指间流走，毕业了！</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="博客增加了对IE6的支持" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2010070717577.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200607202356.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721336.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">博客增加了对IE6的支持</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="Web 设计:实现干净代码的12条定律" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008111521261.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200607202356.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721588.gif" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Web 设计:实现干净代码的12条定律</font> </a></td></tr><tr><td
colspan="5" align="right"> <a
style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"> <font
size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font> </a></td></tr></table>]]></description> <content:encoded><![CDATA[<p>匹配中文字符的正则表达式： [\u4e00-\u9fa5]</p><p>匹配双字节字符(包括汉字在内)：[^\x00-\xff]</p><p>应用：计算字符串的长度（一个双字节字符长度计2，ASCII字符计1）</p><p>String.prototype.len=function(){return this.replace([^\x00-\xff]/g,&quot;aa&quot;).length;}</p><p>匹配空行的正则表达式：\n[\s| ]*\r</p><p>匹配HTML标记的正则表达式：/&lt;(.*)&gt;.*&lt;\/\1&gt;|&lt;(.*) \/&gt;/</p><p>匹配首尾空格的正则表达式：(^\s*)|(\s*$)</p><p>应用：javascript中没有像vbscript那样的trim函数，我们就可以利用这个表达式来实现，如下：</p><p>String.prototype.trim = function()<br
/> {<br
/> return this.replace(/(^\s*)|(\s*$)/g, &quot;&quot;);<br
/> }</p><p>利用正则表达式分解和转换IP地址：</p><p>下面是利用正则表达式匹配IP地址，并将IP地址转换成对应数值的Javascript程序：</p><p>function IP2V(ip)<br
/> {<br
/> re=/(\d+)\.(\d+)\.(\d+)\.(\d+)/g //匹配IP地址的正则表达式<br
/> if(re.test(ip))<br
/> {<br
/> return RegExp.$1*Math.pow(255,3))+RegExp.$2*Math.pow(255,2))+RegExp.$3*255+RegExp.$4*1<br
/> }<br
/> else<br
/> {<br
/> throw new Error(&quot;Not a valid IP address!&quot;)<br
/> }<br
/> }</p><p>不过上面的程序如果不用正则表达式，而直接用split函数来分解可能更简单，程序如下：</p><p>var ip=&quot;10.100.20.168&quot;<br
/> ip=ip.split(&quot;.&quot;)<br
/> alert(&quot;IP值是：&quot;+(ip[0]*255*255*255+ip[1]*255*255+ip[2]*255+ip[3]*1))</p><p>匹配Email地址的正则表达式：\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*</p><p>匹配网址URL的正则表达式：http://([\w-]+\.)+[\w-]+(/[\w- ./?%&amp;=]*)?</p><p>利用正则表达式去除字串中重复的字符的算法程序：[注：此程序不正确，原因见本贴回复]</p><p>var s=&quot;abacabefgeeii&quot;<br
/> var s1=s.replace(/(.).*\1/g,&quot;$1&quot;)<br
/> var re=new RegExp(&quot;[&quot;+s1+&quot;]&quot;,&quot;g&quot;)<br
/> var s2=s.replace(re,&quot;&quot;) <br
/> alert(s1+s2) //结果为：abcefgi</p><p>我原来在CSDN上发贴寻求一个表达式来实现去除重复字符的方法，最终没有找到，这是我能想到的最简单的实现方法。思路是使用后向引用取出包括重复的字符，再以重复的字符建立第二个表达式，取到不重复的字符，两者串连。这个方法对于字符顺序有要求的字符串可能不适用。</p><p>得用正则表达式从URL地址中提取文件名的javascript程序，如下结果为page1</p><p>s=&quot;http://www.9499.net/page1.htm&quot;<br
/> s=s.replace(/(.*\/){0,}([^\.]+).*/ig,&quot;$2&quot;)<br
/> alert(s)</p><p>利用正则表达式限制网页表单里的文本框输入内容：</p><p>用正则表达式限制只能输入中文：onkeyup=&quot;value=value.replace(/[^\u4E00-\u9FA5]/g,”)&quot; onbeforepaste=&quot;clipboardData.setData(&#8216;text&#8217;,clipboardData.getData(&#8216;text&#8217;).replace(/[^\u4E00-\u9FA5]/g,”))&quot;</p><p>用正则表达式限制只能输入全角字符： onkeyup=&quot;value=value.replace(/[^\uFF00-\uFFFF]/g,”)&quot; onbeforepaste=&quot;clipboardData.setData(&#8216;text&#8217;,clipboardData.getData(&#8216;text&#8217;).replace(/[^\uFF00-\uFFFF]/g,”))&quot;</p><p>用正则表达式限制只能输入数字：onkeyup=&quot;value=value.replace(/[^\d]/g,”) &quot;onbeforepaste=&quot;clipboardData.setData(&#8216;text&#8217;,clipboardData.getData(&#8216;text&#8217;).replace(/[^\d]/g,”))&quot;</p><p>用正则表达式限制只能输入数字和英文：onkeyup=&quot;value=value.replace(/[\W]/g,”) &quot;onbeforepaste=&quot;clipboardData.setData(&#8216;text&#8217;,clipboardData.getData(&#8216;text&#8217;).replace(/[^\d]/g,”))&quot;</p><p
style="margin:0;padding:0;height:1px;overflow:hidden;"> <script type="text/javascript">var wumiiSitePrefix = "http://dudo.org";
        var wumiiEnableCustomPos = false;
        var wumiiParams = "&#038;num=5&#038;mode=3&#038;displayInFeed=1&#038;version=1.0.5.5&#038;pf=WordPress3.3.2";</script><script type="text/javascript" src="http://widget.wumii.com/ext/relatedItemsWidget.htm"></script><a
href="http://www.wumii.com/widget/relatedItems.htm" style="border:0;"><img
src="http://static.wumii.com/images/pixel.png" alt="无觅相关文章插件，快速提升流量" style="border:0;padding:0;margin:0;" /></a></p><table
class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;"><tr><td
colspan="5"><b><font
size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td></tr><tr><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important;"> <a
target="_blank" title="收到母校寄来的新年贺卡" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008010218186.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200607202356.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721601.jpg" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">收到母校寄来的新年贺卡</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="百度和Google的差别就在这里" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008041716199.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200607202356.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721447.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">百度和Google的差别就在这里</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="Windows XP SP3 RTM 简体中文版发布[附下载地址]" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2008042314202.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200607202356.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721575.jpg" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Windows XP SP3 RTM 简体中文版发布[附下载地址]</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="Google的新搜索界面" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2010041700504.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200607202356.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721352.png" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Google的新搜索界面</font> </a></td><td
width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"> <a
target="_blank" title="很假很毒很无辜——是谁在作恶" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fdudo.org%2Farchives%2F2010040200369.html&from=http%3A%2F%2Fdudo.org%2Farchives%2F200607202356.html"> <img
style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2010/10/02/721359.jpg" width="96px" height="96px" /><br
/> <font
size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">很假很毒很无辜——是谁在作恶</font> </a></td></tr><tr><td
colspan="5" align="right"> <a
style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"> <font
size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font> </a></td></tr></table>]]></content:encoded> <wfw:commentRss>http://dudo.org/archives/200607202356.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
