<?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>94smart&#039;s Blog &#187; 内容管理系统</title>
	<atom:link href="http://blog.94smart.com/tags/%e5%86%85%e5%ae%b9%e7%ae%a1%e7%90%86%e7%b3%bb%e7%bb%9f/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.94smart.com</link>
	<description>移动或移不动的互联网</description>
	<lastBuildDate>Sat, 11 Feb 2012 02:48:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>小试Prototype：为静态文章列表加上标志</title>
		<link>http://blog.94smart.com/cache/2006/0726_826.html</link>
		<comments>http://blog.94smart.com/cache/2006/0726_826.html#comments</comments>
		<pubDate>Wed, 26 Jul 2006 06:49:59 +0000</pubDate>
		<dc:creator>94smart</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[内容管理系统]]></category>
		<category><![CDATA[随笔]]></category>
		<category><![CDATA[IM]]></category>

		<guid isPermaLink="false">http://blog.94smart.com/2006/07/26/826.html</guid>
		<description><![CDATA[昨天，用Prototype.js解决了一个以前一直解决不了的问题，即静态文章列表加上New标志。 工作上一直使用静态的CMS（内容发布系统），好处是发布的内容全部都有静态页面、唯一地址，访问速度也比较稳定，缺点是放弃了动态的效果，比如文章动态链接、列表更新等等，以及今天要说的根据文章发布时间给标题加New标志。 原理是用Javascript分析列表代码里面带有时间的条目，时间是不是在时间限制之后，如果是，就在这个条目的时间代码段前面加上New的标志代码。 首先对文章列表进行改造，发布系统生成&#60;ul&#62;，每篇文章都是一个&#60;li&#62;，每个&#60;li&#62;里面用&#60;a&#62;包含标题，用&#60;samp&#62;来包含发布时间（还可以选择&#60;span&#62;或其他标签，我特意选了不常用的&#60;samp&#62;），最外层用&#60;div&#62;包含（看具体使用来定，也可以使用&#60;table&#62;等），并增加ID属性。以下是列表的代码： &#60;div id="News"&#62;&#60;ul&#62;&#60;li&#62;&#60;a href="link" target="_blank"&#62;Title&#60;/a&#62;&#60;samp&#62;2006-07-26 10:20&#60;/samp&#62;&#60;/li&#62;&#60;li&#62;&#60;a href="link" target="_blank"&#62;Title&#60;/a&#62;&#60;samp&#62;2006-07-25 10:20&#60;/samp&#62;&#60;/li&#62;&#60;li&#62;&#60;a href="link" target="_blank"&#62;Title&#60;/a&#62;&#60;samp&#62;2006-07-25 10:20&#60;/samp&#62;&#60;/li&#62;&#60;li&#62;&#60;a href="link" target="_blank"&#62;Title&#60;/a&#62;&#60;samp&#62;2006-07-24 10:20&#60;/samp&#62;&#60;/li&#62;&#60;li&#62;&#60;a href="link" target="_blank"&#62;Title&#60;/a&#62;&#60;samp&#62;2006-07-23 10:20&#60;/samp&#62;&#60;/li&#62;&#60;/ul&#62;&#60;/div&#62; Javascript脚本部分，我设定的时间限制是前天0点，也就是说前天发的内容都会加上New的标志。shownew.js代码如下： //shownew.js//email: 94smart(AT)gmail.com//url: http://blog.94smart.com var TheDay = new Date(); //初始化时间TheDay.setDate(TheDay.getDate()-2); //将时间设定为前天，看实际需要而定TheDay.setHours(0,0,0); //将时间设定为前天0点var newImage = '&#60;img src="images/icon_new.gif" border="0" alt="New" /&#62;'; //New字样图片的代码 function showNew(listId){ //参数listId是要处理列表的IDvar thisList = $(listId).getElementsByTagName('li');var listArray = $A(thisList);listArray.each(function(listItem){theSamp = listItem.getElementsByTagName('samp'); //取li里面的samp标签的内容theSamp = theSamp[0];theTime [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="用XHTML+CSS实现文章列表标题时间对齐" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2007%2F0305_1096.html&from=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2006%2F0726_826.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/29/7088198.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;">用XHTML+CSS实现文章列表标题时间对齐</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Prototype1.4.0说明文档showLocalLinks例子有问题" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2006%2F0417_693.html&from=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2006%2F0726_826.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Prototype1.4.0说明文档showLocalLinks例子有问题</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="美味书签和Delicious Soup" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2006%2F0506_716.html&from=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2006%2F0726_826.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/29/7089032.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;">美味书签和Delicious Soup</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="比较郁闷的MM_preloadImages问题" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2006%2F0523_738.html&from=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2006%2F0726_826.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">比较郁闷的MM_preloadImages问题</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%2Fblog.94smart.com%2Fcache%2F2006%2F1024_933.html&from=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2006%2F0726_826.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/29/7090071.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">拿什么来拯救你，我的电脑~</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.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>昨天，用Prototype.js解决了一个以前一直解决不了的问题，即静态文章列表加上New标志。</p>
<p>工作上一直使用静态的CMS（内容发布系统），好处是发布的内容全部都有静态页面、唯一地址，访问速度也比较稳定，缺点是放弃了动态的效果，比如文章动态链接、列表更新等等，以及今天要说的根据文章发布时间给标题加New标志。</p>
<p>原理是用Javascript分析列表代码里面带有时间的条目，时间是不是在时间限制之后，如果是，就在这个条目的时间代码段前面加上New的标志代码。</p>
<p>首先对文章列表进行改造，发布系统生成&lt;ul&gt;，每篇文章都是一个&lt;li&gt;，每个&lt;li&gt;里面用&lt;a&gt;包含标题，用&lt;samp&gt;来包含发布时间（还可以选择&lt;span&gt;或其他标签，我特意选了不常用的&lt;samp&gt;），最外层用&lt;div&gt;包含（看具体使用来定，也可以使用&lt;table&gt;等），并增加ID属性。以下是列表的代码：</p>
<blockquote><p><code>&lt;div id="News"&gt;<br />&lt;ul&gt;<br />&lt;li&gt;&lt;a href="link" target="_blank"&gt;Title&lt;/a&gt;&lt;samp&gt;2006-07-26 10:20&lt;/samp&gt;&lt;/li&gt;<br />&lt;li&gt;&lt;a href="link" target="_blank"&gt;Title&lt;/a&gt;&lt;samp&gt;2006-07-25 10:20&lt;/samp&gt;&lt;/li&gt;<br />&lt;li&gt;&lt;a href="link" target="_blank"&gt;Title&lt;/a&gt;&lt;samp&gt;2006-07-25 10:20&lt;/samp&gt;&lt;/li&gt;<br />&lt;li&gt;&lt;a href="link" target="_blank"&gt;Title&lt;/a&gt;&lt;samp&gt;2006-07-24 10:20&lt;/samp&gt;&lt;/li&gt;<br />&lt;li&gt;&lt;a href="link" target="_blank"&gt;Title&lt;/a&gt;&lt;samp&gt;2006-07-23 10:20&lt;/samp&gt;&lt;/li&gt;<br />&lt;/ul&gt;<br />&lt;/div&gt;</code></p></blockquote>
<p>Javascript脚本部分，我设定的时间限制是前天0点，也就是说前天发的内容都会加上New的标志。shownew.js代码如下：</p>
<blockquote>
<p><code>//shownew.js<br /><a>//email: 94smart(AT)gmail.com</a><br />//url: <a href="http://blog.94smart.com" rel="nofollow">http://blog.94smart.com</a></p>
<p>var TheDay = new Date(); //初始化时间<br />TheDay.setDate(TheDay.getDate()-2); //将时间设定为前天，看实际需要而定<br />TheDay.setHours(0,0,0); //将时间设定为前天0点<br />var newImage = '&lt;img src="images/icon_new.gif" border="0" alt="New" /&gt;'; //New字样图片的代码</p>
<p>function showNew(listId){ //参数listId是要处理列表的ID<br />var thisList = $(listId).getElementsByTagName('li');<br />var listArray = $A(thisList);<br />listArray.each(function(listItem){<br />theSamp = listItem.getElementsByTagName('samp'); //取li里面的samp标签的内容<br />theSamp = theSamp[0];<br />theTime = theSamp.innerHTML; //得到文章的发布时间<br />theTime = new Date(theTime.replace(/\-/g, "/")); //替换时间格式为yyyy/mm/dd h:m:s，如果正好是Javascript的时间格式就不需要这行<br />if (theTime&gt;=TheDay) {<br />new Insertion.Before(theSamp, newImage); //如果发布时间比设定的时限晚就在samp标签前面插入New图片代码<br />}<br />});<br />}</code></p>
</blockquote>
<p>使用的时候在<code>&lt;head&gt;</code>区插入代码：<code>&lt;script src="prototype.js" type="text/javascript"&gt;&lt;/script&gt;</code>和<br /><code>&lt;script src="shownew.js" type="text/javascript"&gt;&lt;/script&gt;，</code>在列表的HTML代码下方加入：<code>&lt;script type="text/javascript"&gt;showNew('News');&lt;/script&gt;</code>，ok，刷新你的页面，看到New了吗？<a href="http:///blog.94smart.com/html/list_show_new.html">没有的话看这里</a>。</p>
<p>上面的代码还可以再挖掘一下，这里就不继续了，希望我的代码对其他人有所帮助。</p>
<p>需要说明的是，用的Prototype是Prototype v1.4.0，别的版本没试，应该也可以。Prototype库真的很强大，尤其是对于我这样的懒人，懒得自己写底层的业余JS人员。</p>
<p>  Technorati : <a href="http://technorati.com/tag/Javascript" rel="tag">Javascript</a>, <a href="http://technorati.com/tag/Prototype" rel="tag">Prototype</a>, <a href="http://technorati.com/tag/XHTML" rel="tag">XHTML</a></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="用XHTML+CSS实现文章列表标题时间对齐" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2007%2F0305_1096.html&from=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2006%2F0726_826.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/29/7088198.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;">用XHTML+CSS实现文章列表标题时间对齐</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Prototype1.4.0说明文档showLocalLinks例子有问题" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2006%2F0417_693.html&from=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2006%2F0726_826.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Prototype1.4.0说明文档showLocalLinks例子有问题</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="美味书签和Delicious Soup" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2006%2F0506_716.html&from=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2006%2F0726_826.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/29/7089032.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;">美味书签和Delicious Soup</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="比较郁闷的MM_preloadImages问题" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2006%2F0523_738.html&from=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2006%2F0726_826.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">比较郁闷的MM_preloadImages问题</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%2Fblog.94smart.com%2Fcache%2F2006%2F1024_933.html&from=http%3A%2F%2Fblog.94smart.com%2Fcache%2F2006%2F0726_826.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/29/7090071.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">拿什么来拯救你，我的电脑~</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.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://blog.94smart.com/cache/2006/0726_826.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

