<?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>三水清三水清</title>
	<atom:link href="http://js8.in/author/admin/feed" rel="self" type="application/rss+xml" />
	<link>http://js8.in</link>
	<description>专注前端开发,分享Javascript/CSS/PHP等Web前端开发技巧</description>
	<lastBuildDate>Sat, 04 Feb 2012 07:28:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>IE6中a标签触发图片和ajax请求被abort</title>
		<link>http://js8.in/944.html</link>
		<comments>http://js8.in/944.html#comments</comments>
		<pubDate>Sat, 04 Feb 2012 07:28:10 +0000</pubDate>
		<dc:creator>三水清</dc:creator>
				<category><![CDATA[web前端开发]]></category>
		<category><![CDATA[abort]]></category>
		<category><![CDATA[a标签]]></category>
		<category><![CDATA[IE6]]></category>

		<guid isPermaLink="false">http://js8.in/?p=944</guid>
		<description><![CDATA[IE6 a标签的请求被abort的原因
最近项目中掉进IE6 a标签abort两次坑，第一次是a标签绑定一个事件，href='javascript:;'这样a标签触发了事件，切换验证码图片，结果验证码图片总是显示不出来，通过抓包显示状态为abort。其实这个的原因可以从IE6中a标签执行顺序说起，IE6中a标签执行onclick在执行默认事件（即href跳转）之前，当触发了绑定的事件之后，那么处理完事件之后，如果不return false或者阻止默认事件，则会继续执行href跳转，IE6会认为页面跳转到其他页面或者页面重新刷新，则abort之前onclick事件中的请求。

所以当onclick时，做出的获取最新验证码图片的请求，会因为下一步href的触发而abort。同时，如果你在a绑定的事件中做ajax请求，那么也会被无情的abort。
IE6 a标签的请求被abort的解决方案
解决的方法就是在onclick或者绑定事件中return false来阻止a标签跳转的默认事件。
例如下面的代码：

&#60;a href=&#34;javascript:void(0)&#34; onclick=&#34;fn();return false;&#34;&#62;Test&#60;/a&#62;

或者你也可以给a标签的href写成“#”，即当前页面的锚点，这样页面就不会跳转，自然不会abort请求。
最好的方式还是两种都用，保险！

声明：文章未声明为原创文章，本文链接 http://js8.in/944.html. 转载请注明转自 JS8.IN ™
随机文章

奋斗了两天！
断桥残雪部落格更换新域名JS8.in
Sql语句优化注意
公司的DBA说了一些SQL数据库的箴言
Opera Chrome Safari浏览器的CSS Hack方法
一款模仿Mac的windows7主题包
使用PHP把excel(xls)文件导入mysql数据库
校内人人网忽悠用户-陈一舟牛啊~


© 三水清 for 三水清, 2012. &#124;
No comment &#124;在微博关注我：@清-三水清
收藏到：
人人网 &#124; 豆瓣 &#124; 开心网 &#124; QQ书签 &#124; 新浪微博 &#124; 腾讯微博

Post tags: abort, a标签, IE6
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="IE6中a标签location.href失效解决方法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F706.html&from=http%3A%2F%2Fjs8.in%2F944.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/07/21/18318778.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;">IE6中a标签location.href失效解决方法</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="png在IE6下透明的几种方法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F448.html&from=http%3A%2F%2Fjs8.in%2F944.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/23/8885105.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;">png在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="最新版wBox 解决IE6 背景太小bug" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F506.html&from=http%3A%2F%2Fjs8.in%2F944.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/11/17/10977733.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;">最新版wBox 解决IE6 背景太小bug</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背景图片不缓存的BUG" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F557.html&from=http%3A%2F%2Fjs8.in%2F944.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://hi.csdn.net/attachment/201104/11/0_1302522572HMK6.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;">解决IE6背景图片不缓存的BUG</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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[<h2>IE6 a标签的请求被abort的原因</h2>
<p>最近项目中掉进IE6 a标签abort两次坑，第一次是a标签绑定一个事件，<code>href='javascript:;'</code>这样a标签触发了事件，切换验证码图片，结果验证码图片总是显示不出来，通过抓包显示状态为<strong>abort</strong>。其实这个的原因可以从IE6中a标签执行顺序说起，IE6中a标签执行onclick在执行默认事件（即href跳转）之前，当触发了绑定的事件之后，那么处理完事件之后，如果不<code>return false</code>或者阻止默认事件，则会继续执行href跳转，IE6会认为页面跳转到其他页面或者页面重新刷新，则abort之前<strong>onclick</strong>事件中的请求。<br />
<span id="more-944"></span><br />
所以当onclick时，做出的获取最新验证码图片的请求，会因为下一步href的触发而abort。同时，如果你在a绑定的事件中做ajax请求，那么也会被无情的<code>abort</code>。</p>
<h2>IE6 a标签的请求被abort的解决方案</h2>
<p>解决的方法就是在onclick或者绑定事件中<code>return false</code>来阻止a标签跳转的默认事件。<br />
例如下面的代码：</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;javascript:void(0)&quot; onclick=&quot;fn();return false;&quot;&gt;Test&lt;/a&gt;</pre></div></div>

<p>或者你也可以给a标签的href写成“#”，即当前页面的锚点，这样页面就不会跳转，自然不会abort请求。</p>
<p>最好的方式还是两种都用，保险！
<div class="copyright">
<strong>声明：</strong>文章未声明为原创文章，本文链接 <a href="http://js8.in/944.html" title="IE6中a标签触发图片和ajax请求被abort">http://js8.in/944.html</a>. 转载请注明转自<a href="http://js8.in" title="前端开发博客"> JS8.IN ™</a></span></span></div>
<h3 class="box-title">随机文章</h3>
<ul class="box_random">
<li><a href="http://js8.in/640.html" title="dedeeims列表页面导航条当前样式实现方法" rel="bookmark inlinks">dedeeims列表页面导航条当前样式实现方法</a></li>
<li><a href="http://js8.in/781.html" title="javascript获取隐藏dom的宽高" rel="bookmark inlinks">javascript获取隐藏dom的宽高</a></li>
<li><a href="http://js8.in/612.html" title="前端开发优化总结" rel="bookmark inlinks">前端开发优化总结</a></li>
<li><a href="http://js8.in/792.html" title="基于express+socket.io的nodejs聊天室" rel="bookmark inlinks">基于express+socket.io的nodejs聊天室</a></li>
<li><a href="http://js8.in/448.html" title="png在IE6下透明的几种方法" rel="bookmark inlinks">png在IE6下透明的几种方法</a></li>
<li><a href="http://js8.in/401.html" title="微软官方发布IE调试工具：SuperPreview for IE" rel="bookmark inlinks">微软官方发布IE调试工具：SuperPreview for IE</a></li>
<li><a href="http://js8.in/426.html" title="7个JavaScript在IE和Firefox浏览器下的差异写法" rel="bookmark inlinks">7个JavaScript在IE和Firefox浏览器下的差异写法</a></li>
<li><a href="http://js8.in/342.html" title="php、js两种不同方式根据关键词返回经纬度接口【基于Google map API】" rel="bookmark inlinks">php、js两种不同方式根据关键词返回经纬度接口【基于Google map API】</a></li>
</ul>
<hr />
<p><small>© 三水清 for <a href="http://js8.in">三水清</a>, 2012. |
<a href="http://js8.in/944.html#comments">No comment</a> |在微博关注我：<a href="//weibo.com/sanshuiqing" target="_blank" title="关注断桥残雪的新浪微博">@清-三水清</a>
<br/>收藏到：
<a rel="nofollow" href="http://share.renren.com/share/buttonshare.do?link=%posturl%&title=%posttitle%" title="收藏本文到人人网" target="_blank">人人网</a> | <a rel="nofollow" href="http://www.douban.com/recommend/?url=%posturl%&title=%posttitle%" title="收藏本文到豆瓣" target="_blank">豆瓣</a> | <a rel="nofollow" href="http://www.kaixin001.com/repaste/share.php?rtitle=%posttitle%&rurl=%posturl%" title="收藏本文到开心网" target="_blank">开心网</a> | <a rel="nofollow" href="http://shuqian.qq.com/post?title=%posttitle%&%20uri=%posturl%" title="收藏本文到QQ书签" target="_blank">QQ书签</a> | <a rel="nofollow" href="http://v.t.sina.com.cn/share/share.php?url=%posturl%&title=%posttitle%" title="收藏本文到新浪微博" target="_blank">新浪微博</a> | <a rel="nofollow" href="http://v.t.qq.com/share/share.php?title=%posttitle%&url=%posturl%&site=http://www.kaixin100.info" title="收藏本文到腾讯微博" target="_blank">腾讯微博</a>
<br/>
Post tags: <a href="http://js8.in/tag/abort" rel="tag">abort</a>, <a href="http://js8.in/tag/a%e6%a0%87%e7%ad%be" rel="tag">a标签</a>, <a href="http://js8.in/tag/ie6" rel="tag">IE6</a><br/>
</small></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="IE6中a标签location.href失效解决方法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F706.html&from=http%3A%2F%2Fjs8.in%2F944.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/07/21/18318778.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;">IE6中a标签location.href失效解决方法</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="png在IE6下透明的几种方法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F448.html&from=http%3A%2F%2Fjs8.in%2F944.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/23/8885105.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;">png在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="最新版wBox 解决IE6 背景太小bug" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F506.html&from=http%3A%2F%2Fjs8.in%2F944.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/11/17/10977733.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;">最新版wBox 解决IE6 背景太小bug</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背景图片不缓存的BUG" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F557.html&from=http%3A%2F%2Fjs8.in%2F944.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://hi.csdn.net/attachment/201104/11/0_1302522572HMK6.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;">解决IE6背景图片不缓存的BUG</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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://js8.in/944.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP实现javascript的escape和unescape函数</title>
		<link>http://js8.in/941.html</link>
		<comments>http://js8.in/941.html#comments</comments>
		<pubDate>Fri, 03 Feb 2012 04:57:03 +0000</pubDate>
		<dc:creator>三水清</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[escape]]></category>
		<category><![CDATA[unescape]]></category>

		<guid isPermaLink="false">http://js8.in/?p=941</guid>
		<description><![CDATA[前端开发工程师都知道javascript有编码函数escape()和对应的解码函数unescape()，而php中只有个urlencode和urldecode，这个编码和解码函数对encodeURI和encodeURIComponent有效，但是对escape的是无效的。
javascript中的escape()函数和unescape()函数用户字符串编码，类似于PHP中的urlencode()函数，下面是php实现的escape函数代码：

/** 
 * js escape php 实现 
 * @param $string           the sting want to be escaped 
 * @param $in_encoding       
 * @param $out_encoding      
 */ 
function escape&#40;$string, $in_encoding = 'UTF-8',$out_encoding = 'UCS-2'&#41; [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="通过PHP批量下载图片文件" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F586.html&from=http%3A%2F%2Fjs8.in%2F941.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/11/17/10977771.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;">通过PHP批量下载图片文件</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="PHP生成RSS类：RSS.class.php" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F412.html&from=http%3A%2F%2Fjs8.in%2F941.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/11/17/10979694.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;">PHP生成RSS类：RSS.class.php</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="21个常用的 PHP 代码汇总" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F457.html&from=http%3A%2F%2Fjs8.in%2F941.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/10/06/8663981.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;">21个常用的 PHP 代码汇总</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="php获取来访者IP信息" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F509.html&from=http%3A%2F%2Fjs8.in%2F941.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/24/2916193.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;">php获取来访者IP信息</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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><strong>前端开发</strong>工程师都知道javascript有编码函数<code>escape()</code>和对应的解码函数<code>unescape()</code>，而php中只有个urlencode和urldecode，这个编码和解码函数对encodeURI和encodeURIComponent有效，但是对<strong>escape</strong>的是无效的。</p>
<p>javascript中的escape()函数和unescape()函数用户字符串编码，类似于PHP中的urlencode()函数，下面是php实现的escape函数代码：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/** 
 * js escape php 实现 
 * @param $string           the sting want to be escaped 
 * @param $in_encoding       
 * @param $out_encoding      
 */</span> 
<span style="color: #000000; font-weight: bold;">function</span> escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$in_encoding</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'UTF-8'</span><span style="color: #339933;">,</span><span style="color: #000088;">$out_encoding</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'UCS-2'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
    <span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> 
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mb_get_info'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
        <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">mb_strlen</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$in_encoding</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
            <span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mb_substr</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$in_encoding</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$str</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// 多字节字符 </span>
                <span style="color: #000088;">$return</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'%u'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">strtoupper</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">bin2hex</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">mb_convert_encoding</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #000088;">$out_encoding</span><span style="color: #339933;">,</span> <span style="color: #000088;">$in_encoding</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> 
                <span style="color: #000088;">$return</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'%'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">strtoupper</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">bin2hex</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$str</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
            <span style="color: #009900;">&#125;</span> 
        <span style="color: #009900;">&#125;</span> 
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$return</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-941"></span><br />
对应的解码<strong>php unescape</strong>代码是：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> unescape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span> 
    <span style="color: #000088;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> 
    <span style="color: #000088;">$len</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$len</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> 
    <span style="color: #009900;">&#123;</span> 
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'%'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$str</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'u'</span><span style="color: #009900;">&#41;</span> 
        <span style="color: #009900;">&#123;</span> 
            <span style="color: #000088;">$val</span> <span style="color: #339933;">=</span> <span style="color: #990000;">hexdec</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span> <span style="color: #339933;">&lt;</span> <span style="color: #208080;">0x7f</span><span style="color: #009900;">&#41;</span> 
                <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
            <span style="color: #b1b100;">else</span>  
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span> <span style="color: #339933;">&lt;</span> <span style="color: #208080;">0x800</span><span style="color: #009900;">&#41;</span> 
                    <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0xc0</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> 
                     <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x80</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span> <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0x3f</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
                <span style="color: #b1b100;">else</span> 
                    <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0xe0</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> 
                     <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x80</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0x3f</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> 
                     <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x80</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span> <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0x3f</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
            <span style="color: #000088;">$i</span> <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> 
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span>  
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'%'</span><span style="color: #009900;">&#41;</span> 
            <span style="color: #009900;">&#123;</span> 
                <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">urldecode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
                <span style="color: #000088;">$i</span> <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span> 
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> 
                <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$str</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<div class="copyright">
<strong>声明：</strong>文章未声明为原创文章，本文链接 <a href="http://js8.in/941.html" title="PHP实现javascript的escape和unescape函数">http://js8.in/941.html</a>. 转载请注明转自<a href="http://js8.in" title="前端开发博客"> JS8.IN ™</a></span></span></div>
<h3 class="box-title">随机文章</h3>
<ul class="box_random">
<li><a href="http://js8.in/330.html" title="光良,第一次—珍喜欢" rel="bookmark inlinks">光良,第一次—珍喜欢</a></li>
<li><a href="http://js8.in/351.html" title="使用CSS控制打印页面格式" rel="bookmark inlinks">使用CSS控制打印页面格式</a></li>
<li><a href="http://js8.in/11.html" title="晚上玩了一个晚上~" rel="bookmark inlinks">晚上玩了一个晚上~</a></li>
<li><a href="http://js8.in/52.html" title="万众期待的Ajax评论发布啦-dedecms扩展工具" rel="bookmark inlinks">万众期待的Ajax评论发布啦-dedecms扩展工具</a></li>
<li><a href="http://js8.in/496.html" title="WordPress博客的 SEO 技巧" rel="bookmark inlinks">WordPress博客的 SEO 技巧</a></li>
<li><a href="http://js8.in/934.html" title="javascript contains方法来判断元素包含关系" rel="bookmark inlinks">javascript contains方法来判断元素包含关系</a></li>
<li><a href="http://js8.in/14.html" title="王老师突然问：考研吗？" rel="bookmark inlinks">王老师突然问：考研吗？</a></li>
<li><a href="http://js8.in/553.html" title="解决IE6 select z-index无效，遮挡div的bug" rel="bookmark inlinks">解决IE6 select z-index无效，遮挡div的bug</a></li>
</ul>
<hr />
<p><small>© 三水清 for <a href="http://js8.in">三水清</a>, 2012. |
<a href="http://js8.in/941.html#comments">No comment</a> |在微博关注我：<a href="//weibo.com/sanshuiqing" target="_blank" title="关注断桥残雪的新浪微博">@清-三水清</a>
<br/>收藏到：
<a rel="nofollow" href="http://share.renren.com/share/buttonshare.do?link=%posturl%&title=%posttitle%" title="收藏本文到人人网" target="_blank">人人网</a> | <a rel="nofollow" href="http://www.douban.com/recommend/?url=%posturl%&title=%posttitle%" title="收藏本文到豆瓣" target="_blank">豆瓣</a> | <a rel="nofollow" href="http://www.kaixin001.com/repaste/share.php?rtitle=%posttitle%&rurl=%posturl%" title="收藏本文到开心网" target="_blank">开心网</a> | <a rel="nofollow" href="http://shuqian.qq.com/post?title=%posttitle%&%20uri=%posturl%" title="收藏本文到QQ书签" target="_blank">QQ书签</a> | <a rel="nofollow" href="http://v.t.sina.com.cn/share/share.php?url=%posturl%&title=%posttitle%" title="收藏本文到新浪微博" target="_blank">新浪微博</a> | <a rel="nofollow" href="http://v.t.qq.com/share/share.php?title=%posttitle%&url=%posturl%&site=http://www.kaixin100.info" title="收藏本文到腾讯微博" target="_blank">腾讯微博</a>
<br/>
Post tags: <a href="http://js8.in/tag/escape" rel="tag">escape</a>, <a href="http://js8.in/tag/php" rel="tag">php</a>, <a href="http://js8.in/tag/unescape" rel="tag">unescape</a><br/>
</small></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="通过PHP批量下载图片文件" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F586.html&from=http%3A%2F%2Fjs8.in%2F941.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/11/17/10977771.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;">通过PHP批量下载图片文件</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="PHP生成RSS类：RSS.class.php" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F412.html&from=http%3A%2F%2Fjs8.in%2F941.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/11/17/10979694.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;">PHP生成RSS类：RSS.class.php</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="21个常用的 PHP 代码汇总" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F457.html&from=http%3A%2F%2Fjs8.in%2F941.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/10/06/8663981.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;">21个常用的 PHP 代码汇总</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="php获取来访者IP信息" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F509.html&from=http%3A%2F%2Fjs8.in%2F941.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/24/2916193.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;">php获取来访者IP信息</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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://js8.in/941.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>javascript contains方法来判断元素包含关系</title>
		<link>http://js8.in/934.html</link>
		<comments>http://js8.in/934.html#comments</comments>
		<pubDate>Thu, 05 Jan 2012 01:49:20 +0000</pubDate>
		<dc:creator>三水清</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[contains]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://js8.in/?p=934</guid>
		<description><![CDATA[IE中的contains方法可以判断A元素是否包含B元素，如果包含则返回true，否则返回false，在开发中会在事件代理处理上面用到。W3C的方法是compareDocumentPosition，所以综上来说：JS通过contains和compareDocumentPosition方法来确定DOM节点间的关系,判断一个元素(对象)是否为另一个元素的子元素。
IE的contains方法很简单，但是W3C的DOMElement.contains(DOMNode)方法会返回却是一个数值。
DOMElement.contains(DOMNode)
link：https://developer.mozilla.org/En/DOM/Node.compareDocumentPosition。
DOMElement.contains(DOMNode)返回的不是一个布尔值，而是一个很奇怪的数值，它是通过如下方式累加计算出来的：





      


Bits
Number
Meaning




000000
0
元素一致


000001
1
节点在不同的文档（或者一个在文档之外）


000010
2
节点 B 在节点 A 之前


000100
4
节点 A 在节点 B 之前 


001000
8
节点 B 包含节点 A


010000
16
节点 A 包含节点 B


100000 
32
浏览器的私有使用 




综上，来个@司徒正美 大大的方案：

var contains  = function&#40;root, el&#41; &#123;
	 if &#40;root.compareDocumentPosition&#41;
		 return root === el &#124;&#124; !!&#40;root.compareDocumentPosition&#40;el&#41; &#38; 16&#41;;
	 if &#40;root.contains &#38;&#38; el.nodeType === 1&#41;&#123;
		 return root.contains&#40;el&#41; &#38;&#38; root !== el;
	 &#125;
	 while [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="通过javascript实现整站黑白效果" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F529.html&from=http%3A%2F%2Fjs8.in%2F934.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/11/18/10979192.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;">通过javascript实现整站黑白效果</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="非字母javascript" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F918.html&from=http%3A%2F%2Fjs8.in%2F934.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/11/30/11698517.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;">非字母javascript</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="Javascript事件触发列表与详解" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F480.html&from=http%3A%2F%2Fjs8.in%2F934.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/11/17/10982510.bmp" 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;">Javascript事件触发列表与详解</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="javascript 位运算符" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F906.html&from=http%3A%2F%2Fjs8.in%2F934.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/11/29/11661329.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;">javascript 位运算符</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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>IE中的<strong>contains</strong>方法可以判断A元素是否包含B元素，如果包含则返回true，否则返回false，在开发中会在事件代理处理上面用到。W3C的方法是<strong>compareDocumentPosition</strong>，所以综上来说：JS通过contains和compareDocumentPosition方法来确定DOM节点间的关系,判断一个元素(对象)是否为另一个元素的子元素。<br />
IE的contains方法很简单，但是W3C的<code>DOMElement.contains(DOMNode)</code>方法会返回却是一个数值。</p>
<h2>DOMElement.contains(DOMNode)</h2>
<p>link：<a target="_blank" target="_blank" href="https://developer.mozilla.org/En/DOM/Node.compareDocumentPosition">https://developer.mozilla.org/En/DOM/Node.compareDocumentPosition</a>。</p>
<p><code>DOMElement.contains(DOMNode)</code>返回的不是一个布尔值，而是一个很奇怪的数值，它是通过如下方式累加计算出来的：</p>
<table class="filament_table" cellspacing="0" width="80%" rules="cols" border="1">
<colgroup>
<col class="grey" width="20%">
<col class="yellow" width="20%">
<col class="grey">
      </colgroup>
<thead>
<tr>
<th>Bits</th>
<th>Number</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>000000</td>
<td>0</td>
<td>元素一致</td>
</tr>
<tr>
<td>000001</td>
<td>1</td>
<td>节点在不同的文档（或者一个在文档之外）</td>
</tr>
<tr>
<td>000010</td>
<td>2</td>
<td>节点 B 在节点 A 之前</td>
</tr>
<tr>
<td>000100</td>
<td>4</td>
<td>节点 A 在节点 B 之前 </td>
</tr>
<tr>
<td>001000</td>
<td>8</td>
<td>节点 B 包含节点 A</td>
</tr>
<tr>
<td>010000</td>
<td>16</td>
<td>节点 A 包含节点 B</td>
</tr>
<tr>
<td>100000 </td>
<td>32</td>
<td>浏览器的私有使用 </td>
</tr>
</tbody>
</table>
<p><span id="more-934"></span><br />
综上，来个@司徒正美 大大的方案：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> contains  <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>root<span style="color: #339933;">,</span> el<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>root.<span style="color: #660066;">compareDocumentPosition</span><span style="color: #009900;">&#41;</span>
		 <span style="color: #000066; font-weight: bold;">return</span> root <span style="color: #339933;">===</span> el <span style="color: #339933;">||</span> <span style="color: #339933;">!!</span><span style="color: #009900;">&#40;</span>root.<span style="color: #660066;">compareDocumentPosition</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #CC0000;">16</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>root.<span style="color: #660066;">contains</span> <span style="color: #339933;">&amp;&amp;</span> el.<span style="color: #660066;">nodeType</span> <span style="color: #339933;">===</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		 <span style="color: #000066; font-weight: bold;">return</span> root.<span style="color: #660066;">contains</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> root <span style="color: #339933;">!==</span> el<span style="color: #339933;">;</span>
	 <span style="color: #009900;">&#125;</span>
	 <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>el <span style="color: #339933;">=</span> el.<span style="color: #660066;">parentNode</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>el <span style="color: #339933;">===</span> root<span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	 <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span></pre></div></div>

<div class="copyright">
<strong>声明：</strong>文章未声明为原创文章，本文链接 <a href="http://js8.in/934.html" title="javascript contains方法来判断元素包含关系">http://js8.in/934.html</a>. 转载请注明转自<a href="http://js8.in" title="前端开发博客"> JS8.IN ™</a></span></span></div>
<h3 class="box-title">随机文章</h3>
<ul class="box_random">
<li><a href="http://js8.in/283.html" title="jQuery+google weather API轻松实现天气地图（二）" rel="bookmark inlinks">jQuery+google weather API轻松实现天气地图（二）</a></li>
<li><a href="http://js8.in/330.html" title="光良,第一次—珍喜欢" rel="bookmark inlinks">光良,第一次—珍喜欢</a></li>
<li><a href="http://js8.in/620.html" title="关于wBox iFrame回调关闭问题的解决方案" rel="bookmark inlinks">关于wBox iFrame回调关闭问题的解决方案</a></li>
<li><a href="http://js8.in/518.html" title="使用Apache htpasswd.exe来管理SVN帐户" rel="bookmark inlinks">使用Apache htpasswd.exe来管理SVN帐户</a></li>
<li><a href="http://js8.in/37.html" title="“学长，你考研挺忙吧？！”" rel="bookmark inlinks">“学长，你考研挺忙吧？！”</a></li>
<li><a href="http://js8.in/586.html" title="通过PHP批量下载图片文件" rel="bookmark inlinks">通过PHP批量下载图片文件</a></li>
<li><a href="http://js8.in/634.html" title="Sina App Engine开发实例：天气预报的定时短信（二）" rel="bookmark inlinks">Sina App Engine开发实例：天气预报的定时短信（二）</a></li>
<li><a href="http://js8.in/802.html" title="HTMl5的sessionStorage和localStorage" rel="bookmark inlinks">HTMl5的sessionStorage和localStorage</a></li>
</ul>
<hr />
<p><small>© 三水清 for <a href="http://js8.in">三水清</a>, 2012. |
<a href="http://js8.in/934.html#comments">One comment</a> |在微博关注我：<a href="//weibo.com/sanshuiqing" target="_blank" title="关注断桥残雪的新浪微博">@清-三水清</a>
<br/>收藏到：
<a rel="nofollow" href="http://share.renren.com/share/buttonshare.do?link=%posturl%&title=%posttitle%" title="收藏本文到人人网" target="_blank">人人网</a> | <a rel="nofollow" href="http://www.douban.com/recommend/?url=%posturl%&title=%posttitle%" title="收藏本文到豆瓣" target="_blank">豆瓣</a> | <a rel="nofollow" href="http://www.kaixin001.com/repaste/share.php?rtitle=%posttitle%&rurl=%posturl%" title="收藏本文到开心网" target="_blank">开心网</a> | <a rel="nofollow" href="http://shuqian.qq.com/post?title=%posttitle%&%20uri=%posturl%" title="收藏本文到QQ书签" target="_blank">QQ书签</a> | <a rel="nofollow" href="http://v.t.sina.com.cn/share/share.php?url=%posturl%&title=%posttitle%" title="收藏本文到新浪微博" target="_blank">新浪微博</a> | <a rel="nofollow" href="http://v.t.qq.com/share/share.php?title=%posttitle%&url=%posturl%&site=http://www.kaixin100.info" title="收藏本文到腾讯微博" target="_blank">腾讯微博</a>
<br/>
Post tags: <a href="http://js8.in/tag/contains" rel="tag">contains</a>, <a href="http://js8.in/tag/javascript" rel="tag">javascript</a><br/>
</small></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="通过javascript实现整站黑白效果" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F529.html&from=http%3A%2F%2Fjs8.in%2F934.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/11/18/10979192.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;">通过javascript实现整站黑白效果</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="非字母javascript" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F918.html&from=http%3A%2F%2Fjs8.in%2F934.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/11/30/11698517.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;">非字母javascript</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="Javascript事件触发列表与详解" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F480.html&from=http%3A%2F%2Fjs8.in%2F934.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/11/17/10982510.bmp" 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;">Javascript事件触发列表与详解</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="javascript 位运算符" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F906.html&from=http%3A%2F%2Fjs8.in%2F934.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/11/29/11661329.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;">javascript 位运算符</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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://js8.in/934.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>使用webbench做压力测试</title>
		<link>http://js8.in/930.html</link>
		<comments>http://js8.in/930.html#comments</comments>
		<pubDate>Wed, 04 Jan 2012 07:37:38 +0000</pubDate>
		<dc:creator>三水清</dc:creator>
				<category><![CDATA[网络技术]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[webbench]]></category>
		<category><![CDATA[压力测试]]></category>

		<guid isPermaLink="false">http://js8.in/?p=930</guid>
		<description><![CDATA[元旦假期帮朋友折腾VPS，安装了centOS和lnmp，网站部好了，而且定时任务也加上了，觉得应该做个压力测试，之前用过apache自带的ab，不过今天使用的是webbench做压力测试。备份下安装测试过程。
首先我们先来安装webbench吧, 为了测试准确，请将 webbench 安装在别的linux服务器上, 因为webbench 做压力测试时，自身也会消耗CPU和内存资源, 否则, 很可能把自己服务器搞挂掉。于是我切换到了ubuntu系统做webbench测试。
安装webbench
安装过程比较简单，如果你的机子之前安装过一些常用软件直接使用下面的命令就可以了：
wget http://home.tiscali.cz/~cz210552/distfiles/webbench-1.5.tar.gz
tar zxvf webbench-1.5.tar.gz
cd webbench-1.5
make &#038;&#038; make install
webbench安装报错
没有安装ctags
如果没有安装 ctags make 编译会报错：/bin/sh: ctags: command not found
这时当然是要安装ctags啦，于是：
apt-get install ctags
搞定
没有安装gcc
这时候可能会报错：
cc: Command not found
这时需要gcc：
apt-get install gcc
其他报错
如果出现下面的错误：
cannot create regular file `/usr/local/man/man1&#8242;: No such file or directory

这时需要创建/usr/local/man/man1文件来解决：
mkdir -m 644 -p /usr/local/man/man1
使用webbench做压力测试
经过上面的折腾，webbench终于安装好了，下面要做的就是做个压力测试了，在shell里面输入下面的命令：
webbench -c 500 -t 30 http://127.0.0.1/test.jpg
参数说明：-c表示并发数，-t表示时间(秒)
最后就会出现详细的测试信息了：
Webbench &#8211; Simple Web Benchmark 1.5
Copyright (c) Radim Kolar [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="linux安装PHP加速器eAccelerator" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F888.html&from=http%3A%2F%2Fjs8.in%2F930.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/15/12184400.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;">linux安装PHP加速器eAccelerator</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="使用windows7的virtual PC打造原装IE6、IE7、IE8测试环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F688.html&from=http%3A%2F%2Fjs8.in%2F930.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/11/17/10978881.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;">使用windows7的virtual PC打造原装IE6、IE7、IE8测试环境</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="jQuery1.4正式版新功能及性能测试" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F450.html&from=http%3A%2F%2Fjs8.in%2F930.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/11/18/11026546.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;">jQuery1.4正式版新功能及性能测试</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="Ubuntu安装Samba实现跟windows文件共享" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F526.html&from=http%3A%2F%2Fjs8.in%2F930.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/11/17/10979469.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;">Ubuntu安装Samba实现跟windows文件共享</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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>元旦假期帮朋友折腾VPS，安装了centOS和lnmp，网站部好了，而且定时任务也加上了，觉得应该做个压力测试，之前用过apache自带的ab，不过今天使用的是<strong>webbench</strong>做压力测试。备份下安装测试过程。<br />
首先我们先来安装webbench吧, 为了测试准确，请将 webbench 安装在别的linux服务器上, 因为webbench 做压力测试时，自身也会消耗CPU和内存资源, 否则, 很可能把自己服务器搞挂掉。于是我切换到了ubuntu系统做<strong>webbench测试</strong>。</p>
<h2>安装webbench</h2>
<p>安装过程比较简单，如果你的机子之前安装过一些常用软件直接使用下面的命令就可以了：</p>
<blockquote><p>wget http://home.tiscali.cz/~cz210552/distfiles/webbench-1.5.tar.gz<br />
tar zxvf webbench-1.5.tar.gz<br />
cd webbench-1.5<br />
make &#038;&#038; make install</p></blockquote>
<h2>webbench安装报错</h2>
<h3>没有安装ctags</h3>
<p>如果没有安装 ctags make 编译会报错：<code>/bin/sh: ctags: command not found</code><br />
这时当然是要安装ctags啦，于是：</p>
<blockquote><p>apt-get install ctags</p></blockquote>
<p>搞定</p>
<h3>没有安装gcc</h3>
<p>这时候可能会报错：</p>
<blockquote><p>cc: Command not found</p></blockquote>
<p>这时需要gcc：</p>
<blockquote><p>apt-get install gcc</p></blockquote>
<h3>其他报错</h3>
<p>如果出现下面的错误：</p>
<blockquote><p>cannot create regular file `/usr/local/man/man1&#8242;: No such file or directory</p></blockquote>
<p><span id="more-930"></span><br />
这时需要创建<code>/usr/local/man/man1</code>文件来解决：</p>
<blockquote><p>mkdir -m 644 -p /usr/local/man/man1</p></blockquote>
<h2>使用webbench做压力测试</h2>
<p>经过上面的折腾，webbench终于安装好了，下面要做的就是做个<strong>压力测试</strong>了，在shell里面输入下面的命令：</p>
<blockquote><p>webbench -c 500 -t 30 http://127.0.0.1/test.jpg</p></blockquote>
<p>参数说明：-c表示并发数，-t表示时间(秒)</p>
<p>最后就会出现详细的测试信息了：</p>
<blockquote><p>Webbench &#8211; Simple Web Benchmark 1.5<br />
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.</p>
<p>Benchmarking: GET http://127.0.0.1/test.jpg<br />
500 clients, running 30 sec.</p>
<p>Speed=3230 pages/min, 11614212 bytes/sec.<br />
Requests: 1615 susceed, 0 failed.</p></blockquote>
<div class="copyright">
<strong>声明：</strong>文章未声明为原创文章，本文链接 <a href="http://js8.in/930.html" title="使用webbench做压力测试">http://js8.in/930.html</a>. 转载请注明转自<a href="http://js8.in" title="前端开发博客"> JS8.IN ™</a></span></span></div>
<h3 class="box-title">随机文章</h3>
<ul class="box_random">
<li><a href="http://js8.in/409.html" title="巧用谷歌Reader订阅最新春运信息" rel="bookmark inlinks">巧用谷歌Reader订阅最新春运信息</a></li>
<li><a href="http://js8.in/605.html" title="javascript简单实现checkbox的全选与反选" rel="bookmark inlinks">javascript简单实现checkbox的全选与反选</a></li>
<li><a href="http://js8.in/818.html" title="chrome扩展应用开发教程之开发chrome应用基础" rel="bookmark inlinks">chrome扩展应用开发教程之开发chrome应用基础</a></li>
<li><a href="http://js8.in/526.html" title="Ubuntu安装Samba实现跟windows文件共享" rel="bookmark inlinks">Ubuntu安装Samba实现跟windows文件共享</a></li>
<li><a href="http://js8.in/467.html" title="Javascript设置光标位置到结尾并显示出来" rel="bookmark inlinks">Javascript设置光标位置到结尾并显示出来</a></li>
<li><a href="http://js8.in/466.html" title="javascript获取光标位置以及设置光标位置" rel="bookmark inlinks">javascript获取光标位置以及设置光标位置</a></li>
<li><a href="http://js8.in/468.html" title="2fool.cn域名健在，爱墙升级" rel="bookmark inlinks">2fool.cn域名健在，爱墙升级</a></li>
<li><a href="http://js8.in/395.html" title="Google2009年Logo大盘点——第二季" rel="bookmark inlinks">Google2009年Logo大盘点——第二季</a></li>
</ul>
<hr />
<p><small>© 三水清 for <a href="http://js8.in">三水清</a>, 2012. |
<a href="http://js8.in/930.html#comments">No comment</a> |在微博关注我：<a href="//weibo.com/sanshuiqing" target="_blank" title="关注断桥残雪的新浪微博">@清-三水清</a>
<br/>收藏到：
<a rel="nofollow" href="http://share.renren.com/share/buttonshare.do?link=%posturl%&title=%posttitle%" title="收藏本文到人人网" target="_blank">人人网</a> | <a rel="nofollow" href="http://www.douban.com/recommend/?url=%posturl%&title=%posttitle%" title="收藏本文到豆瓣" target="_blank">豆瓣</a> | <a rel="nofollow" href="http://www.kaixin001.com/repaste/share.php?rtitle=%posttitle%&rurl=%posturl%" title="收藏本文到开心网" target="_blank">开心网</a> | <a rel="nofollow" href="http://shuqian.qq.com/post?title=%posttitle%&%20uri=%posturl%" title="收藏本文到QQ书签" target="_blank">QQ书签</a> | <a rel="nofollow" href="http://v.t.sina.com.cn/share/share.php?url=%posturl%&title=%posttitle%" title="收藏本文到新浪微博" target="_blank">新浪微博</a> | <a rel="nofollow" href="http://v.t.qq.com/share/share.php?title=%posttitle%&url=%posturl%&site=http://www.kaixin100.info" title="收藏本文到腾讯微博" target="_blank">腾讯微博</a>
<br/>
Post tags: <a href="http://js8.in/tag/linux" rel="tag">linux</a>, <a href="http://js8.in/tag/webbench" rel="tag">webbench</a>, <a href="http://js8.in/tag/%e5%8e%8b%e5%8a%9b%e6%b5%8b%e8%af%95" rel="tag">压力测试</a><br/>
</small></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="linux安装PHP加速器eAccelerator" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F888.html&from=http%3A%2F%2Fjs8.in%2F930.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/15/12184400.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;">linux安装PHP加速器eAccelerator</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="使用windows7的virtual PC打造原装IE6、IE7、IE8测试环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F688.html&from=http%3A%2F%2Fjs8.in%2F930.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/11/17/10978881.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;">使用windows7的virtual PC打造原装IE6、IE7、IE8测试环境</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="jQuery1.4正式版新功能及性能测试" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F450.html&from=http%3A%2F%2Fjs8.in%2F930.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/11/18/11026546.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;">jQuery1.4正式版新功能及性能测试</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="Ubuntu安装Samba实现跟windows文件共享" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F526.html&from=http%3A%2F%2Fjs8.in%2F930.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/11/17/10979469.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;">Ubuntu安装Samba实现跟windows文件共享</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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://js8.in/930.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>非字母javascript</title>
		<link>http://js8.in/918.html</link>
		<comments>http://js8.in/918.html#comments</comments>
		<pubDate>Wed, 30 Nov 2011 02:17:03 +0000</pubDate>
		<dc:creator>三水清</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://js8.in/?p=918</guid>
		<description><![CDATA[你尝试过写javascript不用字母和数字吗？最近准备个xss的分享，记起了之前看到过老外一篇文章，内容是关于non-alpha javascript的，拿到代码分析下。
先看这段猥琐的javascript代码：

_=+&#91;&#93;;$=_++;__=&#40;_&#60;&#60;_&#41;;___=&#40;_&#60;&#60;_&#41;+_;____=__+__;_____=__+___;$$=&#40;&#123;&#125;+&#34;&#34;&#41;&#91;_____&#93;+&#40;&#123;&#125;+&#34;&#34;&#41;&#91;_&#93;+&#40;&#123;&#125;&#91;$&#93;+&#34;&#34;&#41;&#91;_&#93;+&#40;&#40;$!=$&#41;+&#34;&#34;&#41;&#91;___&#93;+&#40;&#40;$==$&#41;+&#34;&#34;&#41;&#91;$&#93;+&#40;&#40;$==$&#41;+&#34;&#34;&#41;&#91;_&#93;+&#40;&#40;$==$&#41;+&#34;&#34;&#41;&#91;__&#93;+&#40;&#123;&#125;+&#34;&#34;&#41;&#91;_____&#93;+&#40;&#40;$==$&#41;+&#34;&#34;&#41;&#91;$&#93;+&#40;&#123;&#125;+&#34;&#34;&#41;&#91;_&#93;+&#40;&#40;$==$&#41;+&#34;&#34;&#41;&#91;_&#93;;$$$=&#40;&#40;$!=$&#41;+&#34;&#34;&#41;&#91;_&#93;+&#40;&#40;$!=$&#41;+&#34;&#34;&#41;&#91;__&#93;+&#40;&#40;$==$&#41;+&#34;&#34;&#41;&#91;___&#93;+&#40;&#40;$==$&#41;+&#34;&#34;&#41;&#91;_&#93;+&#40;&#40;$==$&#41;+&#34;&#34;&#41;&#91;$&#93;;$_$=&#40;&#123;&#125;+&#34;&#34;&#41;&#91;_____&#93;+&#40;&#123;&#125;+&#34;&#34;&#41;&#91;_&#93;+&#40;&#123;&#125;+&#34;&#34;&#41;&#91;_&#93;+&#40;&#40;$!=$&#41;+&#34;&#34;&#41;&#91;__&#93;+&#40;&#123;&#125;+&#34;&#34;&#41;&#91;__+_____&#93;+&#40;&#123;&#125;+&#34;&#34;&#41;&#91;_____&#93;+ &#40;&#123;&#125;+&#34;&#34;&#41;&#91;_&#93;+&#40;&#123;&#125;&#91;$&#93;+&#34;&#34;&#41;&#91;__&#93;+&#40;&#40;$==$&#41;+&#34;&#34;&#41;&#91;___&#93;; &#40;$&#41;&#91;$$&#93;&#91;$$&#93;&#40;$$$+&#34;('&#34;+$_$+&#34;')&#34;&#41;&#40;&#41;;

看到这里你肯定抓狂了，但是这段代码是可以运行的，运行的结果是 alert('cool code'); 。
javascript分析
这段代码能够运行，原因是javascript是弱类型的脚本语言，而且语法相对松散。例如下面的javascript是正确的，而且是有出乎意料结果的：


true+true;//2
undefined+''//'undefined'
&#40;true+&#34;&#34;&#41;&#91;0&#93;;//'t'
&#91;&#93;=='';//true
''==0;//true
typeof &#40;+''&#41;;//number,0
&#40;&#123;&#125;+''&#41;;//&#34;[object Object]&#34;
&#40;&#123;&#125;&#91;0&#93;&#41;;//undefined

所以我们想得到一个0就可以使用:

_= +&#91;&#93;;
_= +'';

下一步通过位运算，++等运算可以得到0~9所有数字。
因为0就是false，则!0就是true，({}[0]);可以得到undefined，({}+'')可以得到字符串：[object Object]，字符串中的字符，可以组成新的字符串，于是通过组合，我们就得到了："constructor"。
javascript中的点(.)运算符和[]的作用都是一样的，只不过[]可以接收传入变量、字符串，所以我们可以得到一个Function对象，即：

&#40;0&#41;&#91;'constructor'&#93;&#91;'constructor'&#93;;

另外我们也知道，下面的代码是运行的：

Function&#40;'alert(1);'&#41;&#40;&#41;;

所以，我想剩下的你就懂了……

声明：文章未声明为原创文章，本文链接 http://js8.in/918.html. 转载请注明转自 JS8.IN ™
随机文章

json_encode数组出现unicode \uxxxx的解决方案
手把手教你偷老师课件甚至考试试题！
21个常用的 PHP 代码汇总
主流浏览器的CSS Hack方法整理
谷歌500元免费AdWords广告费申请第二步
Jquery中的offset()和position()方法详解
使用webbench做压力测试
我被遨游撞了一下腰


© 三水清 for 三水清, 2011. &#124;
5 comments &#124;在微博关注我：@清-三水清
收藏到：
人人网 &#124; 豆瓣 &#124; 开心网 &#124; QQ书签 &#124; 新浪微博 &#124; 腾讯微博

Post tags: javascript
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="Javascript事件触发列表与详解" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F480.html&from=http%3A%2F%2Fjs8.in%2F918.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/11/17/10982510.bmp" 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;">Javascript事件触发列表与详解</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="Javascript设置光标位置到结尾并显示出来" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F467.html&from=http%3A%2F%2Fjs8.in%2F918.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/11/18/11027176.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;">Javascript设置光标位置到结尾并显示出来</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="javascript获取光标位置以及设置光标位置" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F466.html&from=http%3A%2F%2Fjs8.in%2F918.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/11/17/10979320.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;">javascript获取光标位置以及设置光标位置</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="JavaScript跨浏览器的添加删除事件绑定函数" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F408.html&from=http%3A%2F%2Fjs8.in%2F918.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/11/17/10978769.bmp" 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;">JavaScript跨浏览器的添加删除事件绑定函数</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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>你尝试过写javascript不用字母和数字吗？最近准备个xss的分享，记起了之前看到过老外一篇文章，内容是关于non-alpha javascript的，拿到代码分析下。<br />
先看这段猥琐的javascript代码：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">_<span style="color: #339933;">=+</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>$<span style="color: #339933;">=</span>_<span style="color: #339933;">++;</span>__<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>_<span style="color: #339933;">&lt;&lt;</span>_<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>___<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>_<span style="color: #339933;">&lt;&lt;</span>_<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>_<span style="color: #339933;">;</span>____<span style="color: #339933;">=</span>__<span style="color: #339933;">+</span>__<span style="color: #339933;">;</span>_____<span style="color: #339933;">=</span>__<span style="color: #339933;">+</span>___<span style="color: #339933;">;</span>$$<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>_____<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>_<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span>$<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>_<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$<span style="color: #339933;">!=</span>$<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>___<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$<span style="color: #339933;">==</span>$<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>$<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$<span style="color: #339933;">==</span>$<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>_<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$<span style="color: #339933;">==</span>$<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>__<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>_____<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$<span style="color: #339933;">==</span>$<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>$<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>_<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$<span style="color: #339933;">==</span>$<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>_<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>$$$<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$<span style="color: #339933;">!=</span>$<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>_<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$<span style="color: #339933;">!=</span>$<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>__<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$<span style="color: #339933;">==</span>$<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>___<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$<span style="color: #339933;">==</span>$<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>_<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$<span style="color: #339933;">==</span>$<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>$<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>$_$<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>_____<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>_<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>_<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$<span style="color: #339933;">!=</span>$<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>__<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>__<span style="color: #339933;">+</span>_____<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>_____<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>_<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span>$<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>__<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$<span style="color: #339933;">==</span>$<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>___<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>$$<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>$$<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</span>$$$<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;('&quot;</span><span style="color: #339933;">+</span>$_$<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;')&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>看到这里你肯定抓狂了，但是这段代码是可以运行的，运行的结果是 <code>alert('cool code');</code> 。</p>
<h2>javascript分析</h2>
<p>这段代码能够运行，原因是javascript是弱类型的脚本语言，而且语法相对松散。例如下面的javascript是正确的，而且是有出乎意料结果的：<br />
<span id="more-918"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">+</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span><span style="color: #006600; font-style: italic;">//2</span>
undefined<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #006600; font-style: italic;">//'undefined'</span>
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><span style="color: #006600; font-style: italic;">//'t'</span>
<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span><span style="color: #006600; font-style: italic;">//true</span>
<span style="color: #3366CC;">''</span><span style="color: #339933;">==</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><span style="color: #006600; font-style: italic;">//true</span>
<span style="color: #000066; font-weight: bold;">typeof</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #006600; font-style: italic;">//number,0</span>
<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #006600; font-style: italic;">//&quot;[object Object]&quot;</span>
<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #006600; font-style: italic;">//undefined</span></pre></div></div>

<p>所以我们想得到一个0就可以使用:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">_<span style="color: #339933;">=</span> <span style="color: #339933;">+</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
_<span style="color: #339933;">=</span> <span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span></pre></div></div>

<p>下一步通过<a href="http://js8.in/906.html" title="javascript 位运算符" target="_blank">位运算</a>，++等运算可以得到0~9所有数字。</p>
<p>因为0就是false，则!0就是true，<code>({}[0]);</code>可以得到undefined，<code>({}+'')</code>可以得到字符串：[object Object]，字符串中的字符，可以组成新的字符串，于是通过组合，我们就得到了：<code>"constructor"</code>。</p>
<p>javascript中的点(.)运算符和[]的作用都是一样的，只不过[]可以接收传入变量、字符串，所以我们可以得到一个Function对象，即：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'constructor'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'constructor'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>另外我们也知道，下面的代码是运行的：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">Function</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'alert(1);'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>所以，我想剩下的你就懂了……
<div class="copyright">
<strong>声明：</strong>文章未声明为原创文章，本文链接 <a href="http://js8.in/918.html" title="非字母javascript">http://js8.in/918.html</a>. 转载请注明转自<a href="http://js8.in" title="前端开发博客"> JS8.IN ™</a></span></span></div>
<h3 class="box-title">随机文章</h3>
<ul class="box_random">
<li><a href="http://js8.in/480.html" title="Javascript事件触发列表与详解" rel="bookmark inlinks">Javascript事件触发列表与详解</a></li>
<li><a href="http://js8.in/443.html" title="用document.domain+iframe实现Ajax跨子域" rel="bookmark inlinks">用document.domain+iframe实现Ajax跨子域</a></li>
<li><a href="http://js8.in/502.html" title="jQuery插件--wBox发布" rel="bookmark inlinks">jQuery插件&#8211;wBox发布</a></li>
<li><a href="http://js8.in/43.html" title="对Zblog的页面分页链接的修改" rel="bookmark inlinks">对Zblog的页面分页链接的修改</a></li>
<li><a href="http://js8.in/638.html" title="再谈Iframe的问题" rel="bookmark inlinks">再谈Iframe的问题</a></li>
<li><a href="http://js8.in/697.html" title="json_encode数组出现unicode \uxxxx的解决方案" rel="bookmark inlinks">json_encode数组出现unicode \uxxxx的解决方案</a></li>
<li><a href="http://js8.in/639.html" title="企业黄页网站GongSiHuangYe.COM上线" rel="bookmark inlinks">企业黄页网站GongSiHuangYe.COM上线</a></li>
<li><a href="http://js8.in/736.html" title="javascript变量类型" rel="bookmark inlinks">javascript变量类型</a></li>
</ul>
<hr />
<p><small>© 三水清 for <a href="http://js8.in">三水清</a>, 2011. |
<a href="http://js8.in/918.html#comments">5 comments</a> |在微博关注我：<a href="//weibo.com/sanshuiqing" target="_blank" title="关注断桥残雪的新浪微博">@清-三水清</a>
<br/>收藏到：
<a rel="nofollow" href="http://share.renren.com/share/buttonshare.do?link=%posturl%&title=%posttitle%" title="收藏本文到人人网" target="_blank">人人网</a> | <a rel="nofollow" href="http://www.douban.com/recommend/?url=%posturl%&title=%posttitle%" title="收藏本文到豆瓣" target="_blank">豆瓣</a> | <a rel="nofollow" href="http://www.kaixin001.com/repaste/share.php?rtitle=%posttitle%&rurl=%posturl%" title="收藏本文到开心网" target="_blank">开心网</a> | <a rel="nofollow" href="http://shuqian.qq.com/post?title=%posttitle%&%20uri=%posturl%" title="收藏本文到QQ书签" target="_blank">QQ书签</a> | <a rel="nofollow" href="http://v.t.sina.com.cn/share/share.php?url=%posturl%&title=%posttitle%" title="收藏本文到新浪微博" target="_blank">新浪微博</a> | <a rel="nofollow" href="http://v.t.qq.com/share/share.php?title=%posttitle%&url=%posturl%&site=http://www.kaixin100.info" title="收藏本文到腾讯微博" target="_blank">腾讯微博</a>
<br/>
Post tags: <a href="http://js8.in/tag/javascript" rel="tag">javascript</a><br/>
</small></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="Javascript事件触发列表与详解" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F480.html&from=http%3A%2F%2Fjs8.in%2F918.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/11/17/10982510.bmp" 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;">Javascript事件触发列表与详解</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="Javascript设置光标位置到结尾并显示出来" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F467.html&from=http%3A%2F%2Fjs8.in%2F918.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/11/18/11027176.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;">Javascript设置光标位置到结尾并显示出来</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="javascript获取光标位置以及设置光标位置" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F466.html&from=http%3A%2F%2Fjs8.in%2F918.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/11/17/10979320.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;">javascript获取光标位置以及设置光标位置</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="JavaScript跨浏览器的添加删除事件绑定函数" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F408.html&from=http%3A%2F%2Fjs8.in%2F918.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/11/17/10978769.bmp" 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;">JavaScript跨浏览器的添加删除事件绑定函数</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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://js8.in/918.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>javascript 位运算符</title>
		<link>http://js8.in/906.html</link>
		<comments>http://js8.in/906.html#comments</comments>
		<pubDate>Tue, 29 Nov 2011 02:46:09 +0000</pubDate>
		<dc:creator>三水清</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[位运算]]></category>

		<guid isPermaLink="false">http://js8.in/?p=906</guid>
		<description><![CDATA[前几天看到国外人在github总结的javascript的奇巧淫技（http://t.cn/herRcq），里面对位运算提到的很多，所以来科普一下javascript的位运算。于是找到了w3cschool的这篇教程，很好很强大啊，于是就忍不住转载了……
ECMAScript 整数有两种类型，即有符号整数（允许用正数和负数）和无符号整数（只允许用正数）。在 ECMAScript 中，所有整数字面量默认都是有符号整数，这意味着什么呢？
有符号整数使用 31 位表示整数的数值，用第 32 位表示整数的符号，0 表示正数，1 表示负数。数值范围从 -2147483648 到 2147483647。
可以以两种不同的方式存储二进制形式的有符号整数，一种用于存储正数，一种用于存储负数。正数是以真二进制形式存储的，前 31 位中的每一位都表示 2 的幂，从第 1 位（位 0）开始，表示 20，第 2 位（位 1）表示 21。没用到的位用 0 填充，即忽略不计。例如，下图展示的是数 18 的表示法。

18 的二进制版本只用了前 5 位，它们是这个数字的有效位。把数字转换成二进制字符串，就能看到有效位：

var iNum = 18;
alert&#40;iNum.toString&#40;2&#41;&#41;;	//输出 &#34;10010&#34;

这段代码只输出 &#8220;10010&#8243;，而不是 18 的 32 位表示。其他的数位并不重要，因为仅使用前 5 位即可确定这个十进制数值。如下图所示：

负数也存储为二进制代码，不过采用的形式是二进制补码。计算数字二进制补码的步骤有三步：

确定该数字的非负版本的二进制表示（例如，要计算 -18的二进制补码，首先要确定 18 的二进制表示）
求得二进制反码，即要把 0 替换为 1，把 1 替换为 0
在二进制反码上加 1

要确定 -18 的二进制表示，首先必须得到 [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="Javascript设置光标位置到结尾并显示出来" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F467.html&from=http%3A%2F%2Fjs8.in%2F906.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/11/18/11027176.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;">Javascript设置光标位置到结尾并显示出来</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="7个JavaScript在IE和Firefox浏览器下的差异写法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F426.html&from=http%3A%2F%2Fjs8.in%2F906.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/11/17/10990016.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;">7个JavaScript在IE和Firefox浏览器下的差异写法</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="非字母javascript" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F918.html&from=http%3A%2F%2Fjs8.in%2F906.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/11/30/11698517.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;">非字母javascript</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="JavaScript跨浏览器的添加删除事件绑定函数" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F408.html&from=http%3A%2F%2Fjs8.in%2F906.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/11/17/10978769.bmp" 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;">JavaScript跨浏览器的添加删除事件绑定函数</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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>前几天看到国外人在github总结的<strong>javascript</strong>的奇巧淫技（http://t.cn/herRcq），里面对位运算提到的很多，所以来科普一下javascript的位运算。于是找到了w3cschool的这篇教程，很好很强大啊，于是就忍不住转载了……</p>
<p><strong>ECMAScript</strong> 整数有两种类型，即有符号整数（允许用正数和负数）和无符号整数（只允许用正数）。在 ECMAScript 中，所有整数字面量默认都是有符号整数，这意味着什么呢？</p>
<p>有符号整数使用 31 位表示整数的数值，用第 32 位表示整数的符号，0 表示正数，1 表示负数。数值范围从 -2147483648 到 2147483647。</p>
<p>可以以两种不同的方式存储二进制形式的有符号整数，一种用于存储正数，一种用于存储负数。正数是以真二进制形式存储的，前 31 位中的每一位都表示 2 的幂，从第 1 位（位 0）开始，表示 2<sup>0</sup>，第 2 位（位 1）表示 2<sup>1</sup>。没用到的位用 0 填充，即忽略不计。例如，下图展示的是数 18 的表示法。</p>
<p><img style="border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; ;" src="http://www.w3school.com.cn/i/ct_js_integer_binary_signed_32bits.gif" alt="32 位二进制表示的有符号整数" /></p>
<p>18 的二进制版本只用了前 5 位，它们是这个数字的有效位。把数字转换成二进制字符串，就能看到有效位：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> iNum <span style="color: #339933;">=</span> <span style="color: #CC0000;">18</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>iNum.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">//输出 &quot;10010&quot;</span></pre></div></div>

<p>这段代码只输出 &#8220;10010&#8243;，而不是 18 的 32 位表示。其他的数位并不重要，因为仅使用前 5 位即可确定这个十进制数值。如下图所示：</p>
<p><img style="border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; ;" src="http://www.w3school.com.cn/i/ct_js_integer_binary_number18.gif" alt="5 位二进制表示的整数 18" /></p>
<p>负数也存储为二进制代码，不过采用的形式是二进制补码。计算数字二进制补码的步骤有三步：</p>
<ol>
<li>确定该数字的非负版本的二进制表示（例如，要计算 -18的二进制补码，首先要确定 18 的二进制表示）</li>
<li>求得二进制反码，即要把 0 替换为 1，把 1 替换为 0</li>
<li>在二进制反码上加 1</li>
</ol>
<p>要确定 -18 的二进制表示，首先必须得到 18 的二进制表示，如下所示：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">0000 0000 0000 0000 0000 0000 0001 0010</pre></div></div>

<p>接下来，计算二进制反码，如下所示：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1110</span> <span style="color: #CC0000;">1101</span></pre></div></div>

<p>最后，在二进制反码上加 1，如下所示：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1110</span> <span style="color: #CC0000;">1101</span>
                                      <span style="color: #CC0000;">1</span>
<span style="color: #339933;">---------------------------------------</span>
<span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1111</span> <span style="color: #CC0000;">1110</span> <span style="color: #CC0000;">1110</span></pre></div></div>

<p>因此，-18 的二进制表示即 1111 1111 1111 1111 1111 1111 1110 1110。记住，在处理有符号整数时，开发者不能访问 31 位。</p>
<p>有趣的是，把负整数转换成二进制字符串后，ECMAScript 并不以二进制补码的形式显示，而是用数字绝对值的标准二进制代码前面加负号的形式输出。例如：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> iNum <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">18</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>iNum.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">//输出 &quot;-10010&quot;</span></pre></div></div>

<p>这段代码输出的是 &#8220;-10010&#8243;，而非二进制补码，这是为避免访问位 31。为了简便，ECMAScript 用一种简单的方式处理整数，使得开发者不必关心它们的用法。</p>
<p>另一方面，无符号整数把最后一位作为另一个数位处理。在这种模式中，第 32 位不表示数字的符号，而是值 2<sup>31</sup>。由于这个额外的位，无符号整数的数值范围为 0 到 4294967295。对于小于 2147483647 的整数来说，无符号整数看来与有符号整数一样，而大于 2147483647 的整数则要使用位 31（在有符号整数中，这一位总是 0）。</p>
<p>把无符号整数转换成字符串后，只返回它们的有效位。</p>
<p><span style="font-weight: bold; color: #dd0000;">注意：</span>所有整数字面量都默认存储为有符号整数。只有 ECMAScript 的位运算符才能创建无符号整数。</p>
<p><span id="more-906"></span></p>
<h2 >位运算 NOT</h2>
<p>位运算 NOT 由否定号（~）表示，它是 ECMAScript 中为数不多的与二进制算术有关的运算符之一。</p>
<p>位运算 NOT 是三步的处理过程：</p>
<ol>
<li>把运算数转换成 32 位数字</li>
<li>把二进制数转换成它的二进制反码</li>
<li>把二进制数转换成浮点数</li>
</ol>
<p>例如：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> iNum1 <span style="color: #339933;">=</span> <span style="color: #CC0000;">25</span><span style="color: #339933;">;</span>		<span style="color: #006600; font-style: italic;">//25 等于 00000000000000000000000000011001</span>
<span style="color: #003366; font-weight: bold;">var</span> iNum2 <span style="color: #339933;">=</span> ~iNum1<span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">//转换为 11111111111111111111111111100110</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>iNum2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		<span style="color: #006600; font-style: italic;">//输出 &quot;-26&quot;</span></pre></div></div>

<p>位运算 NOT 实质上是对数字求负，然后减 1，因此 25 变 -26。用下面的方法也可以得到同样的方法：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> iNum1 <span style="color: #339933;">=</span> <span style="color: #CC0000;">25</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> iNum2 <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>iNum1 <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>iNum2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">//输出 -26</span></pre></div></div>

<h2>位运算 AND</h2>
<p>位运算 AND 由和号（&amp;）表示，直接对数字的二进制形式进行运算。它把每个数字中的数位对齐，然后用下面的规则对同一位置上的两个数位进行 AND 运算：</p>
<table style="font-family: Arial, Helvetica, sans-serif; margin-top: 10px; border-collapse: collapse;border: 1px solid #888888;" border="0">
<tbody>
<tr>
<th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; text-align: left; border: 1px solid #888888;">第一个数字中的数位</th>
<th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; text-align: left; border: 1px solid #888888;">第二个数字中的数位</th>
<th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; text-align: left; border: 1px solid #888888;">结果</th>
</tr>
<tr>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
</tr>
<tr>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
</tr>
<tr>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
</tr>
<tr>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
</tr>
</tbody>
</table>
<p>例如，要对数字 25 和 3 进行 AND 运算，代码如下所示：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> iResult <span style="color: #339933;">=</span> <span style="color: #CC0000;">25</span> <span style="color: #339933;">&amp;</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>iResult<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">//输出 &quot;1&quot;</span></pre></div></div>

<p>25 和 3 进行 AND 运算的结果是 1。为什么？分析如下：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"> <span style="color: #CC0000;">25</span> <span style="color: #339933;">=</span> 0000 0000 0000 0000 0000 0000 0001 <span style="color: #CC0000;">1001</span>
  <span style="color: #CC0000;">3</span> <span style="color: #339933;">=</span> 0000 0000 0000 0000 0000 0000 0000 0011
<span style="color: #339933;">---------------------------------------------</span>
AND <span style="color: #339933;">=</span> 0000 0000 0000 0000 0000 0000 0000 0001</pre></div></div>

<p>可以看出，在 25 和 3 中，只有一个数位（位 0）存放的都是 1，因此，其他数位生成的都是 0，所以结果为 1。</p>
<h2 >位运算 OR</h2>
<p>位运算 OR 由符号（|）表示，也是直接对数字的二进制形式进行运算。在计算每位时，OR 运算符采用下列规则：</p>
<table style="font-family: Arial, Helvetica, sans-serif; margin-top: 10px; border-collapse: collapse;border: 1px solid #888888;" border="0">
<tbody>
<tr>
<th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; text-align: left; border: 1px solid #888888;">第一个数字中的数位</th>
<th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; text-align: left; border: 1px solid #888888;">第二个数字中的数位</th>
<th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; text-align: left; border: 1px solid #888888;">结果</th>
</tr>
<tr>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
</tr>
<tr>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
</tr>
<tr>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
</tr>
<tr>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
</tr>
</tbody>
</table>
<p>仍然使用 AND 运算符所用的例子，对 25 和 3 进行 OR 运算，代码如下：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> iResult <span style="color: #339933;">=</span> <span style="color: #CC0000;">25</span> <span style="color: #339933;">|</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>iResult<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">//输出 &quot;27&quot;</span></pre></div></div>

<p>25 和 3 进行 OR 运算的结果是 27：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #CC0000;">25</span> <span style="color: #339933;">=</span> 0000 0000 0000 0000 0000 0000 0001 <span style="color: #CC0000;">1001</span>
 <span style="color: #CC0000;">3</span> <span style="color: #339933;">=</span> 0000 0000 0000 0000 0000 0000 0000 0011
<span style="color: #339933;">--------------------------------------------</span>
OR <span style="color: #339933;">=</span> 0000 0000 0000 0000 0000 0000 0001 <span style="color: #CC0000;">1011</span></pre></div></div>

<p>可以看出，在两个数字中，共有 4 个数位存放的是 1，这些数位被传递给结果。二进制代码 11011 等于 27。</p>
<h2 >位运算 XOR</h2>
<p>位运算 XOR 由符号（^）表示，当然，也是直接对二进制形式进行运算。XOR 不同于 OR，当只有一个数位存放的是 1 时，它才返回 1。真值表如下：</p>
<table style="font-family: Arial, Helvetica, sans-serif; margin-top: 10px; border-collapse: collapse;border: 1px solid #888888;" border="0">
<tbody>
<tr>
<th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; text-align: left; border: 1px solid #888888;">第一个数字中的数位</th>
<th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; text-align: left; border: 1px solid #888888;">第二个数字中的数位</th>
<th style="vertical-align: baseline; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #cccccc; text-align: left; border: 1px solid #888888;">结果</th>
</tr>
<tr>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
</tr>
<tr>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
</tr>
<tr>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">1</td>
</tr>
<tr>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
<td style="vertical-align: text-top; padding-top: 5px; padding-right: 15px; padding-bottom: 5px; padding-left: 5px; background-color: #efefef; border: 1px solid #aaaaaa;">0</td>
</tr>
</tbody>
</table>
<p>对 25 和 3 进行 XOR 运算，代码如下：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> iResult <span style="color: #339933;">=</span> <span style="color: #CC0000;">25</span> <span style="color: #339933;">^</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>iResult<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">//输出 &quot;26&quot;</span></pre></div></div>

<p>25 和 3 进行 XOR 运算的结果是 26：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"> <span style="color: #CC0000;">25</span> <span style="color: #339933;">=</span> 0000 0000 0000 0000 0000 0000 0001 <span style="color: #CC0000;">1001</span>
  <span style="color: #CC0000;">3</span> <span style="color: #339933;">=</span> 0000 0000 0000 0000 0000 0000 0000 0011
<span style="color: #339933;">---------------------------------------------</span>
XOR <span style="color: #339933;">=</span> 0000 0000 0000 0000 0000 0000 0001 <span style="color: #CC0000;">1010</span></pre></div></div>

<p>可以看出，在两个数字中，共有 4 个数位存放的是 1，这些数位被传递给结果。二进制代码 11010 等于 26。</p>
<h2 >左移运算</h2>
<p>左移运算由两个小于号表示（<<）。它把数字中的所有数位向左移动指定的数量。例如，把数字 2（等于二进制中的 10）左移 5 位，结果为 64（等于二进制中的 1000000）：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> iOld <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>		<span style="color: #006600; font-style: italic;">//等于二进制 10</span>
<span style="color: #003366; font-weight: bold;">var</span> iNew <span style="color: #339933;">=</span> iOld <span style="color: #339933;">&lt;&lt;</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">//等于二进制 1000000 十进制 64</span></pre></div></div>

<p><span style="font-weight: bold; color: #dd0000;">注意：</span>在左移数位时，数字右边多出 5 个空位。左移运算用 0 填充这些空位，使结果成为完整的 32 位数字。</p>
<p><img style="border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; ;" src="http://www.w3school.com.cn/i/ct_js_operators_bitwise_leftshift.gif" alt="数字 2 进行左移运算" /></p>
<p><span style="font-weight: bold; color: #dd0000;">注意：</span>左移运算保留数字的符号位。例如，如果把 -2 左移 5 位，得到的是 -64，而不是 64。“符号仍然存储在第 32 位中吗？”是的，不过这在 ECMAScript 后台进行，开发者不能直接访问第 32 个数位。即使输出二进制字符串形式的负数，显示的也是负号形式（例如，-2 将显示 -10。）</p>
<h2 >有符号右移运算</h2>
<p>有符号右移运算符由两个大于号表示（&lt;$lt;）。它把 32 位数字中的所有数位整体右移，同时保留该数的符号（正号或负号）。有符号右移运算符恰好与左移运算相反。例如，把 64 右移 5 位，将变为 2：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> iOld <span style="color: #339933;">=</span> <span style="color: #CC0000;">64</span><span style="color: #339933;">;</span>		<span style="color: #006600; font-style: italic;">//等于二进制 1000000</span>
<span style="color: #003366; font-weight: bold;">var</span> iNew <span style="color: #339933;">=</span> iOld <span style="color: #339933;">&gt;&gt;</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">//等于二进制 10 十进制 2</span></pre></div></div>

<p>同样，移动数位后会造成空位。这次，空位位于数字的左侧，但位于符号位之后。ECMAScript 用符号位的值填充这些空位，创建完整的数字，如下图所示：</p>
<p><img style="border-style: initial; border-color: initial; margin-top: 25px; margin-right: 0px; margin-bottom: 0px; ;" src="http://www.w3school.com.cn/i/ct_js_operators_bitwise_signedrightshift.gif" alt="数字 64 进行有符号右移运算" /></p>
<h2 >无符号右移运算</h2>
<p>无符号右移运算符由三个大于号（>>&gt;）表示，它将无符号 32 位数的所有数位整体右移。对于正数，无符号右移运算的结果与有符号右移运算一样。</p>
<p>用有符号右移运算中的例子，把 64 右移 5 位，将变为 2：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> iOld <span style="color: #339933;">=</span> <span style="color: #CC0000;">64</span><span style="color: #339933;">;</span>		<span style="color: #006600; font-style: italic;">//等于二进制 1000000</span>
<span style="color: #003366; font-weight: bold;">var</span> iNew <span style="color: #339933;">=</span> iOld <span style="color: #339933;">&gt;&gt;&gt;</span><span style="color: #CC0000;">5</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">//等于二进制 10 十进制 2</span></pre></div></div>

<p>对于负数，情况就不同了。</p>
<p>无符号右移运算用 0 填充所有空位。对于正数，这与有符号右移运算的操作一样，而负数则被作为正数来处理。</p>
<p>由于无符号右移运算的结果是一个 32 位的正数，所以负数的无符号右移运算得到的总是一个非常大的数字。例如，如果把 -64 右移 5 位，将得到 134217726。如果得到这种结果的呢？</p>
<p>要实现这一点，需要把这个数字转换成无符号的等价形式（尽管该数字本身还是有符号的），可以通过以下代码获得这种形式：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> iUnsigned64 <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">64</span> <span style="color: #339933;">&gt;&gt;&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span></pre></div></div>

<p>然后，用 Number 类型的 toString() 获取它的真正的位表示，采用的基为 2：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>iUnsigned64.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>这将生成 11111111111111111111111111000000，即有符号整数 -64 的二进制补码表示，不过它等于无符号整数 4294967232。</p>
<p>出于这种原因，使用无符号右移运算符要小心。</p>
<p>原文地址：http://www.w3school.com.cn/js/pro_js_operators_bitwise.asp
<div class="copyright">
<strong>声明：</strong>文章未声明为原创文章，本文链接 <a href="http://js8.in/906.html" title="javascript 位运算符">http://js8.in/906.html</a>. 转载请注明转自<a href="http://js8.in" title="前端开发博客"> JS8.IN ™</a></span></span></div>
<h3 class="box-title">随机文章</h3>
<ul class="box_random">
<li><a href="http://js8.in/270.html" title="病毒清除啦~可是似乎xp中访问博客还是很慢！" rel="bookmark inlinks">病毒清除啦~可是似乎xp中访问博客还是很慢！</a></li>
<li><a href="http://js8.in/350.html" title="javascript高效简洁代码的编写及优化技巧" rel="bookmark inlinks">javascript高效简洁代码的编写及优化技巧</a></li>
<li><a href="http://js8.in/618.html" title="使用PHP把excel(xls)文件导入mysql数据库" rel="bookmark inlinks">使用PHP把excel(xls)文件导入mysql数据库</a></li>
<li><a href="http://js8.in/533.html" title="QQ概念版已经开放下载使用" rel="bookmark inlinks">QQ概念版已经开放下载使用</a></li>
<li><a href="http://js8.in/4.html" title="哎~都挺穷的！" rel="bookmark inlinks">哎~都挺穷的！</a></li>
<li><a href="http://js8.in/672.html" title="使用navigator.geolocation来获取用户的地理位置信息" rel="bookmark inlinks">使用navigator.geolocation来获取用户的地理位置信息</a></li>
<li><a href="http://js8.in/359.html" title="提前体验Google新页面" rel="bookmark inlinks">提前体验Google新页面</a></li>
<li><a href="http://js8.in/28.html" title="08.11.16" rel="bookmark inlinks">08.11.16</a></li>
</ul>
<hr />
<p><small>© 三水清 for <a href="http://js8.in">三水清</a>, 2011. |
<a href="http://js8.in/906.html#comments">One comment</a> |在微博关注我：<a href="//weibo.com/sanshuiqing" target="_blank" title="关注断桥残雪的新浪微博">@清-三水清</a>
<br/>收藏到：
<a rel="nofollow" href="http://share.renren.com/share/buttonshare.do?link=%posturl%&title=%posttitle%" title="收藏本文到人人网" target="_blank">人人网</a> | <a rel="nofollow" href="http://www.douban.com/recommend/?url=%posturl%&title=%posttitle%" title="收藏本文到豆瓣" target="_blank">豆瓣</a> | <a rel="nofollow" href="http://www.kaixin001.com/repaste/share.php?rtitle=%posttitle%&rurl=%posturl%" title="收藏本文到开心网" target="_blank">开心网</a> | <a rel="nofollow" href="http://shuqian.qq.com/post?title=%posttitle%&%20uri=%posturl%" title="收藏本文到QQ书签" target="_blank">QQ书签</a> | <a rel="nofollow" href="http://v.t.sina.com.cn/share/share.php?url=%posturl%&title=%posttitle%" title="收藏本文到新浪微博" target="_blank">新浪微博</a> | <a rel="nofollow" href="http://v.t.qq.com/share/share.php?title=%posttitle%&url=%posturl%&site=http://www.kaixin100.info" title="收藏本文到腾讯微博" target="_blank">腾讯微博</a>
<br/>
Post tags: <a href="http://js8.in/tag/javascript" rel="tag">javascript</a>, <a href="http://js8.in/tag/%e4%bd%8d%e8%bf%90%e7%ae%97" rel="tag">位运算</a><br/>
</small></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="Javascript设置光标位置到结尾并显示出来" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F467.html&from=http%3A%2F%2Fjs8.in%2F906.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/11/18/11027176.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;">Javascript设置光标位置到结尾并显示出来</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="7个JavaScript在IE和Firefox浏览器下的差异写法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F426.html&from=http%3A%2F%2Fjs8.in%2F906.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/11/17/10990016.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;">7个JavaScript在IE和Firefox浏览器下的差异写法</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="非字母javascript" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F918.html&from=http%3A%2F%2Fjs8.in%2F906.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/11/30/11698517.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;">非字母javascript</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="JavaScript跨浏览器的添加删除事件绑定函数" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F408.html&from=http%3A%2F%2Fjs8.in%2F906.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/11/17/10978769.bmp" 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;">JavaScript跨浏览器的添加删除事件绑定函数</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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://js8.in/906.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>IE6中javascript文件开启Gzip出现代码不执行情况</title>
		<link>http://js8.in/902.html</link>
		<comments>http://js8.in/902.html#comments</comments>
		<pubDate>Tue, 15 Nov 2011 12:25:23 +0000</pubDate>
		<dc:creator>三水清</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[网络技术]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[IE6]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://js8.in/?p=902</guid>
		<description><![CDATA[今天处理IE6下的一个bug，经过调试才发现是javascript文件文件总是执行不了，后来中午吃完饭回来才想起以前同事遇见的html中的javascript不可以执行的问题，怀疑是gzip的原因，此次的问题就是因为动态加载javascript文件导致代码不执行，经过研究发现gzip压缩过的javascript文件，如果header里Cache-Control 数据有no-cache, no-store，就会出现IE6中js代码不执行的问题。下面是转发的文章内容：
IE6下面调用开启了gzip压缩Javascript的时候，时常会碰到无法执行的情况，有可能是src调用，有可能是ajax调用，其它的浏览器工作正常，唯独IE6不能正常工作。
出现这个BUG的状况如下：

用户使用IE6浏览器
服务器没有设置 被请求文件(javascript) expires, cache-control.
服务器端开启了chunked encoding模式
通过javascrip的src调用方式或者ajax请求javascript文件
有可能是通过php生成的javascript文件
服务器端开启了gzip压缩

解决这个问题，我们要在服务器的cache-control和expires 头信息上做点工作。
经过测试，header头信息如下的gzip压缩过的javascript调用可以正常工作。
Cache-Control:maxage=1
Connection:keep-alive
Content-Encoding:gzip
Content-Type:application/x-javascript;charset=GBK
Date:Wed, 01 Dec 2010 01:24:07 GMT
Expires:Wed, 01 Dec 2010 01:24:08 GMT
Pragma:public
Server:nginx
Transfer-Encoding:chunked
分析上面的头信息，我们可以注意到：

cache-control必须要设置成maxage=time的格式，maxage是指定缓存生效时间，1为1秒
Expires必须要设置，它的时间稍大于Date即可，Date是页面请求时间，Expires是过期时间
Pragma设置为public


设置好了这两个参数，一般就可以了。
在nginx服务器端，我们需要对服务器配置：
location ~* \.(ico&#124;css&#124;js&#124;png&#124;jpeg&#124;jpg&#124;gif&#124;rar&#124;zip&#124;7z&#124;gz&#124;pdf) {
expires 1d;
}
如果javascript文件是由PHP生成的，我们就需要利用php来输出header控制了。

&#60;?php
$expires = 1;
header&#40;&#34;Pragma: public&#34;&#41;;
header&#40;&#34;Cache-Control: maxage=&#34;.$expires&#41;;
header&#40;'Expires: ' . gmdate&#40;'D, d M Y H:i:s', time&#40;&#41;+$expires&#41; . ' GMT'&#41;;
header&#40;&#34;Content-Type: application/x-javascript;charset=GBK\n&#34;&#41;;

实际应用中，需要灵活配置，Javascript文件，请尽可能通过服务器发送header头，PHP生成javascript文件，效率本来就不高，再加上额外需要输入header头，更是得不偿失。

声明：文章未声明为原创文章，本文链接 http://js8.in/902.html. 转载请注明转自 JS8.IN ™
随机文章

nodejs教程：安装express及配置app.js文件
Img,Script,Link等标签为空可导致页面多余请求
雷：蓝翔技校黑谷歌！
使用CSS设置文字反选的背景颜色
十大Google Buzz的使用技巧
chrome扩展应用开发教程之调试和打包上线
digg掘客功能上线
windows Xp和office盗版软件避免十月20号之后出现黑屏方法


© 三水清 for 三水清, 2011. &#124;
8 comments &#124;在微博关注我：@清-三水清
收藏到：
人人网 &#124; 豆瓣 &#124; 开心网 [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="解决IE6不支持max-height的bug" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F606.html&from=http%3A%2F%2Fjs8.in%2F902.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/11/17/10978851.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;">解决IE6不支持max-height的bug</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="最新版wBox 解决IE6 背景太小bug" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F506.html&from=http%3A%2F%2Fjs8.in%2F902.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/11/17/10977733.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;">最新版wBox 解决IE6 背景太小bug</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 PNG图片不透明问题的解决方法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F380.html&from=http%3A%2F%2Fjs8.in%2F902.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/01/2770440.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 PNG图片不透明问题的解决方法</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下javascript不能隐藏select标签的bug" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F686.html&from=http%3A%2F%2Fjs8.in%2F902.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/11/17/10987937.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下javascript不能隐藏select标签的bug</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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>今天处理IE6下的一个bug，经过调试才发现是<strong>javascript</strong>文件文件总是执行不了，后来中午吃完饭回来才想起以前同事遇见的html中的javascript不可以执行的问题，怀疑是gzip的原因，此次的问题就是因为动态加载javascript文件导致代码不执行，经过研究发现gzip压缩过的javascript文件，如果header里Cache-Control 数据有no-cache, no-store，就会出现IE6中js代码不执行的问题。下面是转发的文章内容：</p>
<p>IE6下面调用开启了gzip压缩Javascript的时候，时常会碰到无法执行的情况，有可能是src调用，有可能是ajax调用，其它的浏览器工作正常，唯独IE6不能正常工作。<br />
出现这个BUG的状况如下：</p>
<ol>
<li>用户使用IE6浏览器</li>
<li>服务器没有设置 被请求文件(javascript) expires, cache-control.</li>
<li>服务器端开启了chunked encoding模式</li>
<li>通过javascrip的src调用方式或者ajax请求javascript文件</li>
<li>有可能是通过php生成的javascript文件</li>
<li>服务器端开启了gzip压缩</li>
</ol>
<p>解决这个问题，我们要在服务器的cache-control和expires 头信息上做点工作。<br />
经过测试，header头信息如下的gzip压缩过的javascript调用可以正常工作。</p>
<blockquote><p>Cache-Control:maxage=1<br />
Connection:keep-alive<br />
Content-Encoding:gzip<br />
Content-Type:application/x-javascript;charset=GBK<br />
Date:Wed, 01 Dec 2010 01:24:07 GMT<br />
Expires:Wed, 01 Dec 2010 01:24:08 GMT<br />
Pragma:public<br />
Server:nginx<br />
Transfer-Encoding:chunked</p></blockquote>
<p>分析上面的头信息，我们可以注意到：</p>
<ol>
<li>cache-control必须要设置成maxage=time的格式，maxage是指定缓存生效时间，1为1秒</li>
<li>Expires必须要设置，它的时间稍大于Date即可，Date是页面请求时间，Expires是过期时间</li>
<li>Pragma设置为public</li>
</ol>
<p><span id="more-902"></span><br />
设置好了这两个参数，一般就可以了。</p>
<p>在nginx服务器端，我们需要对服务器配置：</p>
<blockquote><p>location ~* \.(ico|css|js|png|jpeg|jpg|gif|rar|zip|7z|gz|pdf) {<br />
expires 1d;<br />
}</p></blockquote>
<p>如果javascript文件是由PHP生成的，我们就需要利用php来输出header控制了。</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$expires</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Pragma: public&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cache-Control: maxage=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$expires</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Expires: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">gmdate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'D, d M Y H:i:s'</span><span style="color: #339933;">,</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #000088;">$expires</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' GMT'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: application/x-javascript;charset=GBK<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>实际应用中，需要灵活配置，Javascript文件，请尽可能通过服务器发送header头，PHP生成javascript文件，效率本来就不高，再加上额外需要输入header头，更是得不偿失。
<div class="copyright">
<strong>声明：</strong>文章未声明为原创文章，本文链接 <a href="http://js8.in/902.html" title="IE6中javascript文件开启Gzip出现代码不执行情况">http://js8.in/902.html</a>. 转载请注明转自<a href="http://js8.in" title="前端开发博客"> JS8.IN ™</a></span></span></div>
<h3 class="box-title">随机文章</h3>
<ul class="box_random">
<li><a href="http://js8.in/501.html" title="IE中Image.onload失效的问题" rel="bookmark inlinks">IE中Image.onload失效的问题</a></li>
<li><a href="http://js8.in/506.html" title="最新版wBox 解决IE6 背景太小bug" rel="bookmark inlinks">最新版wBox 解决IE6 背景太小bug</a></li>
<li><a href="http://js8.in/750.html" title="javascript入门到高级PPT" rel="bookmark inlinks">javascript入门到高级PPT</a></li>
<li><a href="http://js8.in/606.html" title="解决IE6不支持max-height的bug" rel="bookmark inlinks">解决IE6不支持max-height的bug</a></li>
<li><a href="http://js8.in/623.html" title="IE event.stopPropagation()阻止冒泡事件" rel="bookmark inlinks">IE event.stopPropagation()阻止冒泡事件</a></li>
<li><a href="http://js8.in/532.html" title="Javascript中模拟PHP的base64_decode和base64_encode函数" rel="bookmark inlinks">Javascript中模拟PHP的base64_decode和base64_encode函数</a></li>
<li><a href="http://js8.in/48.html" title="Ajax评论bug更新" rel="bookmark inlinks">Ajax评论bug更新</a></li>
<li><a href="http://js8.in/516.html" title="js8.in PR值升为4" rel="bookmark inlinks">js8.in PR值升为4</a></li>
</ul>
<hr />
<p><small>© 三水清 for <a href="http://js8.in">三水清</a>, 2011. |
<a href="http://js8.in/902.html#comments">8 comments</a> |在微博关注我：<a href="//weibo.com/sanshuiqing" target="_blank" title="关注断桥残雪的新浪微博">@清-三水清</a>
<br/>收藏到：
<a rel="nofollow" href="http://share.renren.com/share/buttonshare.do?link=%posturl%&title=%posttitle%" title="收藏本文到人人网" target="_blank">人人网</a> | <a rel="nofollow" href="http://www.douban.com/recommend/?url=%posturl%&title=%posttitle%" title="收藏本文到豆瓣" target="_blank">豆瓣</a> | <a rel="nofollow" href="http://www.kaixin001.com/repaste/share.php?rtitle=%posttitle%&rurl=%posturl%" title="收藏本文到开心网" target="_blank">开心网</a> | <a rel="nofollow" href="http://shuqian.qq.com/post?title=%posttitle%&%20uri=%posturl%" title="收藏本文到QQ书签" target="_blank">QQ书签</a> | <a rel="nofollow" href="http://v.t.sina.com.cn/share/share.php?url=%posturl%&title=%posttitle%" title="收藏本文到新浪微博" target="_blank">新浪微博</a> | <a rel="nofollow" href="http://v.t.qq.com/share/share.php?title=%posttitle%&url=%posturl%&site=http://www.kaixin100.info" title="收藏本文到腾讯微博" target="_blank">腾讯微博</a>
<br/>
Post tags: <a href="http://js8.in/tag/bug" rel="tag">bug</a>, <a href="http://js8.in/tag/ie6" rel="tag">IE6</a>, <a href="http://js8.in/tag/javascript" rel="tag">javascript</a><br/>
</small></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="解决IE6不支持max-height的bug" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F606.html&from=http%3A%2F%2Fjs8.in%2F902.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/11/17/10978851.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;">解决IE6不支持max-height的bug</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="最新版wBox 解决IE6 背景太小bug" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F506.html&from=http%3A%2F%2Fjs8.in%2F902.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/11/17/10977733.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;">最新版wBox 解决IE6 背景太小bug</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 PNG图片不透明问题的解决方法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F380.html&from=http%3A%2F%2Fjs8.in%2F902.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/01/2770440.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 PNG图片不透明问题的解决方法</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下javascript不能隐藏select标签的bug" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F686.html&from=http%3A%2F%2Fjs8.in%2F902.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/11/17/10987937.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下javascript不能隐藏select标签的bug</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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://js8.in/902.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>开博两年了：换了主题 改了名</title>
		<link>http://js8.in/900.html</link>
		<comments>http://js8.in/900.html#comments</comments>
		<pubDate>Sun, 13 Nov 2011 12:42:10 +0000</pubDate>
		<dc:creator>三水清</dc:creator>
				<category><![CDATA[心情日志]]></category>
		<category><![CDATA[域名]]></category>
		<category><![CDATA[网站更新]]></category>

		<guid isPermaLink="false">http://js8.in/?p=900</guid>
		<description><![CDATA[js8.in这个域名已经快两年历史了，自己开博客也要有三年历史了吧，可以追溯到大学时候的日志，最早的域名是2fool.cn，可是09年的备案风波，我不得不换了js8.in，当时还是啊花童鞋帮忙起的，主机一直是蹭了他的godaddy主机。昨天去朝阳见了袁童鞋，感觉自己的差距越来越大了，他这半年研究了两个超级牛逼的东西：smarthome和手机当鼠标用的东东，自叹不如。回了家，思前想后，越来越惭愧。普加最近来北京的越来越多，小马哥打电话说：舍不得以前的团队，大家散了，可惜了。的确很想你们，虽然现在可以很容易的见面，可是就像万童鞋说的，来了北京发现少了那种归属感和责任感，现在的工作完全是合同关系。
本来想说博客的事情，却突然发了这么多的感慨。博客正式两年是2012年的1月22，也就是大年三十，那时候肯定没时间发博客，趁着现在有时间，又换了主题一段时间了，就总结下。
三水清博客的发展
本博客从最最开始记录大学的一些事情，到发展成为前端开发博客经历了不少“大事情”，期间换域名2fool.cn 更换问js8.in，顺便名字从二傻网，改为了断桥残雪部落格，之前徐同事经常戏称“残花败柳”，其实断桥残雪是西湖的十大美景之一，有点凄凉的感觉，后来啊花说自己一个朋友也是这个名字，所以一直相机会换下名字，为了找工作，注册了微博（其实之前是有的，因为参加APP大赛当了官方微博用了，后来被封了），并且起名字为“清-三水清”，三水清其实是我名字，因为某机关的优秀同志，把我的清换成了青，所以为了强调自己的清是清水的清，一直会说“是三点水的清的那个清”。
微博的主题
上个月博客换了主题，也就是现在的主题，顺便连博客的名字也就改了。感谢老纪同学百忙中听我唠叨，帮我设计博客主题，听说他快当爹了，提前祝福下老纪和嫂子。

这次的博客主题跟上一个版本的一样是html5+css3的，对IE6也没做兼容，风格很像新版新浪微博，而且换肤直接读取的新浪微博的皮肤css即可，换肤后默认记录皮肤cookie。
域名更短
自从换了主题之后，排名收录都不错，于是果断把网址从www.js8.in，301跳转到了js8.in，更加简洁。经过一段时间来看，百度google的排名还是不错的。所以以后大家进入我的boke就可以少敲4个字符了，直接输入js8.in回车就可以了。
网址的站点统计使用的是量子统计，因为他的代码简单，我将代码copy到本地，修改了一下，只看个访客内容就可以了，没太多的要求，近期来看，每天的IP稳定在700以上，只是周末有点少（可能因为周末程序猿都休息吧），订阅本前端博客的已经超过了300，还是不错的一个数据。
今天看了司徒正美的文章比较有感觉，从面试到工资再讲到了前端工程师的个人发展，发现自己还要继续努力，前端的路子很长，说实话有时候前端做的事情很杂，也不受重视，但是前端却至关重要。浮躁了自己，则会被后来者追上，静下心来看清自己，看清自己的发展才是正道。以后会继续写前端的文章，大家多来捧场，记得我博客的名字：三水清，网址：js8.in.
ps:从小不会写作文，每次写的乱七八糟，自嘲到——意识流风格。

声明：文章未声明为原创文章，本文链接 http://js8.in/900.html. 转载请注明转自 JS8.IN ™
随机文章

Javascript事件触发列表与详解
利用浏览器书签实现的网页划词翻译工具
GoDaddy促销COM域名，在华仅0.99美元
jQuery弹出框wBox的一个使用实例
推荐漂亮的一款WordPress新年插件
切换订阅地址到feedsky
onbeforeunload与a标签在IE中的冲突bug
评论开通了~加上啦~


© 三水清 for 三水清, 2011. &#124;
9 comments &#124;在微博关注我：@清-三水清
收藏到：
人人网 &#124; 豆瓣 &#124; 开心网 &#124; QQ书签 &#124; 新浪微博 &#124; 腾讯微博

Post tags: 域名, 网站更新
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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促销COM域名，在华仅0.99美元" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F383.html&from=http%3A%2F%2Fjs8.in%2F900.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/12/22/1492610.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;">GoDaddy促销COM域名，在华仅0.99美元</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.htm?url=http%3A%2F%2Fjs8.in%2F60.html&from=http%3A%2F%2Fjs8.in%2F900.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/11/18/11026002.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="2fool.cn域名健在，爱墙升级" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F468.html&from=http%3A%2F%2Fjs8.in%2F900.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/11/17/10979313.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;">2fool.cn域名健在，爱墙升级</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="断桥残雪部落格更换新域名JS8.in" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F461.html&from=http%3A%2F%2Fjs8.in%2F900.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/11/17/10979232.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;">断桥残雪部落格更换新域名JS8.in</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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>js8.in这个域名已经快两年历史了，自己开博客也要有三年历史了吧，可以追溯到大学时候的日志，最早的域名是2fool.cn，可是09年的备案风波，我不得不换了js8.in，当时还是<a target="_blank" href="http://oncoding.cn" title="幼学笔记" target="_blank">啊花童鞋</a>帮忙起的，主机一直是蹭了他的godaddy主机。昨天去朝阳见了袁童鞋，感觉自己的差距越来越大了，他这半年研究了两个超级牛逼的东西：smarthome和手机当鼠标用的东东，自叹不如。回了家，思前想后，越来越惭愧。普加最近来北京的越来越多，小马哥打电话说：舍不得以前的团队，大家散了，可惜了。的确很想你们，虽然现在可以很容易的见面，可是就像万童鞋说的，来了北京发现少了那种归属感和责任感，现在的工作完全是合同关系。</p>
<p>本来想说博客的事情，却突然发了这么多的感慨。博客正式两年是2012年的1月22，也就是大年三十，那时候肯定没时间发博客，趁着现在有时间，又换了主题一段时间了，就总结下。</p>
<h3>三水清博客的发展</h3>
<p>本博客从最最开始记录大学的一些事情，到发展成为<strong>前端开发博客</strong>经历了不少“大事情”，期间换域名2fool.cn 更换问js8.in，顺便名字从二傻网，改为了断桥残雪部落格，之前徐同事经常戏称“残花败柳”，其实断桥残雪是西湖的十大美景之一，有点凄凉的感觉，后来啊花说自己一个朋友也是这个名字，所以一直相机会换下名字，为了找工作，注册了微博（其实之前是有的，因为参加APP大赛当了官方微博用了，后来被封了），并且起名字为“清-三水清”，三水清其实是我名字，因为某机关的优秀同志，把我的清换成了青，所以为了强调自己的清是清水的清，一直会说“是三点水的清的那个清”。</p>
<h3>微博的主题</h3>
<p>上个月博客换了主题，也就是现在的主题，顺便连博客的名字也就改了。感谢老纪同学百忙中听我唠叨，帮我设计博客主题，听说他快当爹了，提前祝福下老纪和嫂子。<br />
<span id="more-900"></span><br />
这次的博客主题跟上一个版本的一样是html5+css3的，对IE6也没做兼容，风格很像新版新浪微博，而且换肤直接读取的新浪微博的皮肤css即可，换肤后默认记录皮肤cookie。</p>
<h3>域名更短</h3>
<p>自从换了主题之后，排名收录都不错，于是果断把网址从www.js8.in，301跳转到了js8.in，更加简洁。经过一段时间来看，百度google的排名还是不错的。所以以后大家进入我的boke就可以少敲4个字符了，直接输入<strong>js8.in</strong>回车就可以了。</p>
<p>网址的站点统计使用的是量子统计，因为他的代码简单，我将代码copy到本地，修改了一下，只看个访客内容就可以了，没太多的要求，近期来看，每天的IP稳定在700以上，只是周末有点少（可能因为周末程序猿都休息吧），订阅本前端博客的已经超过了300，还是不错的一个数据。</p>
<p>今天看了司徒正美的文章比较有感觉，从面试到工资再讲到了前端工程师的个人发展，发现自己还要继续努力，前端的路子很长，说实话有时候前端做的事情很杂，也不受重视，但是前端却至关重要。浮躁了自己，则会被后来者追上，静下心来看清自己，看清自己的发展才是正道。以后会继续写前端的文章，大家多来捧场，记得我博客的名字：三水清，网址：js8.in.</p>
<p>ps:从小不会写作文，每次写的乱七八糟，自嘲到——意识流风格。</p>
<div class="copyright">
<strong>声明：</strong>文章未声明为原创文章，本文链接 <a href="http://js8.in/900.html" title="开博两年了：换了主题 改了名">http://js8.in/900.html</a>. 转载请注明转自<a href="http://js8.in" title="前端开发博客"> JS8.IN ™</a></span></span></div>
<h3 class="box-title">随机文章</h3>
<ul class="box_random">
<li><a href="http://js8.in/25.html" title="Adobe紧急发布flash Clickjacking漏洞暂时的解决方案" rel="bookmark inlinks">Adobe紧急发布flash Clickjacking漏洞暂时的解决方案</a></li>
<li><a href="http://js8.in/630.html" title="我开发的新浪微博应用：微博送祝福" rel="bookmark inlinks">我开发的新浪微博应用：微博送祝福</a></li>
<li><a href="http://js8.in/567.html" title="一个中国人笑不起来的笑话" rel="bookmark inlinks">一个中国人笑不起来的笑话</a></li>
<li><a href="http://js8.in/633.html" title="Sina App Engine开发实例：天气预报的定时短信（一）" rel="bookmark inlinks">Sina App Engine开发实例：天气预报的定时短信（一）</a></li>
<li><a href="http://js8.in/300.html" title="公司的DBA说了一些SQL数据库的箴言" rel="bookmark inlinks">公司的DBA说了一些SQL数据库的箴言</a></li>
<li><a href="http://js8.in/792.html" title="基于express+socket.io的nodejs聊天室" rel="bookmark inlinks">基于express+socket.io的nodejs聊天室</a></li>
<li><a href="http://js8.in/683.html" title="一道js正则笔试题" rel="bookmark inlinks">一道js正则笔试题</a></li>
<li><a href="http://js8.in/497.html" title="韩峰其实是个好干部" rel="bookmark inlinks">韩峰其实是个好干部</a></li>
</ul>
<hr />
<p><small>© 三水清 for <a href="http://js8.in">三水清</a>, 2011. |
<a href="http://js8.in/900.html#comments">9 comments</a> |在微博关注我：<a href="//weibo.com/sanshuiqing" target="_blank" title="关注断桥残雪的新浪微博">@清-三水清</a>
<br/>收藏到：
<a rel="nofollow" href="http://share.renren.com/share/buttonshare.do?link=%posturl%&title=%posttitle%" title="收藏本文到人人网" target="_blank">人人网</a> | <a rel="nofollow" href="http://www.douban.com/recommend/?url=%posturl%&title=%posttitle%" title="收藏本文到豆瓣" target="_blank">豆瓣</a> | <a rel="nofollow" href="http://www.kaixin001.com/repaste/share.php?rtitle=%posttitle%&rurl=%posturl%" title="收藏本文到开心网" target="_blank">开心网</a> | <a rel="nofollow" href="http://shuqian.qq.com/post?title=%posttitle%&%20uri=%posturl%" title="收藏本文到QQ书签" target="_blank">QQ书签</a> | <a rel="nofollow" href="http://v.t.sina.com.cn/share/share.php?url=%posturl%&title=%posttitle%" title="收藏本文到新浪微博" target="_blank">新浪微博</a> | <a rel="nofollow" href="http://v.t.qq.com/share/share.php?title=%posttitle%&url=%posturl%&site=http://www.kaixin100.info" title="收藏本文到腾讯微博" target="_blank">腾讯微博</a>
<br/>
Post tags: <a href="http://js8.in/tag/%e5%9f%9f%e5%90%8d" rel="tag">域名</a>, <a href="http://js8.in/tag/%e7%bd%91%e7%ab%99%e6%9b%b4%e6%96%b0" rel="tag">网站更新</a><br/>
</small></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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促销COM域名，在华仅0.99美元" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F383.html&from=http%3A%2F%2Fjs8.in%2F900.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/12/22/1492610.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;">GoDaddy促销COM域名，在华仅0.99美元</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.htm?url=http%3A%2F%2Fjs8.in%2F60.html&from=http%3A%2F%2Fjs8.in%2F900.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/11/18/11026002.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="2fool.cn域名健在，爱墙升级" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F468.html&from=http%3A%2F%2Fjs8.in%2F900.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/11/17/10979313.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;">2fool.cn域名健在，爱墙升级</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="断桥残雪部落格更换新域名JS8.in" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F461.html&from=http%3A%2F%2Fjs8.in%2F900.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/11/17/10979232.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;">断桥残雪部落格更换新域名JS8.in</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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://js8.in/900.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>javascript的String.replace的妙用</title>
		<link>http://js8.in/894.html</link>
		<comments>http://js8.in/894.html#comments</comments>
		<pubDate>Tue, 08 Nov 2011 11:33:54 +0000</pubDate>
		<dc:creator>三水清</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[代码优化]]></category>

		<guid isPermaLink="false">http://js8.in/?p=894</guid>
		<description><![CDATA[作为前端开发人员，总会有点自己的奇技淫巧，毕竟前端开发不同于后端，代码全部暴漏给用户不说，代码冗余了少则影响带宽，多则效率降低。所以今天我也来爆个自己的奇技淫巧。
javascript的String.replace方法应该javascript前端开发工程师都了解，可是你掌握了吗？replace有接受两个参数，第一个参数可以是字符串，也可以是正则表达式，第二个参数除支持字符串之外，还支持$1形式正则匹配的文本，除此之外还支持传入一个处理函数，这个函数的return值就是要替换成的内容。
了解更多javascript的String.replace用法，访问：http://www.w3school.com.cn/js/jsref_replace.asp
String.replace的妙用
在《javascript获取隐藏dom的宽高》中，我就使用了replace，使用replace做一些重复性的操作，减少不必要的代码。
其实这里说的重复性的工作就是循环！例如，我们要获取假如我要求id为div1和div2的两个元素的宽高，一部分人会一点一点的做，先算完div1的，然后做div2的，这样你是否觉得有部分是充分的操作呢，于是可以将取宽高的函数独立出来，这样多了一个函数，而且函数只用这两次，似乎有点浪费。
于是一部分人想到了使用split切分字符串，然后用Array.forEach做循环。例如下面的代码：

&#34;div1 div2&#34;.split&#40;' '&#41;.forEach&#40;function&#40;a,i&#41;&#123;
    console.log&#40;a&#41;;
	//do something
&#125;&#41;


这样对于支持forEach的高级浏览器还是可以的，否则需要扩展数组原型了，不提倡扩展原型，即使不扩展原型提供个额外的函数来操作，就又是浪费，
所以我的做法是使用replace，代码如下：

var wh = &#123;&#125;;
&#34;div1 div2&#34;.replace&#40;/[^ ]+/g,function&#40;a&#41;&#123;
	var elem = document.getElementById&#40;a&#41;;
        wh&#91;a&#93; = &#123;&#125;;
	'Width Height'.replace&#40;/[^ ]+/g, function&#40;i&#41;&#123;
			wh&#91;a&#93;&#91;i&#93; = elem&#91;'offset' + i&#93; &#124;&#124; elem&#91;'client' + i&#93;;
		&#125;&#41;;
&#125;&#41;;
console.log&#40;wh&#41;;

有人说不好懂，而且有点太……，对就是有点装B，呵呵~但是简洁，前端开发的代码还是简洁点好。另外还有通过位操作来判断String.indexOf返回的是否为-1，也是个不错的方法~呵呵，不多说了

声明：文章未声明为原创文章，本文链接 http://js8.in/894.html. 转载请注明转自 JS8.IN ™
随机文章

终于搞明白yu.js的使用方法啦~
javascript 位运算符
Img,Script,Link等标签为空可导致页面多余请求
普通话考试！~
写了一个Follow5 API的PHP类
CSS 3.0 参考手册 (中文版)下载
chrome扩展应用开发教程之调试和打包上线
Wordpress Follow5 插件开发日记—插件后台Ajax应用及jQuery的使用


© 三水清 for 三水清, 2011. &#124;
2 comments &#124;在微博关注我：@清-三水清
收藏到：
人人网 [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="javascript高效简洁代码的编写及优化技巧" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F350.html&from=http%3A%2F%2Fjs8.in%2F894.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/11/18/11026179.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;">javascript高效简洁代码的编写及优化技巧</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="Javascript正则表达式详解" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F473.html&from=http%3A%2F%2Fjs8.in%2F894.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/21/32605340.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;">Javascript正则表达式详解</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="非字母javascript" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F918.html&from=http%3A%2F%2Fjs8.in%2F894.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/11/30/11698517.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;">非字母javascript</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="如何写出高质量的Javascript代码" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F676.html&from=http%3A%2F%2Fjs8.in%2F894.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/11/17/10979856.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;">如何写出高质量的Javascript代码</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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>作为<strong>前端开发</strong>人员，总会有点自己的奇技淫巧，毕竟前端开发不同于后端，代码全部暴漏给用户不说，代码冗余了少则影响带宽，多则效率降低。所以今天我也来爆个自己的奇技淫巧。</p>
<p>j<strong>avascript</strong>的String.replace方法应该javascript前端开发工程师都了解，可是你掌握了吗？replace有接受两个参数，第一个参数可以是字符串，也可以是正则表达式，第二个参数除支持字符串之外，还支持<code>$1</code>形式正则匹配的文本，除此之外还支持传入一个处理函数，这个函数的<code>return</code>值就是要替换成的内容。<br />
了解更多javascript的String.replace用法，访问：http://www.w3school.com.cn/js/jsref_replace.asp</p>
<h3>String.replace的妙用</h3>
<p>在《<a href="http://js8.in/781.html" title="javascript获取隐藏dom的宽高" target="_blank">javascript获取隐藏dom的宽高</a>》中，我就使用了replace，使用replace做一些重复性的操作，减少不必要的代码。</p>
<p>其实这里说的重复性的工作就是循环！例如，我们要获取假如我要求id为div1和div2的两个元素的宽高，一部分人会一点一点的做，先算完div1的，然后做div2的，这样你是否觉得有部分是充分的操作呢，于是可以将取宽高的函数独立出来，这样多了一个函数，而且函数只用这两次，似乎有点浪费。</p>
<p>于是一部分人想到了使用split切分字符串，然后用Array.forEach做循环。例如下面的代码：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">&quot;div1 div2&quot;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' '</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">forEach</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #006600; font-style: italic;">//do something</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p><span id="more-894"></span><br />
这样对于支持forEach的高级浏览器还是可以的，否则需要扩展数组原型了，不提倡扩展原型，即使不扩展原型提供个额外的函数来操作，就又是浪费，</p>
<p>所以我的做法是使用replace，代码如下：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> wh <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #3366CC;">&quot;div1 div2&quot;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/[^ ]+/g</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> elem <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        wh<span style="color: #009900;">&#91;</span>a<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	<span style="color: #3366CC;">'Width Height'</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/[^ ]+/g</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			wh<span style="color: #009900;">&#91;</span>a<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> elem<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'offset'</span> <span style="color: #339933;">+</span> i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> elem<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'client'</span> <span style="color: #339933;">+</span> i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>wh<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>有人说不好懂，而且有点太……，对就是有点装B，呵呵~但是简洁，<strong>前端开发</strong>的代码还是简洁点好。另外还有通过位操作来判断String.indexOf返回的是否为-1，也是个不错的方法~呵呵，不多说了</p>
<div class="copyright">
<strong>声明：</strong>文章未声明为原创文章，本文链接 <a href="http://js8.in/894.html" title="javascript的String.replace的妙用">http://js8.in/894.html</a>. 转载请注明转自<a href="http://js8.in" title="前端开发博客"> JS8.IN ™</a></span></span></div>
<h3 class="box-title">随机文章</h3>
<ul class="box_random">
<li><a href="http://js8.in/460.html" title="做个中国工会网竟然670万！" rel="bookmark inlinks">做个中国工会网竟然670万！</a></li>
<li><a href="http://js8.in/566.html" title="利用GControl和GLayer对象在地图上显示panoramio图片" rel="bookmark inlinks">利用GControl和GLayer对象在地图上显示panoramio图片</a></li>
<li><a href="http://js8.in/918.html" title="非字母javascript" rel="bookmark inlinks">非字母javascript</a></li>
<li><a href="http://js8.in/35.html" title="评论开通了~加上啦~" rel="bookmark inlinks">评论开通了~加上啦~</a></li>
<li><a href="http://js8.in/700.html" title="新浪微博jsSDK操作指南" rel="bookmark inlinks">新浪微博jsSDK操作指南</a></li>
<li><a href="http://js8.in/15.html" title="奋斗了两天！" rel="bookmark inlinks">奋斗了两天！</a></li>
<li><a href="http://js8.in/332.html" title="男人也需要一个依靠[转]" rel="bookmark inlinks">男人也需要一个依靠[转]</a></li>
<li><a href="http://js8.in/267.html" title="新功能-QQ秀上线" rel="bookmark inlinks">新功能-QQ秀上线</a></li>
</ul>
<hr />
<p><small>© 三水清 for <a href="http://js8.in">三水清</a>, 2011. |
<a href="http://js8.in/894.html#comments">2 comments</a> |在微博关注我：<a href="//weibo.com/sanshuiqing" target="_blank" title="关注断桥残雪的新浪微博">@清-三水清</a>
<br/>收藏到：
<a rel="nofollow" href="http://share.renren.com/share/buttonshare.do?link=%posturl%&title=%posttitle%" title="收藏本文到人人网" target="_blank">人人网</a> | <a rel="nofollow" href="http://www.douban.com/recommend/?url=%posturl%&title=%posttitle%" title="收藏本文到豆瓣" target="_blank">豆瓣</a> | <a rel="nofollow" href="http://www.kaixin001.com/repaste/share.php?rtitle=%posttitle%&rurl=%posturl%" title="收藏本文到开心网" target="_blank">开心网</a> | <a rel="nofollow" href="http://shuqian.qq.com/post?title=%posttitle%&%20uri=%posturl%" title="收藏本文到QQ书签" target="_blank">QQ书签</a> | <a rel="nofollow" href="http://v.t.sina.com.cn/share/share.php?url=%posturl%&title=%posttitle%" title="收藏本文到新浪微博" target="_blank">新浪微博</a> | <a rel="nofollow" href="http://v.t.qq.com/share/share.php?title=%posttitle%&url=%posturl%&site=http://www.kaixin100.info" title="收藏本文到腾讯微博" target="_blank">腾讯微博</a>
<br/>
Post tags: <a href="http://js8.in/tag/javascript" rel="tag">javascript</a>, <a href="http://js8.in/tag/%e4%bb%a3%e7%a0%81%e4%bc%98%e5%8c%96" rel="tag">代码优化</a><br/>
</small></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="javascript高效简洁代码的编写及优化技巧" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F350.html&from=http%3A%2F%2Fjs8.in%2F894.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/11/18/11026179.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;">javascript高效简洁代码的编写及优化技巧</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="Javascript正则表达式详解" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F473.html&from=http%3A%2F%2Fjs8.in%2F894.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/21/32605340.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;">Javascript正则表达式详解</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="非字母javascript" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F918.html&from=http%3A%2F%2Fjs8.in%2F894.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/11/30/11698517.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;">非字母javascript</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="如何写出高质量的Javascript代码" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F676.html&from=http%3A%2F%2Fjs8.in%2F894.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/11/17/10979856.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;">如何写出高质量的Javascript代码</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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://js8.in/894.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>linux安装PHP加速器eAccelerator</title>
		<link>http://js8.in/888.html</link>
		<comments>http://js8.in/888.html#comments</comments>
		<pubDate>Thu, 03 Nov 2011 14:42:53 +0000</pubDate>
		<dc:creator>三水清</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://js8.in/?p=888</guid>
		<description><![CDATA[感慨下：做前端开发不少日子了，在前公司也使用过一段时间linux系统，对apache配置比较熟悉，可是对nginx配置还是不熟悉，毕竟自己是做前端开发的，大后端的事情还是比较排斥，以后多练习。前些日子vps到期了，换了空间，没配置好eAccelerator，本来想要朋友全权处理，可是他最近比较忙，只好自己处理了，现在将安装eAccelerator过程记录下，以后留用。
vps是centOS系统，php为nginx+fastcgi，nginx安装目录/usr/local/nginx，php安装目录/usr/local/php，开始在linux安装PHP加速器eAccelerator吧！
预编译安装eAccelerator
安装前准备
安装之前使用需要安装make和phpize，如果安装过，跳过此步骤。运行下面的命令

yum install make php5-dev
//ubuntu下用apt-get

安装eAccelerator
然后开始下载eAccelerator，配置安装编译：
wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
tar xjf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1
/usr/bin/phpize
./configure -enable-eaccelerator=shared -with-php-config=/usr/bin/php-config
make
make install

这时会将eaccelerator安装到php目录中，屏幕会显示eaccelerator.so所在路径，例如：

Installing shared extensions:/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/
记住这个路径，在后面的配置文件里面会用到。
配置eAccelerator缓存路径

mkdir /tmp/eaccelerator
chmod 777 /tmp/eaccelerator
配置eAccelerator
安装eAccelerator之后，需要配置才可以使用哦~所以我们需要在php.ini中添加eAccelerator的配置，当然你也可以新建个配置文件，在php.ini中引入配置文件即可。
[eaccelerator]
zend_extension=&#8221;/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so&#8221;
eaccelerator.shm_size=&#8221;8&#8243;
eaccelerator.cache_dir=&#8221;/tmp/eaccelerator&#8221;
eaccelerator.enable=&#8221;1&#8243;
eaccelerator.optimizer=&#8221;1&#8243;
eaccelerator.check_mtime=&#8221;1&#8243;
eaccelerator.debug=&#8221;0&#8243;
eaccelerator.filter=&#8221;"
eaccelerator.shm_max=&#8221;0&#8243;
eaccelerator.shm_ttl=&#8221;3600&#8243;
eaccelerator.shm_prune_period=&#8221;3600&#8243;
eaccelerator.shm_only=&#8221;0&#8243;
eaccelerator.compress=&#8221;1&#8243;
eaccelerator.compress_level=&#8221;9&#8243;
eaccelerator.keys = &#8220;disk_only&#8221;
eaccelerator.sessions = &#8220;disk_only&#8221;
eaccelerator.content = &#8220;disk_only&#8221;
几个重要配置说明
安装为 Zend extension 模式为上面的配置，如果你使用了thread safe模式安装的PHP，你必须使用 “zend_extension_ts” 替换第二行的 “zend_extension”，安装为 PHP extension 模式为“extension”。
cache_dir:缓存的文件夹位置，就是上一步我们mkdir的路径。
shm_size:缓存的大小，根据自己服务器实际情况设置
enable:开启或关闭 eAccelerator，&#8221;1&#8243; 为开启，&#8221;0&#8243; 为关闭。默认值为 &#8220;1&#8243;。
optimizer:启或关闭内部优化器，可以提升代码执行速度。&#8221;1&#8243; 为开启，&#8221;0&#8243; 为关闭。默认值为 &#8220;1&#8243;。
check_mtime:打开或者关闭 PHP 的文件修改检查，&#8221;1&#8243; 是指打开，&#8221;0&#8243; 是指关闭。默认值是 &#8220;1&#8243;。
debug:开启或关闭调试日志记录。&#8221;1&#8243; 为开启，&#8221;0&#8243; 为关闭。默认值为 &#8220;0&#8243;。会将缓存命中得记录写入日志。
filter:判断哪些 PHP 文件必须缓存。可以指定缓存和不缓存的文件类型（如 &#8220;*.php *.phtml&#8221;等）如果参数以 &#8220;!&#8221; 开头，则匹配这些参数的文件被忽略缓存。默认值为 &#8220;&#8221;，即，所有 PHP [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="PHP实现javascript的escape和unescape函数" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F941.html&from=http%3A%2F%2Fjs8.in%2F888.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/2012/01/29/14457910.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;">PHP实现javascript的escape和unescape函数</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="通过PHP批量下载图片文件" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F586.html&from=http%3A%2F%2Fjs8.in%2F888.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/11/17/10977771.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;">通过PHP批量下载图片文件</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="PHP生成RSS类：RSS.class.php" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F412.html&from=http%3A%2F%2Fjs8.in%2F888.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/11/17/10979694.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;">PHP生成RSS类：RSS.class.php</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="php获取来访者IP信息" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F509.html&from=http%3A%2F%2Fjs8.in%2F888.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/24/2916193.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;">php获取来访者IP信息</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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>感慨下：做<strong>前端开发</strong>不少日子了，在前公司也使用过一段时间linux系统，对apache配置比较熟悉，可是对nginx配置还是不熟悉，毕竟自己是做前端开发的，大后端的事情还是比较排斥，以后多练习。前些日子vps到期了，换了空间，没配置好<strong>eAccelerator</strong>，本来想要朋友全权处理，可是他最近比较忙，只好自己处理了，现在将安装eAccelerator过程记录下，以后留用。</p>
<p>vps是centOS系统，php为nginx+fastcgi，nginx安装目录/usr/local/nginx，php安装目录/usr/local/php，开始在linux安装PHP加速器eAccelerator吧！</p>
<h2>预编译安装eAccelerator</h2>
<h3>安装前准备</h3>
<p>安装之前使用需要安装make和phpize，如果安装过，跳过此步骤。运行下面的命令</p>
<blockquote><p>
yum install make php5-dev<br />
//ubuntu下用apt-get
</p></blockquote>
<h3>安装eAccelerator</h3>
<p>然后开始下载eAccelerator，配置安装编译：</p>
<blockquote><p>wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2<br />
tar xjf eaccelerator-0.9.6.1.tar.bz2<br />
cd eaccelerator-0.9.6.1<br />
/usr/bin/phpize<br />
./configure -enable-eaccelerator=shared -with-php-config=/usr/bin/php-config<br />
make<br />
make install
</p></blockquote>
<p>这时会将eaccelerator安装到php目录中，屏幕会显示eaccelerator.so所在路径，例如：<br />
<span id="more-888"></span></p>
<blockquote><p>Installing shared extensions:/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/</p></blockquote>
<p>记住这个路径，在后面的配置文件里面会用到。</p>
<h3>配置eAccelerator缓存路径</h3>
<blockquote><p>
mkdir /tmp/eaccelerator<br />
chmod 777 /tmp/eaccelerator</p></blockquote>
<h2>配置eAccelerator</h2>
<p><strong>安装eAccelerator</strong>之后，需要配置才可以使用哦~所以我们需要在php.ini中添加eAccelerator的配置，当然你也可以新建个配置文件，在php.ini中引入配置文件即可。</p>
<blockquote><p>[eaccelerator]<br />
zend_extension=&#8221;/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so&#8221;<br />
eaccelerator.shm_size=&#8221;8&#8243;<br />
eaccelerator.cache_dir=&#8221;/tmp/eaccelerator&#8221;<br />
eaccelerator.enable=&#8221;1&#8243;<br />
eaccelerator.optimizer=&#8221;1&#8243;<br />
eaccelerator.check_mtime=&#8221;1&#8243;<br />
eaccelerator.debug=&#8221;0&#8243;<br />
eaccelerator.filter=&#8221;"<br />
eaccelerator.shm_max=&#8221;0&#8243;<br />
eaccelerator.shm_ttl=&#8221;3600&#8243;<br />
eaccelerator.shm_prune_period=&#8221;3600&#8243;<br />
eaccelerator.shm_only=&#8221;0&#8243;<br />
eaccelerator.compress=&#8221;1&#8243;<br />
eaccelerator.compress_level=&#8221;9&#8243;<br />
eaccelerator.keys = &#8220;disk_only&#8221;<br />
eaccelerator.sessions = &#8220;disk_only&#8221;<br />
eaccelerator.content = &#8220;disk_only&#8221;</p></blockquote>
<h3>几个重要配置说明</h3>
<p>安装为 Zend extension 模式为上面的配置，如果你使用了thread safe模式安装的PHP，你必须使用 “zend_extension_ts” 替换第二行的 “zend_extension”，安装为 PHP extension 模式为“extension”。</p>
<p>cache_dir:缓存的文件夹位置，就是上一步我们mkdir的路径。<br />
shm_size:缓存的大小，根据自己服务器实际情况设置<br />
enable:开启或关闭 eAccelerator，&#8221;1&#8243; 为开启，&#8221;0&#8243; 为关闭。默认值为 &#8220;1&#8243;。<br />
optimizer:启或关闭内部优化器，可以提升代码执行速度。&#8221;1&#8243; 为开启，&#8221;0&#8243; 为关闭。默认值为 &#8220;1&#8243;。<br />
check_mtime:打开或者关闭 PHP 的文件修改检查，&#8221;1&#8243; 是指打开，&#8221;0&#8243; 是指关闭。默认值是 &#8220;1&#8243;。<br />
debug:开启或关闭调试日志记录。&#8221;1&#8243; 为开启，&#8221;0&#8243; 为关闭。默认值为 &#8220;0&#8243;。会将缓存命中得记录写入日志。<br />
filter:判断哪些 PHP 文件必须缓存。可以指定缓存和不缓存的文件类型（如 &#8220;*.php *.phtml&#8221;等）如果参数以 &#8220;!&#8221; 开头，则匹配这些参数的文件被忽略缓存。默认值为 &#8220;&#8221;，即，所有 PHP 文件都将被缓存。<br />
shm_max:当使用 &#8221; eaccelerator_put() &#8221; 函数时禁止其向共享内存中存储过大的文件。该参数指定允许存储的最大值，单位：字节 (10240, 10K, 1M)。&#8221;0&#8243; 为不限制。默认值为 &#8220;0&#8243;。<br />
shm_ttl:当 eAccelerator 获取新脚本的共享内存大小失败时，它将从共享内存中删除所有在最后 &#8220;shm_ttl&#8221; 秒内没有存取的脚本缓存。默认值为&#8221;0&#8243;，为不从共享内存中删除任何缓存文件。<br />
shm_prune_period:当 eAccelerator 获取新脚本的共享内存大小失败时，他将试图从共享内存中删除早于&#8221;shm_prune_period&#8221; 秒的缓存脚本。默认值为 &#8220;0&#8243;，为不从共享内存中删除任何缓存文件。<br />
shm_only:允许或禁止将已编译脚本缓存在磁盘上。该选项对 session 数据和内容缓存无效。默认值为 &#8220;0&#8243;，为使用磁盘和共享内存进行缓存。<br />
compress:允许或禁止压缩内容缓存。默认值为 &#8220;1&#8243;，为允许压缩。<br />
compress_level:指定内容缓存的压缩等级。默认值为 &#8220;9&#8243;，为最高等级。</p>
<p>eaccelerator.keys = &#8220;disk_only&#8221;<br />
eaccelerator.sessions = &#8220;disk_only&#8221;<br />
eaccelerator.content = &#8220;disk_only&#8221;</p>
<p>设置内容缓存的存放的地方，可以设置为：<br />
shm_and_disk  在共享缓存和硬盘(默认值)<br />
shm      默认存在共享内存，如果共享内存已满或大小超过 &#8220;eaccelerator.shm_max&#8221; 的值，就存到硬盘<br />
shm_only    只存放在共享内存<br />
disk_only    只存放在硬盘<br />
none      不缓存数据</p>
<h3>重启相关服务</h3>
<blockquote><p># 重启nginx<br />
/etc/init.d/nginx restart<br />
# 重启PHP-CGI<br />
/etc/init.d/php-fastcgi restart</p></blockquote>
<h2>查看eAccelerator运行情况</h2>
<p>eAccelerator安装包里有一个control.php文件，把它复制到网站的任意目录，然后将路径添加到配置文件，就可以通过这个php文件可以用它查看和管理eAccelerator，这个必须指定，否则查看缓存内容的时候会出错，访问时候默认的用户名是：admin，密码：eAccelerator，用户名和密码可以在control.php中修改：</p>
<blockquote><p>eaccelerator.allowed_admin_path = &#8220;/data/wsdata/wwwroot&#8221;</p></blockquote>
<p>这样我们就可以通过访问control.php来查看eAccelerator的命中率了，还可以在线清理缓存目录，查看配置的缓存空间使用率。
<div class="copyright">
<strong>声明：</strong>文章未声明为原创文章，本文链接 <a href="http://js8.in/888.html" title="linux安装PHP加速器eAccelerator">http://js8.in/888.html</a>. 转载请注明转自<a href="http://js8.in" title="前端开发博客"> JS8.IN ™</a></span></span></div>
<h3 class="box-title">随机文章</h3>
<ul class="box_random">
<li><a href="http://js8.in/906.html" title="javascript 位运算符" rel="bookmark inlinks">javascript 位运算符</a></li>
<li><a href="http://js8.in/587.html" title="爱墙推出基于PHPwind整合版本，欢迎下载试用" rel="bookmark inlinks">爱墙推出基于PHPwind整合版本，欢迎下载试用</a></li>
<li><a href="http://js8.in/4.html" title="哎~都挺穷的！" rel="bookmark inlinks">哎~都挺穷的！</a></li>
<li><a href="http://js8.in/28.html" title="08.11.16" rel="bookmark inlinks">08.11.16</a></li>
<li><a href="http://js8.in/415.html" title="利用浏览器书签实现的网页划词翻译工具" rel="bookmark inlinks">利用浏览器书签实现的网页划词翻译工具</a></li>
<li><a href="http://js8.in/385.html" title="六个精美的WordPress圣诞插件" rel="bookmark inlinks">六个精美的WordPress圣诞插件</a></li>
<li><a href="http://js8.in/566.html" title="利用GControl和GLayer对象在地图上显示panoramio图片" rel="bookmark inlinks">利用GControl和GLayer对象在地图上显示panoramio图片</a></li>
<li><a href="http://js8.in/623.html" title="IE event.stopPropagation()阻止冒泡事件" rel="bookmark inlinks">IE event.stopPropagation()阻止冒泡事件</a></li>
</ul>
<p style="margin:0;padding:0;height:1px;overflow:hidden;">
    <script type="text/javascript"><!--
        var wumiiSitePrefix = "http://js8.in";
        var wumiiEnableCustomPos = false;
        var wumiiParams = "&#038;num=4&#038;mode=3&#038;displayInFeed=1&#038;version=1.0.5.5&#038;pf=WordPress2.8.6";
    //--></script></p>
<hr />
<p><small>© 三水清 for <a href="http://js8.in">三水清</a>, 2011. |
<a href="http://js8.in/888.html#comments">One comment</a> |在微博关注我：<a href="//weibo.com/sanshuiqing" target="_blank" title="关注断桥残雪的新浪微博">@清-三水清</a>
<br/>收藏到：
<a rel="nofollow" href="http://share.renren.com/share/buttonshare.do?link=%posturl%&title=%posttitle%" title="收藏本文到人人网" target="_blank">人人网</a> | <a rel="nofollow" href="http://www.douban.com/recommend/?url=%posturl%&title=%posttitle%" title="收藏本文到豆瓣" target="_blank">豆瓣</a> | <a rel="nofollow" href="http://www.kaixin001.com/repaste/share.php?rtitle=%posttitle%&rurl=%posturl%" title="收藏本文到开心网" target="_blank">开心网</a> | <a rel="nofollow" href="http://shuqian.qq.com/post?title=%posttitle%&%20uri=%posturl%" title="收藏本文到QQ书签" target="_blank">QQ书签</a> | <a rel="nofollow" href="http://v.t.sina.com.cn/share/share.php?url=%posturl%&title=%posttitle%" title="收藏本文到新浪微博" target="_blank">新浪微博</a> | <a rel="nofollow" href="http://v.t.qq.com/share/share.php?title=%posttitle%&url=%posturl%&site=http://www.kaixin100.info" title="收藏本文到腾讯微博" target="_blank">腾讯微博</a>
<br/>
Post tags: <a href="http://js8.in/tag/linux" rel="tag">linux</a>, <a href="http://js8.in/tag/php" rel="tag">php</a><br/>
</small></p><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="PHP实现javascript的escape和unescape函数" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F941.html&from=http%3A%2F%2Fjs8.in%2F888.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/2012/01/29/14457910.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;">PHP实现javascript的escape和unescape函数</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="通过PHP批量下载图片文件" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F586.html&from=http%3A%2F%2Fjs8.in%2F888.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/11/17/10977771.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;">通过PHP批量下载图片文件</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="PHP生成RSS类：RSS.class.php" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F412.html&from=http%3A%2F%2Fjs8.in%2F888.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/11/17/10979694.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;">PHP生成RSS类：RSS.class.php</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="php获取来访者IP信息" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fjs8.in%2F509.html&from=http%3A%2F%2Fjs8.in%2F888.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/24/2916193.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;">php获取来访者IP信息</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" 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://js8.in/888.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

