<?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>阅微堂 &#187; 网页技术</title>
	<atom:link href="http://zhiqiang.org/blog/tag/%e7%bd%91%e9%a1%b5%e6%8a%80%e6%9c%af/feed" rel="self" type="application/rss+xml" />
	<link>http://zhiqiang.org/blog</link>
	<description>理工科背景的证券从业人员</description>
	<lastBuildDate>Sun, 05 Feb 2012 03:59:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>加速blog：处理页面图片</title>
		<link>http://zhiqiang.org/blog/it/speedup-blog-about-images.html</link>
		<comments>http://zhiqiang.org/blog/it/speedup-blog-about-images.html#comments</comments>
		<pubDate>Wed, 05 Dec 2007 15:18:36 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[IT技术]]></category>
		<category><![CDATA[CSS Sprites]]></category>
		<category><![CDATA[url scheme]]></category>
		<category><![CDATA[网站提速]]></category>
		<category><![CDATA[网页技术]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/?p=714</guid>
		<description><![CDATA[博客 » IT技术 » 网站提速 » 系列：网站提速 查看该系列所有文章 作为文章的或者功能性的或者美学意义上的需求，现在blog越来越丰富多彩，图片也越来越多。 选择合适的图片尺寸 现在数码相机越来越好，动辄800万像素，出来的照片也常在1M以上。但其实电脑上特别是浏览器上根本就没那么大的空间来显示图片（除非放大显示），作为网页上的图片，800*600的图片足够用了。...]]></description>
			<content:encoded><![CDATA[<p id="breadcrumb" class="breadcrumb"><a href="http://zhiqiang.org/blog/">博客</a> » <a href="http://zhiqiang.org/blog/category/it">IT技术</a> » <a href='http://zhiqiang.org/blog/tag/%e7%bd%91%e7%ab%99%e6%8f%90%e9%80%9f'>网站提速</a>  » </p><div class="series"><span>系列：<b>网站提速</b></span><br/>
<a href="http://zhiqiang.org/blog/tag/%e7%bd%91%e7%ab%99%e6%8f%90%e9%80%9f">查看该系列所有文章</a>
<div id='series'></div>
</div>  <p>作为文章的或者功能性的或者美学意义上的需求，现在blog越来越丰富多彩，图片也越来越多。</p>
<h4>选择合适的图片尺寸</h4>
<p>现在数码相机越来越好，动辄800万像素，出来的照片也常在1M以上。但其实电脑上特别是浏览器上根本就没那么大的空间来显示图片（除非放大显示），作为网页上的图片，800*600的图片足够用了。WordPress上传照片的时候会自动使用微缩图，我觉得这种设置比较好。</p>
<h4>不要GZIP图片，但设置Cache</h4>
<p> 图片已经是压缩保存了的，GZIP压缩徒耗服务器的CPU而已。因为图片的变动比较小，所以最好为它们设置强有力的Cache指令。<br />
<h4>指定图片大小</h4>
<p>如果是通过&lt;img src='pic.jpg'/&gt;的方式插入图片，最好明确指定图片大小，如&lt;img src='pic.jpg' height='300' width='300'/&gt;，可减少页面跳动。推荐使用windows live writer写blog，自动指定图片大小，调节也很方便。</p>
<h4>图片背景化</h4>
<p>如果图片在每个页面上的位置比较固定，最好用CSS作为背景载入，这样做的好处是背景图片的载入是后台进行的，不会造成页面晃动。</p>
<h4>Image Map</h4>
<h4>使用CSS Sprites</h4>
<p>介绍和实现方法见<a href="http://zhiqiang.org/blog/it/speedup-website-with-css-sprites.html">用CSS Sprites让网站再加速</a>。</p>
<h4>使用URL scheme</h4>
<p>这种方法只对firefox有效，在IE下无效。<a href="http://tools.ietf.org/html/rfc2397"><code>data:</code> URL scheme</a>可以让你把图片信息直接嵌入在CSS语句中，理论上而言这是小CSS图片的最好解决方案。</p>
<div><h4>相关文章</h4><ul><li><a href="http://zhiqiang.org/blog/it/speedup-website-with-css-sprites.html">用CSS Sprites让网站再加速</a></li><li><a href="http://zhiqiang.org/blog/it/innerhtml-2-cd-issue-dynamic-modification-table-function-of-js.html">innerHTML只读问题 &amp; 两个动态修改Table的js函数</a></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-about-javascript-css.html">加速blog：关于javascript(css)</a></li><li><a href="http://zhiqiang.org/blog/it/speedup-your-blog.html">加速blog：序</a></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-choose-appropriate-server.html">加速blog：选择合适的服务器</a></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-factors-of-slowness.html">加速blog：网站响应缓慢的因素</a></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-set-browser-cache.html">加速blog：设置浏览器缓存</a></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-optimize-wordpress-database.html">加速blog：监测和优化WordPress数据库</a></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-optimize-wordpress.html">加速blog：优化WordPress程序效率</a></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-cache-wordpress.html">加速blog：WordPress的缓存和静态化</a></li></ul></div>    <p></p>
    <hr noshade style="margin:0;height:1px" />
    <p>&copy; zhiqiang for <a href="http://zhiqiang.org/blog">阅微堂</a>, 2007. | <a href="http://zhiqiang.org/blog/it/speedup-blog-about-images.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/it/speedup-blog-about-images.html#comments">0&#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/it/speedup-blog-about-images.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>加速blog：关于javascript(css)</title>
		<link>http://zhiqiang.org/blog/it/speedup-blog-about-javascript-css.html</link>
		<comments>http://zhiqiang.org/blog/it/speedup-blog-about-javascript-css.html#comments</comments>
		<pubDate>Tue, 04 Dec 2007 12:07:22 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[IT技术]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[网页技术]]></category>
		<category><![CDATA[速度优化.javascript]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/?p=712</guid>
		<description><![CDATA[博客 » IT技术 » 网页技术 » 这里先谈一下关于javascript和CSS的问题。 压缩你的javascript和css 这里的压缩和前面的GZIP压缩不同，而是压缩空格，去除注释等，调整顺序等。如果你的服务器不支持GZIP压缩，你就更应该使用下面的压缩工具处理你的css和javascript了。 压缩CSS：压缩比率能达到20%到50%。 压缩javascript：即使是最安全的压缩模式，压缩比率也能达到20%到50%。 警告：以上压...]]></description>
			<content:encoded><![CDATA[<p id="breadcrumb" class="breadcrumb"><a href="http://zhiqiang.org/blog/">博客</a> » <a href="http://zhiqiang.org/blog/category/it">IT技术</a> » <a href='http://zhiqiang.org/blog/tag/%e7%bd%91%e9%a1%b5%e6%8a%80%e6%9c%af'>网页技术</a>  » </p><p>这里先谈一下关于javascript和CSS的问题。</p>
<h3>压缩你的javascript和css</h3>
<p>这里的压缩和前面的GZIP压缩不同，而是压缩空格，去除注释等，调整顺序等。如果你的服务器不支持GZIP压缩，你就更应该使用下面的压缩工具处理你的css和javascript了。</p>
<p><a href="http://www.cssdrive.com/index.php/main/csscompressoradvanced/">压缩CSS</a>：压缩比率能达到20%到50%。</p>
<p>压缩javascript：即使是最安全的压缩模式，压缩比率也能达到20%到50%。</p>
<p>警告：以上压缩会破坏文档格式，请保留好压缩前文档的备份。</p>
<h3>合并javascript和css文件</h3>
<p>这种方面比较繁琐，完全是体力活。可以手动把文件内容都复制粘贴到一起，也可以新写一个php文件include所有需要的文件。在<a href="http://zhiqiang.org/blog/it/wordpress-accelerate-the-pace-of-pages-printed-in-the-generation-and.html">加快WordPress的页面生成和载入速度</a>有比较详细的操作方法。</p>
<h3>javasctip和css文件位置</h3>
<p>一般来说，CSS最好放在HEAD区域内（即&lt;body&gt;之前），这样可以减少页面重绘。javascipt文件越靠后引用越好，比如Google Analytics的统计代码最好放在&lt;/body&gt;之前。也可以考虑<a href="http://msdn.microsoft.com/en-us/library/ms533719.aspx" target="_blank">script的defer属性</a>。</p>
<div><h4>相关文章</h4><ul><li><a href="http://zhiqiang.org/blog/it/speedup-website-with-css-sprites.html">用CSS Sprites让网站再加速</a></li><li><a href="http://zhiqiang.org/blog/it/dreamhost-on-gzip-cache.html">Dreamhost上的GZIP &#038; Cache</a></li><li><a href="http://zhiqiang.org/blog/it/innerhtml-2-cd-issue-dynamic-modification-table-function-of-js.html">innerHTML只读问题 &amp; 两个动态修改Table的js函数</a></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-about-images.html">加速blog：处理页面图片</a></li></ul></div>    <p></p>
    <hr noshade style="margin:0;height:1px" />
    <p>&copy; zhiqiang for <a href="http://zhiqiang.org/blog">阅微堂</a>, 2007. | <a href="http://zhiqiang.org/blog/it/speedup-blog-about-javascript-css.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/it/speedup-blog-about-javascript-css.html#comments">0&#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/it/speedup-blog-about-javascript-css.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用CSS Sprites让网站再加速</title>
		<link>http://zhiqiang.org/blog/it/speedup-website-with-css-sprites.html</link>
		<comments>http://zhiqiang.org/blog/it/speedup-website-with-css-sprites.html#comments</comments>
		<pubDate>Tue, 09 Oct 2007 08:30:22 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[IT技术]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[CSS Sprites]]></category>
		<category><![CDATA[缓存]]></category>
		<category><![CDATA[网站加速]]></category>
		<category><![CDATA[网页技术]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/posts/speedup-website-with-css-sprites.html</guid>
		<description><![CDATA[博客 » IT技术 » 缓存 » 我对于blog的速度有着变态的需求. 网站速度与HTML请求数目有很直接的关系，所以我一直没有在网页上放过多的背景图片——注意这里有个网页加速的小技巧，对于网页上固定位置的图片，应该尽量使用CSS背景图片，而不要用img标签嵌入。 为减少页面上的背景图片数量，嵌入式图片是一个好主意，data: URL scheme可以让你把图片信息直接嵌入在CSS语句中，...]]></description>
			<content:encoded><![CDATA[<p id="breadcrumb" class="breadcrumb"><a href="http://zhiqiang.org/blog/">博客</a> » <a href="http://zhiqiang.org/blog/category/it">IT技术</a> » <a href='http://zhiqiang.org/blog/tag/%e7%bc%93%e5%ad%98'>缓存</a>  » </p><p><img style="margin: 0px 10px 0px 0px" src="http://www.w3schools.com/css/logocss.gif" align="left"/> 我对于blog的速度有着变态的需求. 网站速度与HTML请求数目有很直接的关系，所以我一直没有在网页上放过多的背景图片——注意这里有个网页加速的小技巧，对于网页上固定位置的图片，应该尽量使用CSS背景图片，而不要用img标签嵌入。</p>
<p>为减少页面上的背景图片数量，嵌入式图片是一个好主意，<a href="http://tools.ietf.org/html/rfc2397"><code>data:</code> URL scheme</a>可以让你把图片信息直接嵌入在CSS语句中，理论上而言这是最好的解决方案。可惜目前IE不支持！又是万恶的IE。下面是效果图(Firefox有效)：</p>
<p align="center"><img alt="You see this because you are using IE!" src="data:image/gif;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAwAAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFzByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSpa/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJlZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uisF81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PHhhx4dbgYKAAA7"/></p>
<p>另外一个就是CSS Sprites了，很久以前就见到过，不过操作比较复杂，所以一直没有用。今天，看到一个<a href="http://realazy.org/blog/2007/10/08/css-sprites/" target="_blank">更详细的介绍</a>，而且Yahoo和Facebook都在用这种方式，见<a href="http://developer.yahoo.com/yui/build/assets/skins/sam/sprite.png" target="_blank" rel="nofollow">这里</a>和这里。我也决定紧跟一下潮流。</p>
<p>CSS Sprites就是将网页上所有的背景图片都放在一张大图片上，<a href="http://realazy.org/blog/2007/10/08/css-sprites/" target="_blank">更详细的介绍</a></p>
<blockquote><p>在需要用到图片的时候，现阶段是通过CSS属性<code>background-image</code>组合<code>background-repeat</code>, <code>background-position</code>等来实现......我们的主角是，你一定猜到了，就是<code>background-position</code>。通过调整<code>background-position</code>的数值，背景图片就能以不同的面貌出现在你眼前。其实图片整体面貌没有变，由于图片位置的改变，你看到只该看到的而已。就好比手表上的日期，你今天看到是21，明天看到是22，是因为它的<strong>position</strong>往上跳了一格。所以你也大概了解到，CSS Sprites一般只能使用到固定大小的盒子（box）里，这样才能够遮挡住不应该看到的部分。</p>
</blockquote>
<p>比如本站的所有背景图片已经整合成<a href="http://zhiqiang.org/blog/wp-content/themes/yuewei/images/b.gif" target="_blank">单独一张</a>，然后通过CSS定义背景：</p>
<blockquote><pre>.<span style="color: #800000">bloglines</span>, .<span style="color: #800000">zhuaxia</span>, .<span style="color: #800000">google</span>, {
    <span style="color: #ff0000">background-image</span>: <span style="color: #0000ff">url(images/b.gif)</span>;
}

.<span style="color: #800000">bloglines</span> { <span style="color: #ff0000">background-position</span>: <span style="color: #0000ff">0 -216px</span>; }
.<span style="color: #800000">zhuaxia</span> { <span style="color: #ff0000">background-position</span>: <span style="color: #0000ff">0 -332px</span>; }
.<span style="color: #800000">google</span> { <span style="color: #ff0000">background-position</span>: <span style="color: #0000ff">0 -448px</span>; }</pre>
</blockquote>
<p>上面这一段代码用同一张背景图片生成了Google，Zhuaxia，Bloglines的订阅图片。效果可见右侧栏的订阅区，与各自指定图片背景效果完全一样。</p>
<p>上面最麻烦的一个地方在于如何生成大图片，利用PhotoShop的Merge功能可以把图片整合在一起，但每个小图片在大图片的位置参数需要一个一个去弄，比较麻烦，但是比较自由。利用<a href="http://spritegen.website-performance.org/" target="_blank">CSS Sprites Generator</a>，一切都自动搞定。这个网站支持上传图片的ZIP压缩包，然后生成一张大图片，已经以图片文件名为类名的CSS语句，自动给出每个图片对应的位置。另外还可以设置各个小图片之间的间隔，以适应内容的适度拉伸。</p>
<p>btw，提一下一个APACHE的mod_expires模块，这个模块可以要求服务器缓存制定类型的文件。比如下面的语句(写入.htaccess文件)要求缓存图片, css, js等一个月：</p>
<blockquote><pre><span style="color: #0000ff">&lt;</span><span style="color: #800000">IfModule</span> <span style="color: #ff0000">mod_expires</span>.<span style="color: #ff0000">c</span><span style="color: #0000ff">&gt;</span>
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
ExpiresByType application/x-shockwave-flash A2592000
ExpiresByType text/css A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType text/html A600
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">IfModule</span><span style="color: #0000ff">&gt;</span></pre>
</blockquote>
<p>不过似乎deamhost和bluehost都没有这个模块，但阅微堂所在的CPH服务器是有的...&nbsp; </p>
<div><h4>相关文章</h4><ul><li><a href="http://zhiqiang.org/blog/it/speedup-blog-about-images.html">加速blog：处理页面图片</a></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-about-javascript-css.html">加速blog：关于javascript(css)</a></li><li><a href="http://zhiqiang.org/blog/it/dreamhost-on-gzip-cache.html">Dreamhost上的GZIP &#038; Cache</a></li><li><a href="http://zhiqiang.org/blog/it/innerhtml-2-cd-issue-dynamic-modification-table-function-of-js.html">innerHTML只读问题 &amp; 两个动态修改Table的js函数</a></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-set-browser-cache.html">加速blog：设置浏览器缓存</a></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-cache-on-server.html">加速blog：服务器端的中转和缓存</a></li><li><a href="http://zhiqiang.org/blog/it/using-htaccess-to-speed-blog.html">设置blog的缓存和压缩</a></li></ul></div>    <p></p>
    <hr noshade style="margin:0;height:1px" />
    <p>&copy; zhiqiang for <a href="http://zhiqiang.org/blog">阅微堂</a>, 2007. | <a href="http://zhiqiang.org/blog/it/speedup-website-with-css-sprites.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/it/speedup-website-with-css-sprites.html#comments">17 &#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/it/speedup-website-with-css-sprites.html/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>innerHTML只读问题 &amp; 两个动态修改Table的js函数</title>
		<link>http://zhiqiang.org/blog/it/innerhtml-2-cd-issue-dynamic-modification-table-function-of-js.html</link>
		<comments>http://zhiqiang.org/blog/it/innerhtml-2-cd-issue-dynamic-modification-table-function-of-js.html#comments</comments>
		<pubDate>Wed, 25 Jul 2007 04:06:58 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[IT技术]]></category>
		<category><![CDATA[innerHTML]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[网页技术]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/627.html</guid>
		<description><![CDATA[博客 » IT技术 » 网页技术 » 最近做社会实践项目遇到的一个问题，需要动态修改一个表格。本来以为要想修改一行，直接设置新的 tr.innerHTML即可。后来发现在Firefox下可行，但在IE下通不过，查看了一下帮助，才发现innerHTML还没有一个通用标准，而在IE下innerHTML对于标签为COL, COLGROUP, FRAMESET, HTML, STYLE, TABLE, TBODY, TFOOT, THEAD, TITLE, TR的元素是只读的。要想在IE下动态修改表格，只能...]]></description>
			<content:encoded><![CDATA[<p id="breadcrumb" class="breadcrumb"><a href="http://zhiqiang.org/blog/">博客</a> » <a href="http://zhiqiang.org/blog/category/it">IT技术</a> » <a href='http://zhiqiang.org/blog/tag/%e7%bd%91%e9%a1%b5%e6%8a%80%e6%9c%af'>网页技术</a>  » </p><p>最近做社会实践项目遇到的一个问题，需要动态修改一个表格。本来以为要想修改一行，直接设置新的 tr.innerHTML即可。后来发现在Firefox下可行，但在IE下通不过，查看了一下帮助，才发现innerHTML还没有一个通用标准，而在IE下<strong>innerHTML</strong>对于标签为COL, COLGROUP, FRAMESET, HTML, STYLE, TABLE, TBODY, TFOOT, THEAD, TITLE, TR的元素是<strong>只读</strong>的。要想在IE下动态修改表格，只能使用insertRow和insertCell;</p>
<p>下面这个函数往表格<strong>i</strong>里添加一行，此行的HTML代码为<strong>t。</strong></p>
<blockquote><pre><span style="color: #008000">// insert a row with HTML code t to table i; </span>
<span style="color: #008000">// t: the full HTML code of the row</span>
<span style="color: #008000">// i : the table element</span>
<span style="color: #008000">// Return the row added</span>
<span style="color: #0000ff">function</span> addRow(t, i) {
	<span style="color: #0000ff">if</span> (<span style="color: #0000ff">typeof</span>(i) == "<span style="color: #8b0000">string</span>")	i = <span style="color: #0000ff">document</span>.getElementById(i);

	<span style="color: #0000ff">var</span> f = t.indexOf('&gt;'), l = t.lastIndexOf('&lt;/'),
		tag = t.substr(l+2, t.<span style="color: #0000ff">length</span>-l-3), e;

	<span style="color: #0000ff">if</span> (tag == 'tr') e = i.insertRow(-1);
	<span style="color: #0000ff">else</span> {
		e = <span style="color: #0000ff">document</span>.createElement(tag);
		i.appendChild(e, i);
		e.innerHTML = t.substr(f+1, l-f-1);
	}

	s = t.substr(1, f-1).split(' ');
	<span style="color: #0000ff">for</span> (i=0; i&lt;s.<span style="color: #0000ff">length</span>; i++) {
		ss = s[i].split('=');
		<span style="color: #0000ff">if</span> (ss.<span style="color: #0000ff">length</span>==1) <span style="color: #0000ff">continue</span>;
		e.setAttribute(ss[0], strip(ss[1]));
	}

	ti = t.substr(f+1, l-f-1);
	<span style="color: #0000ff">if</span> (t.substr(l+2, t.<span style="color: #0000ff">length</span>-l-3) == 'tr') {
		<span style="color: #0000ff">var</span> tf;
		<span style="color: #0000ff">while</span>( (tf = ti.indexOf("<span style="color: #8b0000">&lt;td&gt;</span>")) != -1) {
			ti = ti.substr(tf+4, ti.<span style="color: #0000ff">length</span>-tf-4);
			<span style="color: #0000ff">var</span> te = e.insertCell(-1);
			tl = ti.indexOf("<span style="color: #8b0000">&lt;/td&gt;</span>");
			te.innerHTML = ti.substr(0, tl);
			ti = ti.substr(tl, ti.<span style="color: #0000ff">length</span>-tl);
		}
	} 

	<span style="color: #0000ff">return</span> e;

	<span style="color: #0000ff">function</span> strip(ss) {
		<span style="color: #0000ff">if</span> (ss[0]=='\''|| ss[0] == "<span style="color: #8b0000">\"</span>")
			<span style="color: #0000ff">return</span> ss.substr(1, ss.<span style="color: #0000ff">length</span>-2);
	}
}</pre>
</blockquote>
<p>下面这个函数将表格的<strong>i</strong>行改写为代码<strong>t：</strong> </p>
<blockquote><pre><span style="color: #008000">// modify row i with row of HTML code t</span>
<span style="color: #008000">// t: HTML code </span>
<span style="color: #008000">// i: the row element, get by table.rows[row_index]</span>
<span style="color: #008000">// return the row modified</span>
<span style="color: #0000ff">function</span> modifyRow(t, i) {
	<span style="color: #0000ff">var</span> f = t.indexOf('&gt;'), l = t.lastIndexOf('&lt;/'),
		tag = t.substr(l+2, t.<span style="color: #0000ff">length</span>-l-3), e;

	<span style="color: #0000ff">if</span> (tag == 'tr') e = i;
	<span style="color: #0000ff">else</span> {
		e = <span style="color: #0000ff">document</span>.createElement(tag);
		i.appendChild(e, i);
		e.innerHTML = t.substr(f+1, l-f-1);
	}

	s = t.substr(1, f-1).split(' ');
	<span style="color: #0000ff">for</span> (i=0; i&lt;s.<span style="color: #0000ff">length</span>; i++) {
		ss = s[i].split('=');
		<span style="color: #0000ff">if</span> (ss.<span style="color: #0000ff">length</span>==1) <span style="color: #0000ff">continue</span>;
		e.setAttribute(ss[0], strip(ss[1]));
	}

	<span style="color: #0000ff">var</span> ti = t.substr(f+1, l-f-1), ri = 0;
	<span style="color: #0000ff">if</span> (t.substr(l+2, t.<span style="color: #0000ff">length</span>-l-3) == 'tr') {
		<span style="color: #0000ff">var</span> tf;
		<span style="color: #0000ff">while</span> ( (tf = ti.indexOf("<span style="color: #8b0000">&lt;td&gt;</span>")) != -1 ) {
			ti = ti.substr(tf+4, ti.<span style="color: #0000ff">length</span>-tf-4);
			<span style="color: #0000ff">var</span> te;
			<span style="color: #0000ff">if</span> (e.cells.<span style="color: #0000ff">length</span> &lt;= ri)	te = e.insertCell(-1);
			<span style="color: #0000ff">else</span> te = e.cells[ri];
			ri++;
			tl = ti.indexOf("<span style="color: #8b0000">&lt;/td&gt;</span>");
			te.innerHTML = ti.substr(0, tl);
			ti = ti.substr(tl, ti.<span style="color: #0000ff">length</span>-tl);
		}
	} 

	<span style="color: #0000ff">return</span> e;

	<span style="color: #0000ff">function</span> strip(ss) {
		<span style="color: #0000ff">if</span> (ss[0]=='\''|| ss[0] == "<span style="color: #8b0000">\"</span>")
			<span style="color: #0000ff">return</span> ss.substr(1, ss.<span style="color: #0000ff">length</span>-2);
	}
}</pre>
</blockquote>
<p>[tags]javascript, innerHTML, table[/tags]</p>
<div><h4>相关文章</h4><ul><li><a href="http://zhiqiang.org/blog/it/dreamhost-on-gzip-cache.html">Dreamhost上的GZIP &#038; Cache</a></li><li><a href="http://zhiqiang.org/blog/it/speedup-website-with-css-sprites.html">用CSS Sprites让网站再加速</a></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-about-javascript-css.html">加速blog：关于javascript(css)</a></li><li><a href="http://zhiqiang.org/blog/it/speedup-blog-about-images.html">加速blog：处理页面图片</a></li></ul></div>    <p></p>
    <hr noshade style="margin:0;height:1px" />
    <p>&copy; zhiqiang for <a href="http://zhiqiang.org/blog">阅微堂</a>, 2007. | <a href="http://zhiqiang.org/blog/it/innerhtml-2-cd-issue-dynamic-modification-table-function-of-js.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/it/innerhtml-2-cd-issue-dynamic-modification-table-function-of-js.html#comments">3 &#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/it/innerhtml-2-cd-issue-dynamic-modification-table-function-of-js.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

