<?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>SLJ.me - 申力军 &#187; Javascript</title>
	<atom:link href="http://slj.me/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://slj.me</link>
	<description>申力军的博客</description>
	<lastBuildDate>Mon, 05 Dec 2011 05:35:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>JavaScript 操作select控件大全（新增、修改、删除、选中、清空、判断存在等）</title>
		<link>http://slj.me/2010/12/javascript-select-operations/</link>
		<comments>http://slj.me/2010/12/javascript-select-operations/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 02:38:21 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[select]]></category>

		<guid isPermaLink="false">http://slj.me/?p=2124</guid>
		<description><![CDATA[转载一篇，这个有的时候还是很有用的，所以收藏一下 1、判断select选项中 是否存在Value=&#8221;paraValue&#8221;的Item 2、向select选项中 加入一个Item 3、从select选项中 删除一个Item 4、删除select中选中的项 5、修改select选项中 value=&#8221;paraValue&#8221;的text为&#8221;paraText&#8221; 6、设置select中text=&#8221;paraText&#8221;的第一个Item为选中 7、设置select中value=&#8221;paraValue&#8221;的Item为选中 8、得到select的当前选中项的value 9、得到select的当前选中项的text 10、得到select的当前选中项的Index 11、清空select的项 //js 代码 // 1.判断select选项中 是否存在Value="paraValue"的Item function jsSelectIsExitItem(objSelect, objItemValue) { var isExit = false; for (var i = 0; i < objSelect.options.length; i++) { if (objSelect.options[i].value == objItemValue) { isExit = true; break; } } return isExit; } // 2.向select选项中 加入一个Item function jsAddItemToSelect(objSelect, objItemText, [...]]]></description>
			<content:encoded><![CDATA[<p>转载一篇，这个有的时候还是很有用的，所以收藏一下</p>
<p>1、判断select选项中 是否存在Value=&#8221;paraValue&#8221;的Item<br />
2、向select选项中 加入一个Item<br />
3、从select选项中 删除一个Item<br />
4、删除select中选中的项<br />
5、修改select选项中 value=&#8221;paraValue&#8221;的text为&#8221;paraText&#8221;<br />
6、设置select中text=&#8221;paraText&#8221;的第一个Item为选中<br />
7、设置select中value=&#8221;paraValue&#8221;的Item为选中<br />
8、得到select的当前选中项的value<br />
9、得到select的当前选中项的text<br />
10、得到select的当前选中项的Index<br />
11、清空select的项</p>
<p><span id="more-2124"></span></p>
<pre class="js" name="code">
//js 代码
// 1.判断select选项中 是否存在Value="paraValue"的Item
function jsSelectIsExitItem(objSelect, objItemValue) {
    var isExit = false;
    for (var i = 0; i < objSelect.options.length; i++) {
        if (objSelect.options[i].value == objItemValue) {
            isExit = true;
            break;
        }
    }
    return isExit;
}         

// 2.向select选项中 加入一个Item
function jsAddItemToSelect(objSelect, objItemText, objItemValue) {
    //判断是否存在
    if (jsSelectIsExitItem(objSelect, objItemValue)) {
        alert("该Item的Value值已经存在");
    } else {
        var varItem = new Option(objItemText, objItemValue);
        objSelect.options.add(varItem);
        alert("成功加入");
    }
}        

// 3.从select选项中 删除一个Item
function jsRemoveItemFromSelect(objSelect, objItemValue) {
    //判断是否存在
    if (jsSelectIsExitItem(objSelect, objItemValue)) {
        for (var i = 0; i < objSelect.options.length; i++) {
            if (objSelect.options[i].value == objItemValue) {
                objSelect.options.remove(i);
                break;
            }
        }
        alert("成功删除");
    } else {
        alert("该select中 不存在该项");
    }
}    

// 4.删除select中选中的项
function jsRemoveSelectedItemFromSelect(objSelect) {
    var length = objSelect.options.length - 1;
    for(var i = length; i >= 0; i--){
        if(objSelect[i].selected == true){
            objSelect.options[i] = null;
        }
    }
}      

// 5.修改select选项中 value="paraValue"的text为"paraText"
function jsUpdateItemToSelect(objSelect, objItemText, objItemValue) {
    //判断是否存在
    if (jsSelectIsExitItem(objSelect, objItemValue)) {
        for (var i = 0; i < objSelect.options.length; i++) {
            if (objSelect.options[i].value == objItemValue) {
                objSelect.options[i].text = objItemText;
                break;
            }
        }
        alert("成功修改");
    } else {
        alert("该select中 不存在该项");
    }
}        

// 6.设置select中text="paraText"的第一个Item为选中
function jsSelectItemByValue(objSelect, objItemText) {
    //判断是否存在
    var isExit = false;
    for (var i = 0; i < objSelect.options.length; i++) {
        if (objSelect.options[i].text == objItemText) {
            objSelect.options[i].selected = true;
            isExit = true;
            break;
        }
    }
    //Show出结果
    if (isExit) {
        alert("成功选中");
    } else {
        alert("该select中 不存在该项");
    }
}        

// 7.设置select中value="paraValue"的Item为选中
document.all.objSelect.value = objItemValue;    

// 8.得到select的当前选中项的value
var currSelectValue = document.all.objSelect.value;    

// 9.得到select的当前选中项的text
var currSelectText = document.all.objSelect.options[document.all.objSelect.selectedIndex].text;    

// 10.得到select的当前选中项的Index
var currSelectIndex = document.all.objSelect.selectedIndex;    

// 11.清空select的项
document.all.objSelect.options.length = 0;
</pre>
</pre>
<h2  class="related_post_title">Related Posts / 相关文章</h2><ul class="related_post"><li><a href="http://slj.me/2010/04/mysql-group-by-having/" title="MySQL: group by &#8230; having &#8230;">MySQL: group by &#8230; having &#8230;</a></li><li><a href="http://slj.me/2010/03/45-fresh-useful-javascript-and-jquery-techniques-and-tools/" title="[英,转]45个新鲜有用的JS与jQuery技术和工具">[英,转]45个新鲜有用的JS与jQuery技术和工具</a></li><li><a href="http://slj.me/2010/03/building-iphone-apps-with-html-css-and-javascript/" title="【好书PDF】：Building iPhone Apps with HTML, CSS, and JavaScript">【好书PDF】：Building iPhone Apps with HTML, CSS, and JavaScript</a></li><li><a href="http://slj.me/2010/01/js%e8%8e%b7%e5%8f%96%e6%b5%8f%e8%a7%88%e5%99%a8%e7%aa%97%e5%8f%a3%e5%a4%a7%e5%b0%8f-%e8%8e%b7%e5%8f%96%e5%b1%8f%e5%b9%95%ef%bc%8c%e6%b5%8f%e8%a7%88%e5%99%a8%ef%bc%8c%e7%bd%91%e9%a1%b5%e9%ab%98/" title="JS获取浏览器窗口大小 获取屏幕，浏览器，网页高度宽度 ">JS获取浏览器窗口大小 获取屏幕，浏览器，网页高度宽度 </a></li><li><a href="http://slj.me/2009/07/javascript-pic-reflection-glossy-effect/" title="Javascript 实现图像倒影、发光效果">Javascript 实现图像倒影、发光效果</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2010/12/javascript-select-operations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>20个jQuery新效果</title>
		<link>http://slj.me/2010/10/20-jquery-new-effects/</link>
		<comments>http://slj.me/2010/10/20-jquery-new-effects/#comments</comments>
		<pubDate>Thu, 28 Oct 2010 16:18:50 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[effect]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://slj.me/?p=2055</guid>
		<description><![CDATA[本文将介绍20个最新的jQuery效果，还有值得一提的是8月份jQuery 发布移动设备版本 jQuery Mobile。 1. Custom Animation Banner with jQuery 通过使用 jQuery Easing和jQuery 2D Transform插件，创建自定义animation banner。 View Demo（查看示例） 2. 快速反馈表 – jQuery &#38; PHP Martin Angelov 将教你如何快速的创建用于接收来自用户反馈的解决方案，使用到了jQuery, PHP 和 PHPMailer类。 View Demo（查看示例） 3. Wijmo – jQuery UI 组件 Wijmo是一个jQuery UI组件集，有超过30多个jQuery UI 组件；这将是一个CSS3，SVG，HTML5的混合物，目前还处于Beta阶段。 View Demo（查看示例） 4. 页面导航 – jQuery插件 这是一个页面上的导航插件，基于jQuery ScrollTo 插件，你可以在 Github上查看更多介绍。 View Demo（查看示例） 5. [...]]]></description>
			<content:encoded><![CDATA[<p><img height="232" width="595" alt="" src="http://slj.me/wp-content/uploads/2010/10/20_new_jquery_effects_post_thumb.png" class="thumb"/></p>
<p>本文将介绍20个最新的jQuery效果，还有值得一提的是8月份<a rel="external" href="http://www.javaeye.com/news/17316">jQuery 发布移动设备版本 jQuery Mobile</a>。</p>
<p><span id="more-2055"></span><br />
1. <a href="http://tympanus.net/codrops/2010/10/18/custom-animation-banner/" target="_blank">Custom Animation Banner with jQuery</a></p>
<blockquote><p>通过使用 <a href="http://gsgd.co.uk/sandbox/jquery/easing/" target="_blank">jQuery Easing</a>和j<a href="http://plugins.jquery.com/project/2d-transform" target="_blank">Query 2D Transform</a>插件，创建自定义animation banner。</p>
<p><a href="http://tympanus.net/Tutorials/CustomAnimationBanner/" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>2. <a href="http://tutorialzine.com/2010/09/quick-feedback-form-php-jquery/" target="_blank">快速反馈表 – jQuery &amp; PHP</a></p>
<blockquote><p><a href="http://twitter.com/tutorialzine" target="_blank">Martin Angelov</a> 将教你如何快速的创建用于接收来自用户反馈的解决方案，使用到了jQuery, PHP 和 PHPMailer类。</p>
<p><a href="http://twitter.com/tutorialzine" target="_blank"></a><a href="http://demo.tutorialzine.com/2010/09/quick-feedback-form-php-jquery/feedback.html" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>3. <a href="http://wijmo.com/" target="_blank">Wijmo – jQuery UI 组件</a></p>
<blockquote><p>Wijmo是一个jQuery UI组件集，有超过30多个jQuery UI 组件；这将是一个CSS3，SVG，HTML5的混合物，目前还处于Beta阶段。</p>
<p><a href="http://wijmo.com/Wijmo-Open/samples/index.html" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>4. <a href="http://trevordavis.net/blog/jquery-one-page-navigation-plugin/" target="_blank">页面导航 – jQuery插件</a></p>
<p><a href="http://trevordavis.net/blog/jquery-one-page-navigation-plugin/" target="_blank"> </a></p>
<blockquote><p>这是一个页面上的导航插件，基于<a href="http://flesler.blogspot.com/2007/10/jqueryscrollto.html" target="_blank">jQuery ScrollTo </a>插件，你可以在 <a href="http://github.com/davist11/jQuery-One-Page-Nav" target="_blank">Github</a>上查看更多介绍。</p>
<p><a href="http://trevordavis.net/play/jquery-one-page-nav/" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>5. <a href="http://net.tutsplus.com/tutorials/javascript-ajax/how-to-build-an-rss-reader-with-jquery-mobile-2/" target="_blank">RSS Reader With jQuery Mobile</a></p>
<blockquote><p><a href="http://www.twitter.com/nettuts" target="_blank">Jeffrey Way</a> 创建了一个简单的RSS reader，主要用于iphone和Andriod手机，通过PHP和jQuery mobile 实现。</p>
<p><a href="http://demo.jeffrey-way.com/tutsMobile/" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>6. <a href="http://www.madeincima.eu/blog/jquery-plugin-easy-accordion/" target="_blank">Easy Accordion – jQuery插件</a></p>
<blockquote><p>The Easy Accordion插件可以生成一个类似手风琴样子的自定义列表。</p>
<p><a href="http://www.madeincima.eu/samples/jquery/easyAccordion/" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>7. <a href="http://github.com/davatron5000/Lettering.js" target="_blank">Lettering – jQuery Typography Plugin</a></p>
<blockquote><p>Lettering是一个轻量级易于使用的网页排版插件，例如印刷CSS3的海报，自定义类型的标题等。</p>
<p><a href="http://daverupert.com/2010/09/lettering-js/" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>8. <a href="http://tympanus.net/codrops/2010/10/12/annotation-overlay-effect/" target="_blank">Annotation Overlay Effect with jQuery</a></p>
<blockquote><p>创建一个简单的叠加效应</p>
<p><a href="http://tympanus.net/Tutorials/AnnotationOverlayEffect/" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>9. <a href="http://www.steamdev.com/snippet/" target="_blank">Snippet – jQuery Syntax Highlighter</a></p>
<blockquote><p>Snippet是一个很酷的jQuery语法高亮插件，基于SHJS脚本，你可以在SourceForge上找到源码。</p>
<p><a href="http://www.steamdev.com/snippet/" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>10. <a href="http://tutorialzine.com/2010/09/google-powered-site-search-ajax-jquery/" target="_blank">Google Powered Site Search With jQuery</a></p>
<blockquote><p>教你如何创建一个自定义的搜索引擎，只需要使用Google AJAX Search API，你可以搜索到您网站上的图片，视频和新闻等……</p>
<p><a href="http://demo.tutorialzine.com/2010/09/google-powered-site-search-ajax-jquery/search.html" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>11. <a href="http://www.sohtanaka.com/web-design/simple-tooltip-w-jquery-css/" target="_blank">简单的工具提示 – jQuery &amp; CSS</a></p>
<blockquote><p><a href="http://twitter.com/sohtanaka" target="_blank">Soh Tanaka</a> 创建一个简单的jQuery和CSS样式提示</p>
<p><a href="http://www.sohtanaka.com/web-design/examples/element-tooltip/" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>12. <a href="http://tympanus.net/codrops/2010/10/03/compact-news-previewer/" target="_blank">Compact News Previewer with jQuery</a></p>
<blockquote><p>创建一个文章/新闻预览，以经凑的方式显示您最想的文章或新闻。预览工具将会显示一些关于文章更长的描述。</p>
<p><a href="http://tympanus.net/Tutorials/CompactNewsPreviewer/" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>13. <a href="http://exposureforjquery.wordpress.com/download/" target="_blank">Exposure jQuery插件</a></p>
<blockquote><p>Exposure是一个图片预览插件，用于创建丰富，自定义的视觉体验。</p>
<p><a href="http://exposure.blogocracy.org/demos/demo1.html?v=0.5" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>14. <a href="http://tutorialzine.com/2010/09/giveaway-randomizer-app-jquery/" target="_blank">Giveaway Randomizer App – jQuery</a></p>
<blockquote><p>它会教你如何去创建一个jQuery专用的随机数发生器。</p>
<p><a href="http://demo.tutorialzine.com/2010/09/giveaway-randomizer-app-jquery/randomizer.html" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>15. <a href="http://www.webdesign-bulgaria.com/opensource/jquery-smooth-fading-tabs-plugin.php" target="_blank">jQuery Smooth Tabs Plugin</a></p>
<blockquote><p>jQuery Smooth Tabs是一个简单易于使用的插件，可以让你选择一些漂亮的效果来显示你的文字内容，带来更好的用户体验。</p>
<p><a href="http://www.webdesign-bulgaria.com/opensource/jquery-smooth-fading-tabs-demo.php" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>16. <a href="http://www.tn34.de/projekte/downloads/jQuery.tn34.timetabs.html" target="_blank">TN34 Timetabs – jQuery Plugin</a></p>
<blockquote><p>Mario Alves创建的一个tab容器的jQuery插件，可以选定不一样的样式来显示下一个tab。下载插件：<a href="http://plugins.jquery.com/project/tn34-timetabs" target="_blank">HERE</a>.</p>
<p><a href="http://demo.tn34.de/jquery-plugins/timetabs/demo.html" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>17. <a href="http://tympanus.net/codrops/2010/09/08/full-page-image-gallery/" target="_blank">Full Page Image Gallery with jQuery</a></p>
<blockquote><p>创建一个效果惊人的滚动缩略图和滚动全屏预览的画廊。</p>
<p><a href="http://tympanus.net/Tutorials/FullPageImageGallery/" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>18. <a href="http://www.ajaxblender.com/bgstretcher-jquery-stretch-background-plugin.html" target="_blank">bgStretcher – jQuery Plugin</a></p>
<blockquote><p>Background Stretcher可以让你在背景中添加一个或多个大尺寸的图片，并调整他们的大小来填满整个页面，多张图片时会以幻灯片的形式出现。</p>
<p><a href="http://www.ajaxblender.com/script-sources/bgstretcher/demo/index.html" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>19. <a href="http://slidenote.info/" target="_blank">SlideNote – jQuery插件（滑动通</a><a href="http://slidenote.info/" target="_blank">知</a><a href="http://slidenote.info/" target="_blank">）</a></p>
<blockquote><p><a href="http://slidenote.info/" target="_blank"></a>SlideNote 是一个自定义，扩展性很强的jQuery插件，可以轻松的在网页或你的web应用上创建滑动通知。</p>
<p><a href="http://slidenote.info/" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<p>20. <a href="http://www.madeincima.eu/blog/jquery-plugin-easy-list-splitter/" target="_blank">Easy List Splitter – jQuery插件</a></p>
<blockquote><p>Easy List Splitter插件将获取到的list和wrap装入一个container div，生成相应的列表项，并且生成一个有效的HTML代码。</p>
<p><a href="http://www.madeincima.eu/samples/jquery/easyListSplitter/" target="_blank">View Demo</a>（查看示例）</p></blockquote>
<h2  class="related_post_title">Related Posts / 相关文章</h2><ul class="related_post"><li><a href="http://slj.me/2010/03/45-fresh-useful-javascript-and-jquery-techniques-and-tools/" title="[英,转]45个新鲜有用的JS与jQuery技术和工具">[英,转]45个新鲜有用的JS与jQuery技术和工具</a></li><li><a href="http://slj.me/2010/01/10%e4%b8%aajquery-lightbox%e6%95%88%e6%9e%9c%e6%8f%92%e4%bb%b6/" title="10个jQuery Lightbox效果插件">10个jQuery Lightbox效果插件</a></li><li><a href="http://slj.me/2009/12/lazyload/" title="LazyLoad &#8211; jQuery延迟载入插件">LazyLoad &#8211; jQuery延迟载入插件</a></li><li><a href="http://slj.me/2009/12/20-more-beautiful-interactive-website-design-using-jquery/" title="20多个漂亮的使用jQuery交互的网站设计欣赏">20多个漂亮的使用jQuery交互的网站设计欣赏</a></li><li><a href="http://slj.me/2009/12/the-best-jquery-plugins-of-2009/" title="2009 年度最佳 jQuery 插件">2009 年度最佳 jQuery 插件</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2010/10/20-jquery-new-effects/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>关于几种文本替换技术－CSS3, sIFR, Typeface.js, cufon</title>
		<link>http://slj.me/2010/07/font-replacement-css3-sifr-typeface-js-cufon/</link>
		<comments>http://slj.me/2010/07/font-replacement-css3-sifr-typeface-js-cufon/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 08:53:39 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[cufon]]></category>
		<category><![CDATA[font replacement]]></category>
		<category><![CDATA[sifr]]></category>
		<category><![CDATA[Typeface]]></category>

		<guid isPermaLink="false">http://slj.me/?p=1936</guid>
		<description><![CDATA[在现今的开发中，客户对页面中字体的显示效果越来越重视，尤其是标题文字。以往采用的方法是使用静态图片，但因为图片中文字不是动态的，采用一种新的方式尤为重要，下面是4种文字替代技术。 方案一：@font-face (CSS3样式) CSS3的@font-face属性（事实上CSS2中就已引入），为我们带来了一些希望，而Firefox 3.5新增的对@font-face的支持，让我们离这个希望更进了一些。 到现在为止，已经有Safari、Chrome、Opera 10和Firefox 3.5支持@font-face了，比较意外的是，IE系列浏览器也部分支持该属性。Mozilla旗下的其它产品，SeaMonkey 2 和Thunderbird 3 也支持该属性。 浏览器 最低版本 支持字体 Internet Explorer 4.0 只支持OpenType字体(eof格式) Firefox (Gecko) 3.5 (1.9.1) TrueType(ttf格式)和OpenType 字体 Opera 10.0 TrueType和OpenType 字体 Safari (WebKit) 3.1 (525) TrueType和OpenType 字体 从表中可以看出，IE系浏览器不支持TTF格式的字体，只支持eof格式，不过，微软官方发布了一个WEFT工具，可以将TTF转化为EOF，需要的朋友可以去下载使用。 可以使用的样式如下： @font-face　{ font-family: MyHelvetica; src: local("Helvetica Neue Bold"), local("HelveticaNeue-Bold"), url(MgOpenModernaBold.ttf); font-weight: bold; font-style:　normal; } .fontFace{ font-family: MyHelvetica; src: local("Helvetica [...]]]></description>
			<content:encoded><![CDATA[<p><img height="260" width="595" alt="" src="http://slj.me/wp-content/uploads/2010/07/font_replacement_post_thumb.png" class="thumb"/><br />
在现今的开发中，客户对页面中字体的显示效果越来越重视，尤其是标题文字。以往采用的方法是使用静态图片，但因为图片中文字不是动态的，采用一种新的方式尤为重要，下面是4种文字替代技术。</p>
<p><span id="more-1936"></span></p>
<h3>方案一：@font-face (CSS3样式)</h3>
<p>CSS3的@font-face属性（事实上CSS2中就已引入），为我们带来了一些希望，而Firefox 3.5新增的对@font-face的支持，让我们离这个希望更进了一些。</p>
<p>到现在为止，已经有Safari、Chrome、Opera 10和<a rel="external nofollow" href="https://developer.mozilla.org/index.php?title=En/CSS/%40font-face">Firefox 3.5支持@font-face</a>了，比较意外的是，IE系列浏览器也部分支持该属性。Mozilla旗下的其它产品，SeaMonkey 2 和Thunderbird 3 也支持该属性。<span id="more-1092"> </span></p>
<table style="height: 109px;" width="441">
<tbody>
<tr>
<td>浏览器</td>
<td>最低版本</td>
<td>支持字体</td>
</tr>
<tr>
<td>Internet Explorer</td>
<td>4.0</td>
<td>只支持OpenType字体(eof格式)</td>
</tr>
<tr>
<td>Firefox (Gecko)</td>
<td>3.5 (1.9.1)</td>
<td>TrueType(ttf格式)和OpenType 字体</td>
</tr>
<tr>
<td>Opera</td>
<td>10.0</td>
<td>TrueType和OpenType 字体</td>
</tr>
<tr>
<td>Safari (WebKit)</td>
<td>3.1 (525)</td>
<td>TrueType和OpenType 字体</td>
</tr>
</tbody>
</table>
<p>从表中可以看出，IE系浏览器不支持TTF格式的字体，只支持eof格式，不过，微软官方发布了一个WEFT工具，可以将TTF转化为EOF，需要的朋友可以去下载使用。</p>
<p>可以使用的样式如下：</p>
<div class="wp_syntax">
<table>
<tbody>
<tr>
<td class="line_numbers"></td>
<td class="code">
<pre class="css" style="font-family: monospace;"><span style="color: #a1a100;">@font-face　{</span>
  <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00aa00;">:</span> MyHelvetica<span style="color: #00aa00;">;</span>
  src<span style="color: #00aa00;">:</span> local<span style="color: #00aa00;">(</span><span style="color: #ff0000;">"Helvetica Neue Bold"</span><span style="color: #00aa00;">)</span><span style="color: #00aa00;">,</span>
  local<span style="color: #00aa00;">(</span><span style="color: #ff0000;">"HelveticaNeue-Bold"</span><span style="color: #00aa00;">)</span><span style="color: #00aa00;">,</span>
  <span style="color: #993333;">url</span><span style="color: #00aa00;">(</span><span style="color: #ff0000; font-style: italic;">MgOpenModernaBold.ttf</span><span style="color: #00aa00;">)</span><span style="color: #00aa00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00aa00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00aa00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-style</span><span style="color: #00aa00;">:</span>　<span style="color: #993333;">normal</span><span style="color: #00aa00;">;</span>
<span style="color: #00aa00;">}</span>
.fontFace<span style="color: #00aa00;">{</span>
  <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00aa00;">:</span> MyHelvetica<span style="color: #00aa00;">;</span>
  src<span style="color: #00aa00;">:</span> local<span style="color: #00aa00;">(</span><span style="color: #ff0000;">"Helvetica Neue Bold"</span><span style="color: #00aa00;">)</span><span style="color: #00aa00;">,</span>
  local<span style="color: #00aa00;">(</span><span style="color: #ff0000;">"HelveticaNeue-Bold"</span><span style="color: #00aa00;">)</span><span style="color: #00aa00;">,</span>
  <span style="color: #993333;">url</span><span style="color: #00aa00;">(</span><span style="color: #ff0000; font-style: italic;">MgOpenModernaBold.ttf</span><span style="color: #00aa00;">)</span><span style="color: #00aa00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00aa00;">:</span>　<span style="color: #933;">3.2em</span><span style="color: #00aa00;">;</span>
  <span style="color: #000000; font-weight: bold;">letter-spacing</span><span style="color: #00aa00;">:</span>　<span style="color: #933;">1px</span><span style="color: #00aa00;">;</span>
  <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00aa00;">:</span>　<span style="color: #993333;">center</span><span style="color: #00aa00;">;</span>
<span style="color: #00aa00;">}</span></pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>IE中的样式如下：</p>
<div class="wp_syntax">
<table>
<tbody>
<tr>
<td class="line_numbers"></td>
<td class="code">
<pre class="css" style="font-family: monospace;"><span style="color: #a1a100;">@font-face　{</span>
　　<span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00aa00;">:</span>　Goudy　Stout<span style="color: #00aa00;">;</span>
　　<span style="color: #000000; font-weight: bold;">font-style</span><span style="color: #00aa00;">:</span>　<span style="color: #993333;">normal</span><span style="color: #00aa00;">;</span>
　　<span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00aa00;">:</span>　<span style="color: #cc66cc;">400</span><span style="color: #00aa00;">;</span>
　　src<span style="color: #00aa00;">:</span>　<span style="color: #993333;">url</span><span style="color: #00aa00;">(</span>GOUDYST0.eot<span style="color: #00aa00;">)</span><span style="color: #00aa00;">;</span>
<span style="color: #00aa00;">}</span></pre>
</td>
</tr>
</tbody>
</table>
</div>
<blockquote><p>相关链接：</p>
<ul>
<li> <a rel="external nofollow" href="https://developer.mozilla.org/index.php?title=En/CSS/%40font-face">https://developer.mozilla.org/index.php?title=En/CSS/%40font-face</a></li>
<li> <a rel="external nofollow" href="http://www.css3.info/preview/web-fonts-with-font-face/">Web fonts with @font-face :http://www.css3.info/preview/web-fonts-with-font-face/</a></li>
</ul>
</blockquote>
<h3>方案二：sIFR (Scalable Inman Flash Replacement)</h3>
<p>sIFR并非一种新技术，而是已经存在并被使用很多年了。sIFR是一种很有用也很好用的文本替换技术，通过Flash+JS+CSS将网络字体嵌入到页面中。</p>
<ul>
<li>sIFR 是一种用Flash替换页面中文本元素的技术。</li>
<li>sIFR利用了Flash的dynamic text和character embedded这个功能实现。</li>
</ul>
<p>关于sIFR的一些事实：</p>
<ul>
<li> sIFR不需要更改(X)HTML代码，所有的工作由Javascript、Flash和CSS来完成；</li>
<li> 如果用户没有安装Flash或者不支持Javascript，那么(X)HTML的文本就会被CSS样式化后显示出来。</li>
<li> sIFR是可缩放的，可以在渲染时更改为用户设置的缺省字体尺寸。</li>
<li> sIFR兼容所有的屏幕阅读机，至今还没有问题被报道出来。</li>
<li> sIFR的文本可以被鼠标选择，尽管当全选文本时，选中的状态看上去不那么确切。</li>
<li> sIFR不影响搜索引擎的定位和评定，不会隐藏真实的文本内容。</li>
</ul>
<p>在链接上使用sIFR</p>
<p>最新版本的sIFR允许链接文本被替换。但可能造成以下的可访问性问题：</p>
<ul>
<li>不支持浏览器的右键点击功能（上下文菜单）</li>
<li>不支持apple的option键</li>
<li>没有状态条信息</li>
</ul>
<p>使用步骤：</p>
<ol>
<li>包含所需的js和css:
<div class="wp_syntax">
<table style="height: 92px;" width="585">
<tbody>
<tr>
<td class="line_numbers"></td>
<td class="code">
<pre class="html4strict" style="font-family: monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"stylesheet"</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"all.css"</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text/css"</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"all"</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"stylesheet"</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"sIFR-screen.css"</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text/css"</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"screen"</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"stylesheet"</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"sIFR-print.css"</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text/css"</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"print"</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"sifr.js"</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text/javascript"</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"sifr-addons.js"</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text/javascript"</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre>
</td>
</tr>
</tbody>
</table>
</div>
</li>
<li>执行代码:
<div class="wp_syntax">
<table>
<tbody>
<tr>
<td class="line_numbers"></td>
<td class="code">
<pre class="javascript" style="font-family: monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366cc;">"text/javascript"</span><span style="color: #339933;">&gt;</span>
<span style="color: #006600; font-style: italic;">//&lt;![CDATA[</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">(</span><span style="color: #000066; font-weight: bold;">typeof</span> sIFR <span style="color: #339933;">==</span> <span style="color: #3366cc;">"function"</span><span style="color: #009900;">)</span><span style="color: #009900;">{</span>
<span style="color: #006600; font-style: italic;">// 建议用这种格式</span>
    sIFR.<span style="color: #660066;">replaceElement</span><span style="color: #009900;">(</span>named<span style="color: #009900;">(</span><span style="color: #009900;">{</span>sSelector<span style="color: #339933;">:</span><span style="color: #3366cc;">"body h1"</span><span style="color: #339933;">,</span> sFlashSrc<span style="color: #339933;">:</span><span style="color: #3366cc;">"vandenkeere.swf"</span><span style="color: #339933;">,</span> sColor<span style="color: #339933;">:</span><span style="color: #3366cc;">"#000000"</span><span style="color: #339933;">,</span> sLinkColor<span style="color: #339933;">:</span><span style="color: #3366cc;">"#000000"</span><span style="color: #339933;">,</span> sBgColor<span style="color: #339933;">:</span><span style="color: #3366cc;">"#FFFFFF"</span><span style="color: #339933;">,</span> sHoverColor<span style="color: #339933;">:</span><span style="color: #3366cc;">"#CCCCCC"</span><span style="color: #339933;">,</span> nPaddingTop<span style="color: #339933;">:</span><span style="color: #cc0000;">20</span><span style="color: #339933;">,</span> nPaddingBottom<span style="color: #339933;">:</span><span style="color: #cc0000;">20</span><span style="color: #339933;">,</span> sFlashVars<span style="color: #339933;">:</span><span style="color: #3366cc;">"textalign=center&amp;offsetTop=6"</span><span style="color: #009900;">}</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// 这种格式也可以，但参数的顺序就必须按照指定的顺序写，没有的参数用null表示。</span>
    sIFR.<span style="color: #660066;">replaceElement</span><span style="color: #009900;">(</span><span style="color: #3366cc;">"h5#pullquote"</span><span style="color: #339933;">,</span> <span style="color: #3366cc;">"vandenkeere.swf"</span><span style="color: #339933;">,</span> <span style="color: #3366cc;">"#000000"</span><span style="color: #339933;">,</span> <span style="color: #3366cc;">"#000000"</span><span style="color: #339933;">,</span> <span style="color: #3366cc;">"#FFFFFF"</span><span style="color: #339933;">,</span> <span style="color: #3366cc;">"#FFFFFF"</span><span style="color: #339933;">,</span> <span style="color: #cc0000;">0</span><span style="color: #339933;">,</span> <span style="color: #cc0000;">0</span><span style="color: #339933;">,</span> <span style="color: #cc0000;">0</span><span style="color: #339933;">,</span> <span style="color: #cc0000;">0</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
    sIFR.<span style="color: #660066;">replaceElement</span><span style="color: #009900;">(</span><span style="color: #3366cc;">"h3"</span><span style="color: #339933;">,</span> <span style="color: #3366cc;">"tradegothic.swf"</span><span style="color: #339933;">,</span> <span style="color: #3366cc;">"#000000"</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #cc0000;">0</span><span style="color: #339933;">,</span> <span style="color: #cc0000;">0</span><span style="color: #339933;">,</span> <span style="color: #cc0000;">0</span><span style="color: #339933;">,</span> <span style="color: #cc0000;">0</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #009900;">}</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//]]&gt;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre>
</td>
</tr>
</tbody>
</table>
</div>
</li>
</ol>
<p>sIFR.replaceElement函数的参数 </p>
<ul>
<li>sSelector<br />
  <span lang="EN-US">CSS selector </span><span>，使用这个选择器选择需要替换的文本元素。支持的选择器包括</span> <span lang="EN-US">ID</span><span>选择器（</span><span lang="EN-US">#</span><span>）</span><span lang="EN-US">,</span><span>子代选择器（</span><span lang="EN-US">&gt;</span><span>）和类选择器（</span><span lang="EN-US">.</span><span>）。</span> <span>多个选择器可以用逗号隔开。如：</span><span lang="EN-US">“body h1″</span><span>，</span><span lang="EN-US">“h5#pullquote”</span><span>，</span><span lang="EN-US">“h3.sidebox”</span><span>，</span><span lang="EN-US">“h3″</span><span>等等。</span></li>
<li>sFlashSrc<br />
  <span>嵌入字符的</span><span lang="EN-US">swf</span><span>文件的位置。</span></li>
<li><span lang="EN-US">sColor<br />
  </span><span>文本颜色。如</span><span lang="EN-US"> (#000000).</span></li>
<li>sLinkColor<br />
  链接的文本颜色</li>
<li>sHoverColor<br />
  <span lang="EN-US">hovered links</span><span>的颜色</span><span lang="EN-US">.</span></li>
<li>sBgColor<br />
  <span>背景色。</span></li>
<li><span lang="EN-US">nPaddingTop<br />
  </span><span>上部填充。单位</span><span lang="EN-US">pixels, </span><span>但不要写</span><span lang="EN-US"> px</span><span>部分。</span></li>
<li>nPaddingRight<br />
  右填充</li>
<li>nPaddingBottom<br />
  底部填充</li>
<li>nPaddingLeft<br />
  左填充</li>
<li>sFlashVars<br />
  <span>传递给</span><span lang="EN-US">Flash</span><span>的参数。参数间用</span><span lang="EN-US">&amp;</span><span>分隔。</span><span>如下可以使用下面这些参数：</span><span lang="EN-US"> </span> <span lang="EN-US">textalign=center: </span><span>水平居中</span> <span lang="EN-US">offsetLeft=5: </span><span>距离左边</span><span lang="EN-US">5px </span> <span lang="EN-US">offsetTop=5: </span><span>距离上边</span><span lang="EN-US">5px</span> <span lang="EN-US">underline=true: </span><span>对</span><span lang="EN-US">hover</span><span>的链接添加下划线</span></li>
<li>sCase<br />
  <span>等于</span><span lang="EN-US">upper</span><span>可以变成大写；等于</span><span lang="EN-US">lower </span><span>转换成小写。</span></li>
<li>sWmode<br />
  <span>将该参数设置成</span><span lang="EN-US"> transparent </span><span>，可以使背景透明。如果希望元素叠放在</span><span lang="EN-US">Flash</span><span>上，则应设置成</span><code><span lang="EN-US">opaque</span></code></li>
</ul>
<p>总结</p>
<ul>
<li>sIFR并不会和图片替换技术相竞争；它是针对不同工作的独特的工具。它能被最好的使用在那些显示为浏览器缺省字体大小的，而又不能替换为自建图片的文本上。</li>
<li>sIFR理想的使用场合是，当你想要仅用一张图片就显示自定义的字体或者反锯齿的标题时。这在web上被非常频繁的使用，在这些案例中sIFR是一个更好的选择。它可以缩放为用户缺省的字体尺寸，可以被选择，可以使用在数以千计的页面上而只需要下载一两个文件。</li>
</ul>
<p>摘要</p>
<ul>
<li>在页面标题上使用sIFR。</li>
<li>有限度的使用sIFR，以获得最佳的下载时间。</li>
<li>不要在链接上使用sIFR。</li>
</ul>
<p>相关链接：</p>
<ul>
<li><a rel="external nofollow" href="http://dev.novemberborn.net/sifr3/nightlies/">sIFR 3版本：http://wiki.novemberborn.net/sifr3/</a></li>
<li><a rel="external nofollow" href="http://wiki.novemberborn.net/sifr3/">sIFR 3文档： http://wiki.novemberborn.net/sifr3/</a></li>
<li><a rel="external nofollow" href="http://www.mikeindustries.com/blog/sifr/">Mike Davidson  –  sIFR: http://www.mikeindustries.com/blog/sifr/</a></li>
<li><a rel="external nofollow" href="http://baike.baidu.com/view/1311052.htm">sIFR – 百度百科: http://baike.baidu.com/view/1311052.htm</a></li>
<li><a rel="external nofollow" href="http://guowushi54.blog.163.com/blog/static/203582220071123112455818/">sIFR-文本替换技术: http://guowushi54.blog.163.com/blog/static/203582220071123112455818/</a></li>
<li><a rel="external nofollow" href="http://www.w3cn.org/article/translate/2005/117.html">如何以及何时使用sIFR: http://www.w3cn.org/article/translate/2005/117.html</a></li>
</ul>
<h3>方案三：Typeface.js</h3>
<p>Typeface被认为是替代SIFR的最佳方案，相对于sIFR，Typeface少了Flash的应用，使用纯JS来嵌入相关字体，而且用法也很简单：在页面中引入相应的js文件就可以。</p>
<div class="wp_syntax">
<table>
<tbody>
<tr>
<td class="line_numbers"></td>
<td class="code">
<pre class="html4strict" style="font-family: monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
　<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--加载所有的样式先--&gt;</span>
　　<span style="color: #009900;">&lt;link　<span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"stylesheet"</span>　<span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text/css"</span>　ref<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"/style.css"</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--再加载typeface.js　库文件和typeface.js字体文件--&gt;</span>
　　<span style="color: #009900;">&lt;script　<span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text/javascript"</span>　<span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"typeface-0.10.js"</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
　　<span style="color: #009900;">&lt;script　<span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text/javascript"</span>　<span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"helvetiker_regular.typeface.js"</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
　<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
　<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--继续并使用CSS指定typeface.js字体--&gt;</span>
　　<span style="color: #009900;">&lt;div　<span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"myclass　typeface-js"</span>　<span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"font-family:　Helvetiker"</span>&gt;</span>
　　　文本文本...
　　<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
　<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>相关链接：</p>
<ul>
<li> <a href="http://typeface.neocracy.org/">typeface: http://typeface.neocracy.org/</a></li>
</ul>
<h3>方案四：cufon</h3>
<p>cufon是一个比较新的技术，被定位为有价值的sIFR替代方案，它有很多优势：</p>
<ul>
<li>无需浏览器插件——被浏览器原生支持；</li>
<li>兼容性——兼容各个主流浏览器</li>
<li>易用—— 无需配置</li>
<li>速度—— 快速渲染大量字体</li>
</ul>
<p>cufon和typeface.js对比</p>
<table>
<tbody>
<tr>
<td width="151"></td>
<td width="429">Cufón</td>
<td width="439">Typeface.js</td>
</tr>
<tr>
<td><strong>File size</strong></td>
<td>14.0kb (压缩后)</td>
<td>16.3kb (未压缩)</td>
</tr>
<tr>
<td><strong>支持的浏览器</strong></td>
<td>Firefox 1.5+, Safari 3+, Opera 9.5+, Google Chrome 和 Internet Explorer6+</td>
<td>Firefox 1.5+, Safari 2+, and Internet Explorer 6+, 最新版已经支持IE8</td>
</tr>
<tr>
<td><strong>支持的字体类型</strong></td>
<td>.ttf, .otf, PFB, postscript</td>
<td>.ttf</td>
</tr>
<tr>
<td><strong>支持的字体样式</strong></td>
<td>font-size, font-style, font-weight, line-height, text-shadow, color</td>
<td>font-size, font-style, font-weight, font-stretch, letter-spacing, line-height</td>
</tr>
<tr>
<td><strong>可选文字?</strong></td>
<td>尚不支持</td>
<td>尚不支持</td>
</tr>
</tbody>
</table>
<p>cufon资源：</p>
<ul>
<li>cufon项目: <a href="http://wiki.github.com/sorccu/cufon/about" target="_blank">http://wiki.github.com/sorccu/cufon/about</a></li>
<li>cufon演示(列表): <a href="http://wiki.github.com/sorccu/cufon/demos" target="_blank">http://wiki.github.com/sorccu/cufon/demos</a></li>
<li>cufon生成器: <a href="http://cufon.shoqolate.com/generate/" target="_blank">http://cufon.shoqolate.com/generate/</a></li>
<li>wp-cufon: <a href="http://wordpress.org/extend/plugins/wp-cufon/" target="_blank">一个使用cufon的wordpress插件  http://wordpress.org/extend/plugins/wp-cufon/</a></li>
<li><a href="http://stackoverflow.com/questions/692990/sifr-vs-cufon-vs-typeface-js" target="_blank">Typeface.js VS sIFR VS cufon: http://stackoverflow.com/questions/692990/sifr-vs-cufon-vs-typeface-js</a></li>
</ul>
<p>相关链接：</p>
<ul>
<li><a href="http://wiki.github.com/sorccu/cufon/about" target="_blank">cufon 文档: http://wiki.github.com/sorccu/cufon/about</a></li>
</ul>
<p>综述：</p>
<p>事实上，sIFR、typeface.js和cufon都是目前常说的文本替换技术，这些技术都可以用来替换@font-face，并且实现更好的浏览器兼容性。但是每种技术都不是完美的：</p>
<p>@font-face最简单，虽然大部分浏览器也都支持了，但是其浏览器兼容性并不是很完美，对IE还需要eof字体的特殊支持，而且对于中文字体来说，一般都很大，这会占用很大的页面加载时间和服务器流量。</p>
<p>sIFR是兼容性和可用性最好、对SEO友好的一种方案，但也是实现起来最复杂的，而且需要浏览器支持Flash插件。</p>
<p>typeface和cufon都是利用在IE中渲染VML，而在非IE浏览器中使用canvas的方式实现“伪”字体的，他们使用起来相对简单，但是可用性和用户体验以及SEO都不是很理想。</p>
<p>版权问题是一个很重要的问题，无论你使用哪种技术，都需要考虑文字的授权。</p>
<blockquote><p>注：</p>
<ul>
<li>部分资料收集于网络，纯属交流学习，有侵犯版权之处请联系我</li>
<li>欢迎贡献讨论关于 “文字替换技术” 的更多相关文章资料</li>
</ul>
</blockquote>
<h2  class="related_post_title">Related Posts / 相关文章</h2><ul class="related_post"><li><a href="http://slj.me/2010/03/css3-please-the-cross-browser-css3-rule-generator/" title="CSS3, Please! The Cross-Browser CSS3 Rule Generator">CSS3, Please! The Cross-Browser CSS3 Rule Generator</a></li><li><a href="http://slj.me/2009/12/html5-css3/" title="揭秘HTML5和CSS3">揭秘HTML5和CSS3</a></li><li><a href="http://slj.me/2009/12/pushing-your-buttons-with-practical-css3/" title="来用实用的CSS3来制作你的酷炫按钮吧">来用实用的CSS3来制作你的酷炫按钮吧</a></li><li><a href="http://slj.me/2009/05/scalable-inman-flash-replacement/" title="谈谈sIFR &#8211; 可伸缩Inman Flash替换">谈谈sIFR &#8211; 可伸缩Inman Flash替换</a></li><li><a href="http://slj.me/2009/04/css-3-the-future-shines-bright/" title="CSS 3 &#8211; 前途一片光明">CSS 3 &#8211; 前途一片光明</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2010/07/font-replacement-css3-sifr-typeface-js-cufon/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Twitter Connect 转载自 Twitter 官方 Wiki</title>
		<link>http://slj.me/2010/04/twitter-connect-sign-in-with-twitter/</link>
		<comments>http://slj.me/2010/04/twitter-connect-sign-in-with-twitter/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 05:22:30 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://slj.me/?p=1710</guid>
		<description><![CDATA[Sign in with Twitter is the pattern of authentication that allows users to connect their Twitter account with third-party services in as little is one click. It utilizes OAuth and although the flow is very similar, the authorization URL and workflow differs slightly as described below. The normal flow dictates that applications send request tokens [...]]]></description>
			<content:encoded><![CDATA[<p><img height="260" width="595" class="thumb" alt="Twitter Connect" src="http://slj.me/wp-content/uploads/2010/04/twitter_connect_post_thumb.png"/></p>
<p><strong>Sign in with Twitter</strong> is the pattern of authentication that  allows users to connect their Twitter account with third-party services in as  little is one click. It utilizes OAuth and although the flow is very similar,  the authorization URL and workflow differs slightly as described below.</p>
<p>The normal flow dictates that applications send request tokens to oauth/authorize in Twitter&#8217;s  implementation of the OAuth Specification. To take advantage of <strong>Sign in  with Twitter</strong>, applications should send request tokens in the oauth_token parameter to oauth/authenticate instead.</p>
<p><span id="more-1710"></span><br />
The oauth/authenticate method  will perform the following:</p>
<ol>
<li>If the user is logged into Twitter.com and has already approved the calling  application, the user will be immediately authenticated and returned to the  callback URL.</li>
<li>If the user is not logged into Twitter.com and has already approved the  calling application, the user will be prompted to login to Twitter.com then will  be immediately authenticated and returned to the callback URL.</li>
<li>If the user is logged into Twitter.com and has not already approved the  calling application, the OAuth authorization prompt will be presented.  Authorizing users will then be redirected to the callback URL.</li>
<li>If the user is not logged into Twitter.com and has not already approved the  calling application, the user will be prompted to login to Twitter.com then will  be presented the authorization prompt before redirecting back to the callback  URL.</li>
</ol>
<p>This behavior is explained in the following flowchart:</p>
<p><img src="http://slj.me/wp-content/uploads/2010/04/oauth_sign_in_with_twitter_flow.png" alt="" /></p>
<h3><strong>Sign in with Twitter</strong> Buttons</h3>
<p>Twitter would prefer your application to use the following buttons. While it  is easy roll your own buttons or create text links, using these standard buttons  will instill user confidence and standardize the experience.</p>
<h4>Darker</h4>
<p><img src="http://slj.me/wp-content/uploads/2010/04/Sign-in-with-Twitter-darker.png" alt="" /></p>
<p><img src="http://slj.me/wp-content/uploads/2010/04/Sign-in-with-Twitter-darker-small.png" alt="" /></p>
<h4>Lighter</h4>
<p><img src="http://slj.me/wp-content/uploads/2010/04/Sign-in-with-Twitter-lighter.png" alt="" /></p>
<p><img src="http://slj.me/wp-content/uploads/2010/04/Sign-in-with-Twitter-lighter-small.png" alt="" /></p>
<p>Peter Denton has also created a <a href="http://twibs.com/oAuthButtons.php" target="_blank">number of buttons</a> to make this experience easy and  beautiful.</p>
<h2  class="related_post_title">Related Posts / 相关文章</h2><ul class="related_post"><li><a href="http://slj.me/2009/07/twitter-ops/" title="从 Twitter 运维技术经验可以学到什么">从 Twitter 运维技术经验可以学到什么</a></li><li><a href="http://slj.me/2009/06/louzui/" title="注册漏嘴网">注册漏嘴网</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2010/04/twitter-connect-sign-in-with-twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>转：使用 Dojo 开发离线应用</title>
		<link>http://slj.me/2010/04/%e8%bd%ac%ef%bc%9a%e4%bd%bf%e7%94%a8-dojo-%e5%bc%80%e5%8f%91%e7%a6%bb%e7%ba%bf%e5%ba%94%e7%94%a8/</link>
		<comments>http://slj.me/2010/04/%e8%bd%ac%ef%bc%9a%e4%bd%bf%e7%94%a8-dojo-%e5%bc%80%e5%8f%91%e7%a6%bb%e7%ba%bf%e5%ba%94%e7%94%a8/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 14:11:44 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://slj.me/?p=1679</guid>
		<description><![CDATA[Dojo 离线功能简介 所谓离线，指的是用户能够在没有网络的环境下也可以进行工作，并且当网络环境恢复后，之前的操作能够自动地同步到服务器上。目前，离线应用可以分为两种，一种是桌面应用，其中以 IBM Lotus Notes 为代表。另外一种则是近来比较热门的 Web 离线应用，其中最具代表的为 Google 的离线应用，如 Google Docs, Gmail, Google Reader 等。而本文介绍的 Dojo 离线功能，则是目前最为流行的实现第二种离线应用的框架。 回页首 Dojo 离线原理 Dojo Offline 是一个免费的开放源代码的离线开发工具，它可以轻松地让 Web 开发人员开发离线应用。Dojo Offline 构建于 Google Gear 之上，它使得在 Google Gear 上开发离线应用变得更加简单。Dojo Offline 对 Google Gears 的 API 进行了封装，能够更方便地以 JavaScript 的方式访问数据；另外，Dojo Offline 还提供了如下功能： Offline Widget：开发人员只要添加几行代码，就能够将这个离线的 widget 嵌入自己的应用中，之后，就能够自动获得网络反馈 , 同步消息以及离线操作配置说明等。 同步框架：保存离线数据，并且在网络恢复后将这些操作和服务器进行同步。 自动的网络和应用程序状态监控机制：离线应用可以基于这些监控结果来决定采取什么样的操作。 slurp() [...]]]></description>
			<content:encoded><![CDATA[<p><a name="1.Dojo 离线功能简介 |outline">Dojo 离线功能简介</a></p>
<p>所谓离线，指的是用户能够在没有网络的环境下也可以进行工作，并且当网络环境恢复后，之前的操作能够自动地同步到服务器上。目前，离线应用可以分为两种，一种是桌面应用，其中以 IBM Lotus Notes 为代表。另外一种则是近来比较热门的 Web 离线应用，其中最具代表的为 Google 的离线应用，如 Google Docs, Gmail, Google Reader 等。而本文介绍的 Dojo 离线功能，则是目前最为流行的实现第二种离线应用的框架。</p>
<p><span id="more-1679"></span></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" alt="" width="100%" height="1" /><br />
<img src="http://www.ibm.com/i/c.gif" border="0" alt="" width="8" height="6" /></td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="0" align="right">
<tbody>
<tr align="right">
<td><img src="http://www.ibm.com/i/c.gif" alt="" width="100%" height="4" /></p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="middle"><img src="http://www.ibm.com/i/v14/icons/u_bold.gif" border="0" alt="" width="16" height="16" /></td>
<td align="right" valign="top"><a href="http://www.ibm.com/developerworks/cn/web/0906_dojo_offline_hehj/#main"><strong>回页首</strong></a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p><a name="2.Dojo 离线原理 |outline">Dojo 离线原理</a></p>
<p>Dojo Offline 是一个免费的开放源代码的离线开发工具，它可以轻松地让 Web 开发人员开发离线应用。Dojo Offline 构建于 Google Gear 之上，它使得在 Google Gear 上开发离线应用变得更加简单。Dojo Offline 对 Google Gears 的 API 进行了封装，能够更方便地以 JavaScript 的方式访问数据；另外，Dojo Offline 还提供了如下功能：</p>
<ol>
<li>Offline Widget：开发人员只要添加几行代码，就能够将这个离线的 widget 嵌入自己的应用中，之后，就能够自动获得网络反馈 , 同步消息以及离线操作配置说明等。</li>
<li>同步框架：保存离线数据，并且在网络恢复后将这些操作和服务器进行同步。</li>
<li>自动的网络和应用程序状态监控机制：离线应用可以基于这些监控结果来决定采取什么样的操作。</li>
<li>slurp() 方法：通过 slurp() 方法来自动扫描页面，找出需要缓存到本地的资源，包括图片，样式，脚本等。这使得 Web 开发人员能够集中精力地去开发业务逻辑和展示页面，而不需要考虑具体哪些资源需要缓存到本地。</li>
<li>提供两种本地存储实现方法：Dojo Storage 和 Dojo SQL。Dojo Storage 使用哈希表来存储离线数据，为开发人员屏蔽了重量级的 Google Gears 的 SQL 使用方法，我们可以通过 Dojo Storage 将数据保存到 Google Gears 里去。Dojo SQL 通过执行 SQL 命令，对一般的 JavaScript 对象进行存取。</li>
<li>加密和解密关键字 ENCRYPT() 和 DECRYPT()：提供对下载后的离线数据加密和解密方法。</li>
<li>Dojo 其他模块的集成：如果用户选择 Dojo Offline，毫无疑问，其应用可以受益于 Dojo 的其他功能，比如完善的事件处理机制，Ajax 框架等等。</li>
</ol>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" alt="" width="100%" height="1" /><br />
<img src="http://www.ibm.com/i/c.gif" border="0" alt="" width="8" height="6" /></td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="0" align="right">
<tbody>
<tr align="right">
<td><img src="http://www.ibm.com/i/c.gif" alt="" width="100%" height="4" /></p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="middle"><img src="http://www.ibm.com/i/v14/icons/u_bold.gif" border="0" alt="" width="16" height="16" /></td>
<td align="right" valign="top"><a href="http://www.ibm.com/developerworks/cn/web/0906_dojo_offline_hehj/#main"><strong>回页首</strong></a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p><a name="3.Google Gears 简介 |outline">Google Gears 简介</a></p>
<p>Google Gears 是 Google 开发的一个自由和开源软件，以 BSD 许可证发布。主要是为了能够让用户可以在离线时能够继续使用 Web 应用。这套软件透过 SQLite 数据库让本地端能够把资料暂存起来。所以网页是透过缓存取得的，而不是从实际的网络上取得。而且，Web 相关的程序可以周期性的透过 Gears 将本地缓存的资料与网络上的资料做同步。如果网络暂时无法使用，这个同步过程将会延后，直到网络恢复为止。Google Gears 通过以浏览器扩展的方式添加 JavaScript API，使得浏览器的脚本能够访问本地的缓存数据库。该扩展目前支持 Firefox，Internet Explorer 和 Safari，并需工作于 Windows、Mac OS X，或是 Linux 下。</p>
<p>Google Gears 有几个主要的组件：</p>
<ol>
<li>一个本地服务器，用来存储和读取离线程序资源（包括 HTML 文件 , JavaScript 文件 , 图片等）。</li>
<li>一个小型数据库（基于 SQLite 轻量数据库），用来储存本地数据。</li>
<li>一个工作池，用来让开发者将本地数据与服务器端后台同步。</li>
<li>一个桌面模型，可使网络程序的操作贴近桌面程序。</li>
<li>一个地理定位模型，能够让网络程序侦测到目前用户的地理位置。</li>
</ol>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" alt="" width="100%" height="1" /><br />
<img src="http://www.ibm.com/i/c.gif" border="0" alt="" width="8" height="6" /></td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="0" align="right">
<tbody>
<tr align="right">
<td><img src="http://www.ibm.com/i/c.gif" alt="" width="100%" height="4" /></p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="middle"><img src="http://www.ibm.com/i/v14/icons/u_bold.gif" border="0" alt="" width="16" height="16" /></td>
<td align="right" valign="top"><a href="http://www.ibm.com/developerworks/cn/web/0906_dojo_offline_hehj/#main"><strong>回页首</strong></a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p><a name="4. 开发 Dojo 离线应用程序 |outline">开发 Dojo 离线应用程序</a></p>
<p>一般来说开发一个离线应用有以下几个步骤：</p>
<ol>
<li>应用加载时缓存所引用的资源。</li>
<li>应用加载之后设置必要的离线事件处理函数。如：与服务器进行同步操作时的下载事件、下载完成事件，重放事件等。</li>
<li>检查应用是否在线，读取应用所需的数据。如果离线则从本地读取数据；如果在线则与服务器数据进行同步：首先上传离线数据（如果有的话），然后从服务器上下载最新数据。</li>
<li>初始化应用程序。</li>
</ol>
<p>下面我们会先分别介绍如何保存离线资源，保存和使用应用离线数据以及如何与服务器的数据保持同步等相关技术，然后以一个具体的例子说明如何按上述步骤开发一个离线应用。</p>
<p><a name="N10125">保存离线资源</a></p>
<p>为了使页面能够在离线情况下操作，在页面加载时必须要保存页面所引用的 HTML 文件，JavaScript 文件，CSS 文件，图片文件等资源，这样在与服务器断开连接时，页面便能够从本地缓存中提取到页面及相关的资源。Dojo 提供了一个功能非常强大的函数 slurp 来实现这一功能。slurp 函数在页面加载之后会自动分析页面所引用的资源，并得到一个资源文件的 url 列表，然后抓取 url 的内容，保存到 Google Gears 中。slurp 函数能够缓存大部分的资源文件，包括引用 CSS 文件里的图片，但是对于使用内联方式指定的 CSS 图片以及用 JavaScript 动态产生的引用 slurp 则无法进行缓存。这种情况可以通过调用 dojox.off.files.cache () 方法来手动添加要缓存的资源，具体用法详见后文。</p>
<p>Dojo Offline 还提供了在调试时查看已缓存资源文件的方法，首先以 debug 方式加载 Dojo，然后在页面和 Dojo Offline 加载完之后调用 dojox.off.files.printURLs() 函数。这个函数会在控制台以调试的方式打印出已缓存的资源文件的 url。</p>
<p><a name="N10131">保存和使用离线数据</a></p>
<p>一般来说，离线应用不仅要缓存页面所引用的 HTML 文件，JavaScript，CSS，图片等资源，还要缓存页面所使用的数据。Dojo 对 Google Gears 的访问接口进行了封装，提供了 Dojo Storage 和 Dojo SQL 两种方式操作离线数据。通过这两种方式，用户可以方便、灵活地保存和读取离线数据。</p>
<ul>
<li>Dojo Storage</li>
</ul>
<p>提供了一种类似哈希表的方式对数据进行操作，数据以键值对的方式存取。</p>
<p>保存：dojox.storage.put(key,value) — key 是字符串类型，value 可以是字符串和可序列化的 JavaScript 对象，但是浏览器对象（如 DOM 节点和 XMLHttpRequest 对象）是不能够保存的。</p>
<p>读取：var value = dojox.storage.get(key) —获取字符串 key 对应的值。<br />
<a name="N1014A"><strong>清单 1</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>var car = {type: "Nissan", color: "white", price: 20000, optional:
 "air-conditioner, stereo"};
dojox.storage.put("complexKey", car);

var value = dojox.storage.get("someKey");
var car = dojox.storage.get("complexKey");
if(car)
alert(car.type);</pre>
</td>
</tr>
</tbody>
</table>
<p>上述代码先将一个对象 car 放置在 Dojox.Storage 里，然后又从中取出并展示。</p>
<ul>
<li>Dojo SQL</li>
</ul>
<p>通过 Dojo SQL 对 Google Gears 关系存储层的封装，能够以更适合 JavaScript 对象的访问方式对关系表进行操作。如下所示，我们对 Documents 表进行了创建，插入，查询操作：<br />
<a name="N1015D"><strong>清单 2</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>//create Documents table if not exist
dojox.sql("CREATE TABLE IF NOT EXISTS DOCUMENTS ("
+ "fileName		TEXT NOT NULL PRIMARY KEY UNIQUE,"
+ "content		TEXT NOT NULL) ");
//insert a record
dojox.sql("INSERT INTO DOCUMENTS (fileName, content) VALUES (?, ?)", fileName, contents);
//query
var results = dojox.sql("SELECT * FROM DOCUMENTS WHERE fileName = ?", someFileName);</pre>
</td>
</tr>
</tbody>
</table>
<p>Dojo 查询操作返回的是一个记录对象的数组，如访问第一条记录的 fileName 字段，可以使用 results[0].fileName，访问 content 字段则可以使用 results[0].content。</p>
<p><a name="N10166">与服务器同步数据</a></p>
<p>离线操作所产生的新数据，在与服务器连接可用时需要上传到服务器；并且，在该用户离线期间，其他用户也可能已经更改过数据，因此重新连接服务器时需要下载最新的数据。Dojo 的同步操作发生的时机有两个，一是在页面首次加载并且在线的时候，或是离线后又检测到连接恢复的时候，具体包括 3 个步骤：</p>
<ol>
<li>下载并缓存最新的页面资源，包括由 slurp 函数以及用户手动缓存的资源。Dojo Offline Widget 会自动更新相应的状态，如下图所示：
<p><a name="N10174"><strong>图 1. 下载状态 </strong></a><br />
<img src="http://www.ibm.com/developerworks/cn/web/0906_dojo_offline_hehj/image003.jpg" alt="下载状态" width="164" height="140" /></li>
<li>上传用户在离线期间所创建的数据。
<p><a name="N10185"><strong>图 2. 上传状态 </strong></a><br />
<img src="http://www.ibm.com/developerworks/cn/web/0906_dojo_offline_hehj/image005.jpg" alt="上传状态" width="166" height="142" /></li>
<li>下载服务器最新数据进行展示。
<p><a name="N10196"><strong>图 3. 同步成功 </strong></a><br />
<img src="http://www.ibm.com/developerworks/cn/web/0906_dojo_offline_hehj/image007.jpg" alt="同步成功" width="166" height="140" /></p>
<p>如上所示，Dojo Offline 提供了一个 UI 控件来通知用户当前的状态，如下载，上传以及网络连接状态等。Dojo Offline Widget 处理了大部分的逻辑，开发人员可以直接在页面中使用该控件。使用 Offline Widget 很简单，只需在页面加入一个占位符即可。Offline Widget 也提供了扩展机制，以更改所使用的图片和样式来跟页面风格保持一致。</li>
</ol>
<p><a name="N101A7">Dojo 离线应用示例</a></p>
<p>Dojo Offline 随附的开发包中提供了 3 个例子，下面以 hello world 为例说明如何构建一个简单的离线应用。hello world 程序模拟了用户与服务器简单的消息交互。用户界面包括一个输入框和一个发送按钮，在输入框里输入文本，点击发送按钮将消息发送到服务器。为了保持用例的简单，实际上消息并没有真正被发送到服务器，而只是简单地将其弹出。在应用离线时，点击发送按钮则会先在本地保存该消息，当应用重新连接时再重新执行该操作。</p>
<ol>
<li>首先加载 Dojo 及离线所使用的 JavaScript 文件。
<p><a name="N101B5"><strong>清单 3</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>&lt;script type="text/javascript" src="../../../../dojo/dojo.js"
djConfig="isDebug: true"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="../../../../dojox/off/offline.js"&gt;
&lt;/script&gt;</pre>
</td>
</tr>
</tbody>
</table>
<p>当然，我们也可以用 dojo.require 方法进行加载：</p>
<p><a name="N101C0"><strong>清单 4</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>&lt;script type="text/javascript" src="../../../../dojo/dojo.js"
djConfig="isDebug: true"&gt;&lt;/script&gt;
&lt;script type="text/javascript" &gt;
 dojo.require(“dojox.off.offline”);
 &lt;/script&gt;</pre>
</td>
</tr>
</tbody>
</table>
</li>
<li>设置应用程序的名字，这个名字会显示在 Dojo Offline Widget 上。
<p><a name="N101CB"><strong>清单 5</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>dojox.off.ui.appName = "Hello World";</pre>
</td>
</tr>
</tbody>
</table>
</li>
<li>缓存页面资源文件。要使离线功能正常工作，这个函数必须在 Dojo Offline 初始化之前调用，即 dojox.off.initialize 函数调用之前。
<p><a name="N101D5"><strong>清单 6</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>dojox.off.files.slurp();</pre>
</td>
</tr>
</tbody>
</table>
</li>
<li>初始化应用程序，设置离线操作的一些事件响应函数。
<p><a name="N101DF"><strong>清单 7</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>initialize: function(){
	console.debug("helloWorld.initialize");
	var self = this;
	dojo.connect(dojox.off.sync, "onSync", this, function(type){
		if(type == "download"){
			self._messages.push("Hi! This is fake downloaded data!");
			dojox.storage.put("messages", self._messages);
			dojox.off.sync.finishedDownloading();
		}else if(type == "finished"){
			this._messages = [];
			dojox.storage.remove("messages");
		}
	});
	dojo.connect(dojox.off.sync.actions, "onReplay", this,
				function(action, actionLog){
					if(action.name == "new hello world message"){
						var message = action.data;
						self.sendMessage(message);
						actionLog.continueReplay();
				}
	});
	if(!dojox.off.isOnline){
		this.loadOfflineData();
	}
	this.printMessages();
}</pre>
</td>
</tr>
</tbody>
</table>
<p>可以看到，此处最主要的两个操作是设置 dojox.off.sync 对象的 onSync 事件和 dojox.off.sync.actions 对象的 onReplay 事件。其中，onSync 用来处理与服务器的同步，download 事件发生在第一次加载页面或是网络重新连接的时候，在该事件中我们应该从服务器下载数据，并在下载完毕之后调用 dojox.off.sync.finishedDownloading() 方法，以便告诉 Dojo Offline Widget 更新当前状态。finished 事件则说明从服务器下载数据结束，可以更新应用程序了。</p>
<p>Dojo Offline 使用 action log 来记录用户在离线时所执行的操作，并在重新获得网络连接时再次执行这些操作，将数据上传到服务器。</p>
<p>一般来说，程序初始化时首先要判断应用是否在线，如果不在线则加载本地数据进行页面展示。值得注意的是，这些事件何时触发是由 Dojo Offline 的同步框架根据当前应用程序状态决定的，开发人员只需设置相应的事件处理函数即可。</li>
<li>保存离线数据，这是通过创建 action log 来实现的。在与服务器重新连接时 action log 会自动重新执行。
<p><a name="N101F2"><strong>清单 8</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>saveOfflineSend: function(message){
	this._messages.push(message);
	dojox.storage.put("messages", this._messages);
	var action = {name: "new hello world message", data: message};
	dojox.off.sync.actions.add(action);
	alert("This message has been saved for sending when we go back online");</pre>
</td>
</tr>
</tbody>
</table>
</li>
<li>Dojo 的离线功能要在页面加载完及 Dojo Offline 初始化之后才能工作，因此页面本身的代码要在 Dojo Offline 初始化完成之后执行。Dojo Offline 的初始化完成可以用 dojox.off.ui 的 onLoad 事件来标识。我们首先将页面的初始化函数绑定到 dojox.off.ui 的 onLoad 事件，然后调用 dojox.off.initialize 函数对 Dojo Offline 进行初始化。
<p><a name="N101FD"><strong>清单 9</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>dojo.connect(dojox.off.ui, "onLoad", helloWorld, "initialize");
dojox.off.initialize();</pre>
</td>
</tr>
</tbody>
</table>
</li>
<li>加载 Dojo Offline Widget。实际上任何 html 元素，只要 id 为“dot-widget”都可以作为 Offline Widget 的占位符。Dojo Offline 初始化的时候会对这个元素进行填充。
<p><a name="N10208"><strong>清单 10</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>&lt;div id="dot-widget"&gt;&lt;/div&gt;</pre>
</td>
</tr>
</tbody>
</table>
</li>
<li>为页面加入展示元素。
<p><a name="N10213"><strong>清单 11</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>&lt;div id="helloMessage" style="margin: 1em;"&gt;
&lt;label for="helloInput" 	style="margin-right: 0.2em;"&gt;
Enter Hello World Message:
&lt;/label&gt;
&lt;input name="helloInput" id="helloInput" 	style="margin-right: 0.2em;"&gt;
&lt;button id="sendMessage" onclick="helloWorld.send()" style="margin-right: 0.2em;"&gt;
Send&lt;/button&gt;
&lt;/div&gt;
&lt;p&gt;Debug output:&lt;/p&gt;</pre>
</td>
</tr>
</tbody>
</table>
</li>
<li>运行 hello world
<p>hello world 示例程序不涉及服务器端代码，因此并不一定需要部署才能执行。但是为了便于测试在线 / 离线操作，最好还是通过服务器访问。</p>
<p>在 Dojo Offline 里随附的例子中，Moxie 编辑器是一个包括服务器和客户端的完整应用程序，它使用 Jetty 作为 Web 容器，使用 Derby 作为数据库。我们可以启动 Moxie 应用所在的 Jetty 容器来访问 hello world 应用。</p>
<p>首先请安装 jdk1.5 或以上版本，在 dojox/off/demos/editor/server/ 目录下，运行：</p>
<p>java -jar editor.jar</p>
<p>在浏览器地址栏输入 http://localhost:8000/dojox/off/demos/helloworld/helloworld.html 即可访问 hello world 应用。可以通过关闭 / 打开 Jetty 来观察 hello world 和 Dojo Offline Widget 在离线、在线及同步时的行为。</li>
</ol>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" alt="" width="100%" height="1" /><br />
<img src="http://www.ibm.com/i/c.gif" border="0" alt="" width="8" height="6" /></td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="0" align="right">
<tbody>
<tr align="right">
<td><img src="http://www.ibm.com/i/c.gif" alt="" width="100%" height="4" /></p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="middle"><img src="http://www.ibm.com/i/v14/icons/u_bold.gif" border="0" alt="" width="16" height="16" /></td>
<td align="right" valign="top"><a href="http://www.ibm.com/developerworks/cn/web/0906_dojo_offline_hehj/#main"><strong>回页首</strong></a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p><a name="5. 高级议题 |outline">高级议题</a></p>
<p><a name="N10235">网页资源的手工缓存</a></p>
<p>尽管利用 slurp() 方法可以为我们完成很多自动化的工作，但一些出现在 JavaScript 中的动态加载的资源是 slurp() 所无法分析得到的。因此，在实际应用中作为补充，我们往往还需要将一些 slurp 过程中的“漏网之鱼”手工加入本地缓存中。而 Dojo Offline 也为我们提供了相应的功能以支持这一需求。</p>
<p>手工将网络资源加入本地缓存的方法十分简单，例如，假设我们要将一个名为 big_and_little_fish.jpg 的文件缓存起来，可以执行如下方法：<br />
<a name="N10243"><strong>清单 12</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>dojox.off.files.cache("images/big_and_little_fish.jpg");</pre>
</td>
</tr>
</tbody>
</table>
<p>不仅如此，Dojo Offline 还提供了一次性指定多个文件的功能，调用方法如下所示：<br />
<a name="N1024F"><strong>清单 13</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>dojox.off.files.cache([
 "images/fish1.png",
 "images/fish2.png",
 "scripts/some_dynamic_fish.js"
 ]);</pre>
</td>
</tr>
</tbody>
</table>
<p>我们可以多次调用 cache() 方法，假如调用过程中指定了多个同名文件，则最后一次被缓存的文件将会替换前面的同名文件。利用这一方法，再结合前述的 slurp() 方法，我们就可以很好的将离线所需的全部资源在本地缓存起来了。</p>
<p><a name="N10258">数据的加密与解密</a></p>
<p>将数据下载到本地进行缓存是离线功能得以实现的重要步骤，但是假如这些数据中包含有敏感信息，例如身份证号码，而本地环境又不甚安全时，则对数据进行加密处理是很有必要的。前面曾经提到，我们在利用 Dojo Offline 进行数据存储时可以选择使用 Dojo SQL。而 Dojo SQL 允许我们很方便的对数据的某些字段进行加密和解密。</p>
<p>假设我们以前面的 DOCUMENT 表为例，假定其中的“content”字段属于敏感信息。</p>
<p>Dojo SQL 提供了两个特殊的关键字，ENCRYPT() 和 DECRYPT()，分别用以实现加密和解密操作。以 content 为例，调用方式类似如下：<br />
<a name="N10269"><strong>清单 14</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>var password = "password";
dojox.sql("INSERT INTO DOCUMENTS VALUES (?,ENCRYPT(?))", "helloworld.txt",
"sensitive content", password,
function(results, error, errorMsg){
if(error){ alert(errorMsg); return; }
});</pre>
</td>
</tr>
</tbody>
</table>
<p>在上述代码中，我们在后一个字段加上了 ENCRYPT 关键字，声明对其进行加密。除此以外，我们还提供了一个 password 参数，这是底层加密机制所必须的。当我们启用应用系统时，系统会提示输入这一密码。出于对本地数据安全性的考虑，请不要将其存于 Cookie，Dojo Storage，或是 Dojo SQL 中，否则他人就可以轻易利用这一密码解开存于本地的敏感数据。另外，上述代码里还定义了一个回调函数。该回调函数将会在加密过程结束之后被调用。如果加密成功，results 对象中将会包含经过加密后的数据；如果加密失败，则 error 值将会为 true，并且 errorMsg 中会包含对错误原因的描述信息。</p>
<p>和加密一样，对数据进行解密的过程也十分简单。我们只需对需要解密的字段调用 DECRYPT 关键字即可。示例代码如下：<br />
<a name="N10277"><strong>清单 15</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>var password = "password";
dojox.sql("SELECT fileName, DECRYPT(content) FROM DOCUMENTS",
password,
function(results, error, errorMsg){
if(error){ alert(errorMsg); return; }
// go through decrypted results
alert("First document info: "
+ results[0].fileName + " "
+ results[0].content);
});</pre>
</td>
</tr>
</tbody>
</table>
<p>在上述代码中，我们利用 alert 语句将加密后的第一条结果数据打印了出来。其中的 password 必须与加密时所使用的完全一致，否则解密将会失败，结果数据将仍然是加密后的样子。</p>
<p>假如我们要对多个字段进行加密，Dojo SQL 的 ENCRYPT 还有一种很方便的书写方法，即：ENCRYPT(?, ?)；同样的，对于 DECRYPT 也存在类似的书写方式，已完成一次性对多个数据字段进行解密：DECRYPT(fileName, content)</p>
<p><a name="N10283">定制 Offline Widget</a></p>
<p>虽然利用 Dojo Offline Widget 可以省去我们很多的功夫，但是在某些情况下，其默认行为并不一定能够很好的满足我们的需要，例如：默认的样式风格与我们的应用程序不一致，此时，我们就可以对 Offline Widget 进行一定程度的定制。</p>
<p>事实上，我们在页面上所见到的 Offline Widget 有其对应的模板文件，该文件位于 dojox/off/resources/offline-widget.html，其中包含有一系列的 HTML 元素，这些元素都有相应的 ID，比如：dot-widget-network-indicator，Offline Widget 就是利用默认的 CSS 文件对其进行控制的，该 CSS 文件位于：dojox/off/resources/offline-widget.css。我们可以通过自定义 CSS 的方式来改变 HTML 元素的样式，从而改变 Offline Widget 在页面中的展现风格。</p>
<p>除了改变展现风格，有时我们可能还需要改变展现的内容，我们可以将 offline-widget.html 中的内容选择性的复制到我们自己的 HTML 页面中，这样我们就可以根据自己的需要随意设计 Offline Widget 的展现内容，而无需定义一个 ID 为 dot-widget 的特定 DIV 了。</p>
<p>此外，如果我们只是想修改 Offline Widget 所使用的默认图标的话，则还有更为简单的做法。那就是对如下几个 JavaScript 变量进行修改：</p>
<ul>
<li>dojox.off.ui.onlineImagePath：表示在线状态的图标</li>
<li>dojox.off.ui.offlineImagePath：表示离线状态的图标</li>
<li>dojox.off.ui.rollerImagePath：表示同步正在进行的图标</li>
<li>dojox.off.ui.checkmarkImagePath：表示同步结束的图标</li>
</ul>
<p>例如，如果我们想将表示在线状态的绿色小圆球状图标替换为自己设计的图标，则可以修改如下：</p>
<p>dojox.off.ui.onlineImagePath = &#8220;images/myonlineball.png&#8221;;</p>
<p>最后，假如我们对默认的“Learn How”页面不甚满意的话，则还可以对 dojox/off/resources/learnhow.html 进行修改，其对应的 CSS 样式也定义与 dojox/off/resources/offline-widget.css 中。</p>
<p><a name="N102AC">性能问题</a></p>
<p>Dojo Offline 每次在对数据进行同步时，始终都会刷新缓存于本地的资源，这一点有可能会对同步的性能构成较大的影响，因为毕竟并非每一次同步都需要刷新所有的本地数据。为了提高同步的效率，Dojo Offline 提供了一种可选的方案，即由应用程序提供一个名为 version.js 的特殊文件，并将其置于应用程序的主路径下。假如该文件存在的话，则同步期间 Dojo Offline 会去读取该文件的内容，并判断其内容是否改变，以此来选择性的刷新本地缓存文件。</p>
<p>我们在 version.js 文件中所提供的内容其实非常简单，可以是一个字符串，也可以是一个数字，形式不限。例如：&#8221;03-15-2009.9&#8243;。只要能够让 Dojo Offline 判断出内容的变化即可。</p>
<p>除了同步时候的性能问题外，另一个可能会遇到的性能问题是数据的存储。当我们使用 Dojo SQL 来存储数据时，必须先将底层所依赖的 Google Gears 的存储数据库打开，而后才能进行数据的存储，而当数据存储完毕之后，还需将数据库关闭。通常情况下，我们并不需要关心这一点，因为 Dojo SQL 会自动为我们完成这一切，每次当我们执行一句 SQL 语句时，底层代码都会自动处理数据库的打开和关闭。</p>
<p>不过，假如我们是在批量的向本地缓存插入数据的话，比如在一个循环次数为上百次的 for 循环中执行数据插入操作，那么每执行一次 SQL 语句都要打开和关闭一次数据库或许是一种很低效做法。为了提高效率，我们可以在批量操作数据之前通过调用 dojox.sql.open() 手工将数据库打开，等所有操作完成之后后再通过调用 dojox.sql.close() 手工将其关闭。插入数据期间，Dojo SQL 会自动判断数据库的连接状态，并保持连接一直处于打开状态，直至手工关闭为止：<br />
<a name="N102C0"><strong>清单 16</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>var dataSet = getDataSet(); // get an array that has a bunch of data
//in it
dojox.sql.open();
for(var i = 0; i &lt; dataSet.length; i++){
 dojox.sql("INSERT INTO DOCUMENTS (fileName, content) VALUES (?, ?)",
 dataSet[i].fileName, dataSet[i].content);
}
dojox.sql.close();</pre>
</td>
</tr>
</tbody>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" alt="" width="100%" height="1" /><br />
<img src="http://www.ibm.com/i/c.gif" border="0" alt="" width="8" height="6" /></td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="0" align="right">
<tbody>
<tr align="right">
<td><img src="http://www.ibm.com/i/c.gif" alt="" width="100%" height="4" /></p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="middle"><img src="http://www.ibm.com/i/v14/icons/u_bold.gif" border="0" alt="" width="16" height="16" /></td>
<td align="right" valign="top"><a href="http://www.ibm.com/developerworks/cn/web/0906_dojo_offline_hehj/#main"><strong>回页首</strong></a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p><a name="6. 总结 |outline">总结</a></p>
<p>本文介绍了 Dojo Offline 的强大功能。通过阅读本文，读者能够了解到 Dojo Offline 的基本工作原理和一定的高级定制功能，从而掌握如何使用 Dojo Offline 进行 Web 离线应用程序开发的技能。</p>
<p>申明：</p>
<p>本文仅代表作者个人观点。</p>
<p><a name="resources">参考资料</a></p>
<p><strong>学习</strong></p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Dojo_Toolkit">Dojo 的 Wiki</a>：对 dojo 进行了全面的介绍，是一个入门的好地方。</li>
<li><a href="http://dojotoolkit.org/">Dojo 官方网站</a>：提供了最全面的资料，包括 dojo 源码，各种文档，实例等等。</li>
<li>参考 <a href="http://dojotoolkit.org/book/dojo-book-0-9/part-5-dojox/dojo-offline">Dojo offline</a> 官方文档。</li>
<li><a href="http://dojotoolkit.org/docs">Dojo 官方文档库</a>：在这里您可以找到全部和 Dojo 开发相关的文档资料。</li>
<li>参考 <a href="http://gears.google.com/">Google Gear</a> 相关文档，了解更多 Google Gear 的内容。</li>
<li>参考 W3C <a href="http://www.w3.org/TR/offline-webapps/">Offline Web Applications</a> 规范。</li>
<li><a href="http://www.ibm.com/developerworks/cn/web/wa-dojotoolkit/">developerWorks Dojo 专题</a>：汇集了大量与 Dojo 相关的技术资源。</li>
<li>通过 developerWorks <a href="http://www.ibm.com/developerworks/cn/web/">Web 开发专区</a> 内有关 Web 技术的文章和教程（包括本专栏之前的各期文章）扩展您的站点开发技能。</li>
</ul>
<p><strong>获得产品和技术</strong></p>
<ul>
<li><a href="http://www.ibm.com/developerworks/cn/downloads/">IBM 试用软件</a>：使用这些可直接从 developerWorks 下载的软件构建您的下一个开发项目。</li>
</ul>
<p><strong>讨论</strong></p>
<ul>
<li>通过参与 <a href="http://www.ibm.com/developerworks/blogs/?S_TACT=105AGX52&amp;S_CMP=cn-a-wa">developerWorks blog</a> 加入 developerWorks 社区。</li>
</ul>
<p><a name="author">作者简介</a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td colspan="3"><img src="http://www.ibm.com/i/c.gif" alt="" width="100%" height="5" /></td>
</tr>
<tr align="left" valign="top">
<td><img src="http://www.ibm.com/developerworks/cn/web/0906_dojo_offline_hehj/hehuijian.jpg" alt="/developerworks/cn/web/0906_dojo_offline_hehj/hehuijian.jpg" align="left" /></td>
<td><img src="http://www.ibm.com/i/c.gif" alt="" width="4" height="5" /></td>
<td width="100%">何辉剑，现在 IBM 中国软件开发实验室 Lotus 开发中心工作，目前从事 Lotus Quickr 的开发定制以及客户支持工作。对 Dojo，Web2.0 相关技术和社会化软件有丰富的经验。</td>
</tr>
</tbody>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td colspan="3"><img src="http://www.ibm.com/i/c.gif" alt="" width="100%" height="5" /></td>
</tr>
<tr align="left" valign="top">
<td><img src="http://www.ibm.com/developerworks/cn/web/0906_dojo_offline_hehj/zhangshun.jpg" alt="/developerworks/cn/web/0906_dojo_offline_hehj/zhangshun.jpg" align="left" /></td>
<td><img src="http://www.ibm.com/i/c.gif" alt="" width="4" height="5" /></td>
<td width="100%">张顺，现在 IBM 中国软件开发实验室 Lotus 开发中心工作，目前从事 Lotus Quickr 的开发定制以及客户支持工作。对 Web 服务，Web2.0 相关技术有浓厚的兴趣。</td>
</tr>
</tbody>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td colspan="3"><img src="http://www.ibm.com/i/c.gif" alt="" width="100%" height="5" /></td>
</tr>
<tr align="left" valign="top">
<td><img src="http://www.ibm.com/developerworks/cn/web/0906_dojo_offline_hehj/moying.jpg" alt="/developerworks/cn/web/0906_dojo_offline_hehj/moying.jpg" align="left" /></td>
<td><img src="http://www.ibm.com/i/c.gif" alt="" width="4" height="5" /></td>
<td width="100%">莫映，现在IBM中国软件开发实验室Lotus开发中心工作，目前从事Lotus Quickr的Platform Service开发。热衷于Web 2.0相关技术及智能Web 2.0应用的构建。</td>
</tr>
</tbody>
</table>
<h2  class="related_post_title">Other Posts / 其他文章</h2><ul class="related_post"><li><a href="http://slj.me/2009/11/free-hi-resolution-paint-stroke-photoshop-brushes/" title="免费的Photoshop高分辨率笔刷">免费的Photoshop高分辨率笔刷</a></li><li><a href="http://slj.me/2010/03/ultimate-guide-css-text-typography/" title="[转]CSS文字排版终极指南">[转]CSS文字排版终极指南</a></li><li><a href="http://slj.me/2010/07/css-rgba/" title="CSS中的RGBa色彩">CSS中的RGBa色彩</a></li><li><a href="http://slj.me/2009/05/scalable-inman-flash-replacement/" title="谈谈sIFR &#8211; 可伸缩Inman Flash替换">谈谈sIFR &#8211; 可伸缩Inman Flash替换</a></li><li><a href="http://slj.me/2009/10/design-at-facebook/" title="[译]Facebook是如何设计的">[译]Facebook是如何设计的</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2010/04/%e8%bd%ac%ef%bc%9a%e4%bd%bf%e7%94%a8-dojo-%e5%bc%80%e5%8f%91%e7%a6%bb%e7%ba%bf%e5%ba%94%e7%94%a8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[下载] Dojo 中文手册《实战Dojo工具包》PDF</title>
		<link>http://slj.me/2010/03/%e4%b8%8b%e8%bd%bd-dojo-%e4%b8%ad%e6%96%87%e6%89%8b%e5%86%8c%e3%80%8a%e5%ae%9e%e6%88%98dojo%e5%b7%a5%e5%85%b7%e5%8c%85%e3%80%8bpdf/</link>
		<comments>http://slj.me/2010/03/%e4%b8%8b%e8%bd%bd-dojo-%e4%b8%ad%e6%96%87%e6%89%8b%e5%86%8c%e3%80%8a%e5%ae%9e%e6%88%98dojo%e5%b7%a5%e5%85%b7%e5%8c%85%e3%80%8bpdf/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 09:22:01 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[pdf]]></category>

		<guid isPermaLink="false">http://slj.me/?p=1672</guid>
		<description><![CDATA[实战Dojo工具包 一个品质远远超出“原型建造”的Ajax库 点击下载PDF：Dojo中文手册 Related Posts / 相关文章【转】使用 Dojo 的 Ajax 应用开发进阶教程 : 富含语义的 HTML]]></description>
			<content:encoded><![CDATA[<h2>实战Dojo工具包</h2>
<p>一个品质远远超出“原型建造”的Ajax库</p>
<p><a href="http://slj.me/wp-content/uploads/2010/03/Dojo中文手册.pdf" target="_blank">点击下载PDF：Dojo中文手册</a></p>
<h2  class="related_post_title">Related Posts / 相关文章</h2><ul class="related_post"><li><a href="http://slj.me/2009/07/dojo-ajax-semanticize-html/" title="【转】使用 Dojo 的 Ajax 应用开发进阶教程 : 富含语义的 HTML">【转】使用 Dojo 的 Ajax 应用开发进阶教程 : 富含语义的 HTML</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2010/03/%e4%b8%8b%e8%bd%bd-dojo-%e4%b8%ad%e6%96%87%e6%89%8b%e5%86%8c%e3%80%8a%e5%ae%9e%e6%88%98dojo%e5%b7%a5%e5%85%b7%e5%8c%85%e3%80%8bpdf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用回车键提交网页表单的条件</title>
		<link>http://slj.me/2010/03/%e4%bd%bf%e7%94%a8%e5%9b%9e%e8%bd%a6%e9%94%ae%e6%8f%90%e4%ba%a4%e7%bd%91%e9%a1%b5%e8%a1%a8%e5%8d%95%e7%9a%84%e6%9d%a1%e4%bb%b6/</link>
		<comments>http://slj.me/2010/03/%e4%bd%bf%e7%94%a8%e5%9b%9e%e8%bd%a6%e9%94%ae%e6%8f%90%e4%ba%a4%e7%bd%91%e9%a1%b5%e8%a1%a8%e5%8d%95%e7%9a%84%e6%9d%a1%e4%bb%b6/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 16:03:51 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[回车]]></category>
		<category><![CDATA[表单]]></category>

		<guid isPermaLink="false">http://slj.me/2010/03/%e4%bd%bf%e7%94%a8%e5%9b%9e%e8%bd%a6%e9%94%ae%e6%8f%90%e4%ba%a4%e7%bd%91%e9%a1%b5%e8%a1%a8%e5%8d%95%e7%9a%84%e6%9d%a1%e4%bb%b6/</guid>
		<description><![CDATA[回车键提交表单是我们经常操作的一个动作，而什么条件下能使回车键提交却很少有人关心！ 我们有时候希望回车键敲在文本框（input element）里来提交表单（form），但有时候又不希望如此。比如搜索行为，希望输入完关键词之后直接按回车键立即提交表单，而有些复杂表单，可能要避免回车键误操作在未完成表单填写的时候就触发了表单提交。 要控制这些行为，不需要借助JS，浏览器已经帮我们做了这些处理，这里总结几条规则： 1、如果表单里有一个type=”submit”的按钮，回车键生效。 2、如果表单里只有一个type=”text”的input，回车键生效。 3、如果按钮不是用input，而是用button，并且没有加type，IE下默认为type=button，FX默认为type=submit。 4、其他表单元素如textarea、select不影响。 实际应用的时候，要让表单响应回车键很容易，保证表单里有个type=”submit”的按钮就行。而当只有一个文本框又不希望响应回车键怎么办呢？我的方法有点别扭，就是再写一个无意义的文本框，隐藏起来。根据第4条规则，我们在用button的时候，尽量显式声明type以使浏览器表现一致。 一个demo，列出了一些例子 Other Posts / 其他文章JavaScript 图片切割效果 转：使用 Dojo 开发离线应用找出 MySQL 里哪些查询 Query 速度较慢CSS在Internet Explorer 6, 7 和8中的差别从Kiya.cn到slj.me]]></description>
			<content:encoded><![CDATA[<div id="content_body">
<p>回车键提交表单是我们经常操作的一个动作，而什么条件下能使回车键提交却很少有人关心！</p>
<p>我们有时候希望回车键敲在文本框（input element）里来提交表单（form），但有时候又不希望如此。比如搜索行为，希望输入完关键词之后直接按回车键立即提交表单，而有些复杂表单，可能要避免回车键误操作在未完成表单填写的时候就触发了表单提交。</p>
<p>要控制这些行为，不需要借助JS，浏览器已经帮我们做了这些处理，这里总结几条规则：<br />
1、如果表单里有一个type=”submit”的按钮，回车键生效。<br />
2、如果表单里只有一个type=”text”的input，回车键生效。<br />
3、如果按钮不是用input，而是用button，并且没有加type，IE下默认为type=button，FX默认为type=submit。<br />
4、其他表单元素如textarea、select不影响。</p>
<p>实际应用的时候，要让表单响应回车键很容易，保证表单里有个type=”submit”的按钮就行。而当只有一个文本框又不希望响应回车键怎么办呢？我的方法有点别扭，就是再写一个无意义的文本框，隐藏起来。根据第4条规则，我们在用button的时候，尽量显式声明type以使浏览器表现一致。</p>
<p>一个<a href="http://ued.koubei.com/wp-content/uploads/2009/01/submit.html">demo</a>，列出了一些例子</p>
</div>
<h2  class="related_post_title">Other Posts / 其他文章</h2><ul class="related_post"><li><a href="http://slj.me/2009/08/%e3%80%90%e8%bd%ac%e3%80%91%e9%a9%ac%e4%ba%91%e7%bb%99%e6%ad%a3%e5%9c%a8%e5%a5%8b%e6%96%97%e7%9a%84%e4%ba%ba%e7%9a%84%e7%b2%be%e5%85%b8%e8%af%ad%e5%8f%a5/" title="【转】马云给正在奋斗的人的精典语句">【转】马云给正在奋斗的人的精典语句</a></li><li><a href="http://slj.me/2009/10/method-to-uncover-google-gmail-google-reader-for-iphone/" title="揭开iPhone版Google，Gmail，Google Reader神秘面纱的方法">揭开iPhone版Google，Gmail，Google Reader神秘面纱的方法</a></li><li><a href="http://slj.me/2009/04/hosting-completed/" title="空间总算是弄好了">空间总算是弄好了</a></li><li><a href="http://slj.me/2009/09/compatible-with-ie6-css-picture-middle-vertical-align/" title="完美兼容IE6，摆脱table用CSS实现图片垂直居中">完美兼容IE6，摆脱table用CSS实现图片垂直居中</a></li><li><a href="http://slj.me/2010/01/theme-upgrade-advice-for-meeplace-2-4/" title="Theme Upgrade Advice For MeePlace 2.4">Theme Upgrade Advice For MeePlace 2.4</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2010/03/%e4%bd%bf%e7%94%a8%e5%9b%9e%e8%bd%a6%e9%94%ae%e6%8f%90%e4%ba%a4%e7%bd%91%e9%a1%b5%e8%a1%a8%e5%8d%95%e7%9a%84%e6%9d%a1%e4%bb%b6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[英,转]45个新鲜有用的JS与jQuery技术和工具</title>
		<link>http://slj.me/2010/03/45-fresh-useful-javascript-and-jquery-techniques-and-tools/</link>
		<comments>http://slj.me/2010/03/45-fresh-useful-javascript-and-jquery-techniques-and-tools/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 06:10:09 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[工具]]></category>

		<guid isPermaLink="false">http://slj.me/?p=1617</guid>
		<description><![CDATA[45 Fresh Useful JavaScript and jQuery Techniques and Tools Yes, this is another round-up of fresh and useful Javascript techniques, tools and resources. But don’t close the tab yet, as you might find this one very useful. In this selection we present calendars, forms, buttons, navigation, debugging, optimization and compatibility tables as well as handy [...]]]></description>
			<content:encoded><![CDATA[<h2>45 Fresh Useful JavaScript and jQuery Techniques and Tools</h2>
<p>Yes, this is another round-up of <strong>fresh and useful Javascript techniques, tools and resources</strong>. But don’t close the tab yet, as you might find this one very useful. In this selection we present calendars, forms, buttons, navigation, debugging, optimization and compatibility tables as well as handy resources and tools. We also cover various jQuery-plugins that will help you extend the functionality of your website and improve user experience with ready components or coding solutions.</p>
<p>The last section also covers a number of useful educational resources such as a compilation of useful JavaScript coding practices, a detailed comparison of JavaScript frameworks and general JavaScript programming conventions. We are looking forward to your feedback.</p>
<p><span id="more-1617"></span>You may be interested in the following related posts:</p>
<ul>
<li><a rel="external nofollow" href="http://www.smashingmagazine.com/2009/06/21/50-fresh-javascript-tools-that-will-improve-your-workflow/">50 Fresh JavaScript Tools That Will Improve Your Workflow</a></li>
<li><a rel="external nofollow" href="http://www.smashingmagazine.com/2010/01/12/45-powerful-css-javascript-techniques/">45 Powerful CSS/JavaScript-Techniques</a></li>
<li><a rel="external nofollow" href="http://www.smashingmagazine.com/2009/03/08/70-new-useful-ajax-and-javascript-techniques/">70 Useful AJAX And JavaScript Techniques</a></li>
</ul>
<p>[By the way, did you know there is a brand new <a rel="external nofollow" href="http://creatives.commindo-media.de/www/delivery/ck.php?oaparams=2__bannerid=1339__zoneid=0__cb=a279a7c66d__oadest=http%3A%2F%2Fshop.smashingmagazine.com%2Fsmashingbook-dispatcher.php%3Fd%3Dsmashing-wordpress%26utm_source%3DSmashing%252BMagazine%26utm_medium%3Deditorialbox2%26utm_campaign%3DSmashing%252BWordPress%2520-%2520BTW%2520Editorial%2520Box">Smashing WordPress Book</a>? Push WordPress past its limits!]</p>
<h3>Calendars and Timelines</h3>
<p><a rel="external nofollow" href="http://www.radoslavdimov.com/jquery-plugins/jquery-plugin-digiclock/">jDigiClock – Digital Clock (HTC Hero inspired)</a><br />
jDigiClock is a jQuery plugin inspired from HTC Hero Clock Widget.</p>
<p><a rel="external nofollow" href="http://www.radoslavdimov.com/jquery-plugins/jquery-plugin-digiclock/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-82.jpg" alt="Javascript-techniques-82 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://home.comcast.net/~vonholdt/test/clock_slide/index.htm">jQuery Sliding Clock v1.1</a><br />
jQuery transpearant Slider clock with CSS sprites.</p>
<p><a rel="external nofollow" href="http://home.comcast.net/~vonholdt/test/clock_slide/index.htm"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-67.jpg" alt="Javascript-techniques-67 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://home.jongsma.org/software/js/datepicker">Date / Time Picker</a><br />
Note that this control is not designed to work in IE6; although it will function correctly in most cases, the positioning of the calendar may be way off depending on how your page is styled.</p>
<p><a rel="external nofollow" href="http://home.jongsma.org/software/js/datepicker"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-05.jpg" alt="Javascript-techniques-05 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<h3>JavaScript Debugging and Validation Tools</h3>
<p><a rel="external nofollow" href="http://www.mozilla.org/projects/venkman/">Venkman JavaScript Debugger project page</a><br />
Venkman is the code name for Mozilla’s JavaScript Debugger. Venkman aims to provide a powerful JavaScript debugging environment for Gecko-based browsers namely Firefox 3.x, the Netscape 7.x series of browsers, Netscape 9.x series, Mozilla Seamonkey 1.x and Mozilla Seamonkey 2.x. It does not include Gecko-based browsers such as K-Meleon 1.x, Galeon 2.x and Netscape 8.x. The debugger is available as an add-on package in XPI format. Venkman JavaScript Debugger has been provided as part of the Mozilla install distribution since October 3rd 2001.</p>
<p><a rel="external nofollow" href="http://www.mozilla.org/projects/venkman/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-14.jpg" alt="Javascript-techniques-14 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://www.my-debugbar.com/wiki/CompanionJS/HomePage">CompanionJS</a><br />
Companion.JS (pronounced Companion dot JS or CJS) is a Javascript debugger for IE.</p>
<p><a rel="external nofollow" href="http://www.my-debugbar.com/wiki/CompanionJS/HomePage"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-32.jpg" alt="Javascript-techniques-32 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://net.tutsplus.com/tutorials/javascript-ajax/how-to-test-your-javascript-code-with-qunit/">How to Test your JavaScript Code with QUnit</a><br />
QUnit is a powerful JavaScript unit testing framework that helps you to debug code. It’s written by members of the jQuery team, and is the official test suite for jQuery. But QUnit is general enough to test any regular JavaScript code, and it’s even able to test server-side JavaScript via some JavaScript engine like Rhino or V8.</p>
<p><a rel="external nofollow" href="http://net.tutsplus.com/tutorials/javascript-ajax/how-to-test-your-javascript-code-with-qunit/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-44.jpg" alt="Javascript-techniques-44 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://jsbin.com/">JS Bin – Collaborative JavaScript Debugging</a><br />
JS Bin is an open source collaborative JavaScript debugging tool.</p>
<p><a rel="external nofollow" href="http://jsbin.com/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-12.jpg" alt="Javascript-techniques-12 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<h3>Forms, Buttons &amp; Navigation</h3>
<p><a rel="external nofollow" href="http://tutorialzine.com/2009/10/google-wave-history-slider-jquery/">Making a Google Wave History Slider</a><br />
Here is shown how to create a Google Wave-like history slider. Using it will enable visitors to go back and forth in time to view the changes that take place on a comment thread.</p>
<p><a rel="external nofollow" href="http://tutorialzine.com/2009/10/google-wave-history-slider-jquery/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-73.jpg" alt="Javascript-techniques-73 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://theodin.co.uk/blog/design/fancy-radio-buttons-jquery.html">Fancy Radio Buttons With jQuery</a><br />
Creation of 2 mandatory option sets that a user could choose, while hiding off the radio button inputs and using an anchor links to make it a bit more usable.</p>
<p><a rel="external nofollow" href="http://theodin.co.uk/blog/design/fancy-radio-buttons-jquery.html"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-62.jpg" alt="Javascript-techniques-62 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://www.tutorial9.net/web-tutorials/creative-button-animations-with-sprites-and-jquery-part-2/">Creative Button Animations with Sprites and JQuery</a><br />
Fading hover effect for which the transition is smoothed with JavaScript, using jQuery library.</p>
<p><a rel="external nofollow" href="http://www.tutorial9.net/web-tutorials/creative-button-animations-with-sprites-and-jquery-part-2/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-83.jpg" alt="Javascript-techniques-83 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://www.vileworks.com/password-unmasking">Password (un)Masking</a><br />
JavaScript jQuery that toggles the masking and unmasking of the password field.</p>
<p><a rel="external nofollow" href="http://www.vileworks.com/password-unmasking"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-68.jpg" alt="Javascript-techniques-68 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://css-tricks.com/jquery-magicline-navigation/">jQuery MagicLine Navigation</a><br />
These “sliding” style navigation bars have been around a while, and turns out it’s really pretty darn easy. Here are put two examples together.</p>
<p><a rel="external nofollow" href="http://css-tricks.com/jquery-magicline-navigation/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-49.jpg" alt="Javascript-techniques-49 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://tympanus.net/codrops/2009/12/11/fixed-fade-out-menu-a-css-and-jquery-tutorial/">Fixed Fade Out Menu: A CSS and jQuery Tutorial</a><br />
The aim is to have a fixed navigation that follows the user when he scrolls, and only subtly showing itself by fading out and becoming almost transparent. When the user hovers over it, the menu then becomes opaque again. Inside of the navigation we will have some links, a search input and a top and bottom button that let the user navigate to the top or the bottom of the page.</p>
<p><a rel="external nofollow" href="http://tympanus.net/codrops/2009/12/11/fixed-fade-out-menu-a-css-and-jquery-tutorial/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-52.jpg" alt="Javascript-techniques-52 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://cssglobe.com/post/7161/jquery-plugin-simplest-twitterlike-dynamic-character-count-for-textareas">jQuery plugin: Simplest Twitter-like dynamic character count for textareas and input fields</a><br />
The best way to explain what this plugin does is to mention Twitter. Twitter posts are limited to 140 characters. While typing the Twitter post there is this always present information about how many characters the users have before reaching the limit. The information is not only provided merely by displaying a number, there are different colors applied to certain stages to notify the user about the status.</p>
<p><a rel="external nofollow" href="http://www.csskarma.com/blog/sliding-labels-v2/">Sliding Labels v2</a><br />
Form label keeping the label inline, but sliding it off to the left rather than going away on click.</p>
<p><a rel="external nofollow" href="http://www.csskarma.com/blog/sliding-labels-v2/"><img src="http://media.smashingmagazine.com/cdn_smash/wp-content/uploads/2010/03/javascript-techniques-87.jpg" alt="Javascript-techniques-87 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="100" /></a></p>
<p><a rel="external nofollow" href="http://demos.usejquery.com/ketchup-plugin/index.html">Ketchup Plugin</a><br />
Ketchup is a slim jQuery Plugin that validates your forms. It aims to be very flexible and extendable for its appearance and functionality.</p>
<p><a rel="external nofollow" href="http://demos.usejquery.com/ketchup-plugin/index.html"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-84.jpg" alt="Javascript-techniques-84 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<h3>Layout tools</h3>
<p><a rel="external nofollow" href="http://www.kromosome.net/cssdesignergrid/">jQuery {css}designerGrid Plugin</a><br />
{css} designerGrid is A jQuery Plugin developed for website interface developers who use the grid system of layout. {css} designerGrid is intended to assist these developers with CSS prototyping.</p>
<p><a rel="external nofollow" href="http://www.kromosome.net/cssdesignergrid/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-80.jpg" alt="Javascript-techniques-80 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://code.google.com/p/css-template-layout/">css-template-layout</a><br />
JavaScript (jQuery) implementation of the CSS Template Layout Module</p>
<p><a rel="external nofollow" href="http://code.google.com/p/css-template-layout/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-33.jpg" alt="Javascript-techniques-33 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://blog.creativityden.com/fluid-grid-using-jquery/">How to create a fluid grid with jQuery</a><br />
Grid-based layout is probably the more preferred way to style up a webpage to give it more magazine-like look and feel. This tutorial is about how to use CSS and Javascript to create a fluid grid-based layout (See demo here). The algorithm/procedure used in this tutorial is very simple and straightforward. There are more advanced algorithms out there which can handle multiple scenarios. But the purpose is to understand the basic logic on how to create such layout. So here it goes…</p>
<p><a rel="external nofollow" href="http://blog.creativityden.com/fluid-grid-using-jquery/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-51.jpg" alt="Javascript-techniques-51 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://code.google.com/p/closure-templates/">closure-templates</a><br />
Closure Templates are a client- and server-side templating system that helps you dynamically build reusable HTML and UI elements. They are easy to learn and customizable to fit your application’s needs. Closure Templates support JavaScript and Java and use a data model and expression syntax that works for either language. You can also use the built-in message support to easily localize your applications.</p>
<p><a rel="external nofollow" href="http://code.google.com/p/closure-templates/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-46.jpg" alt="Javascript-techniques-46 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<h3>Useful jQuery Plugins</h3>
<p><a rel="external nofollow" href="http://code.drewwilson.com/entry/tiptip-jquery-plugin">TipTip jQuery Plugin</a><br />
TipTip detects the edges of the browser window and will make sure the tooltip stays within the current window size. As a result the tooltip will adjust itself to be displayed above, below, to the left or to the right of the element with TipTip applied to it, depending on what is necessary to stay within the browser window. TipTip is a very lightweight and intelligent custom tooltip jQuery plugin. It uses ZERO images and is completely customizable via CSS. It’s also only 3.5kb minified!</p>
<p><a rel="external nofollow" href="http://code.drewwilson.com/entry/tiptip-jquery-plugin"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-65.jpg" alt="Javascript-techniques-65 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://fredhq.com/projects/roundabout/">jQuery Roundabout</a><br />
Roundabout is a jQuery plugin that converts a structure of static HTML elements into a highly customizable turntable-like interactive area. (And now, not just turntables, but many shapes!)</p>
<p><a rel="external nofollow" href="http://fredhq.com/projects/roundabout/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-69.jpg" alt="Javascript-techniques-69 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://jparse.kylerush.net/">jParse – jQuery XML Parse Plugin</a><br />
jParse is a jQuery plugin that allows you to parse XML that was fetched with the jQuery .ajax method (making it fully customizable).</p>
<p><a rel="external nofollow" href="http://jparse.kylerush.net/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-72.jpg" alt="Javascript-techniques-72 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://razorjack.net/quicksand/">jQuery Quicksand plugin</a><br />
Reorder and filter items with a nice shuffling animation.</p>
<p><a rel="external nofollow" href="http://razorjack.net/quicksand/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-48.jpg" alt="Javascript-techniques-48 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://thinkinginweb.com/sections/articles/18-11-2009-typeQuery-change-website-typography-with-jquery.aspx">typeQuery, change website typography with jquery</a><br />
typeQuery gives the flexibility to change the font-family for everything you define with class, id, or tag, this example is referring to the selected item on a select object with id=”tag” and the font-family value at select object with id=”family”: <code>$($("#tag").val()).css("font-family", $("#family").val());</code></p>
<p><a rel="external nofollow" href="http://thinkinginweb.com/sections/articles/18-11-2009-typeQuery-change-website-typography-with-jquery.aspx"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-70.jpg" alt="Javascript-techniques-70 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://lab.smashup.it/flip/">Flip! A jQuery plugin v0.9.9</a><br />
Flip is a jQuery plugin that will flip easily your elements in four directions.</p>
<p><a rel="external nofollow" href="http://lab.smashup.it/flip/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-55.jpg" alt="Javascript-techniques-55 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://www.webresourcesdepot.com/data-encryption-with-javascript-jcryption/">Data Encryption With JavaScript: jCryption</a><br />
jCryption is a jQuery plugin for encrypting POST/GET data submitted by forms. It uses public-key algorithm of RSA for the encryption &amp; has a PHP file for handling the decryption of data.</p>
<p><a rel="external nofollow" href="http://www.webresourcesdepot.com/data-encryption-with-javascript-jcryption/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-24.jpg" alt="Javascript-techniques-24 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://trif3cta.com/blog/entry/jquery-plugins-under-4k/">Minimalist jQuery: 11 useful plugins under 4K</a><br />
jQuery makes our lives easier. So much so that it’s tempting to use it all the time, inadvertently slowing our page load times (cue <a rel="external nofollow" href="http://developer.yahoo.com/yslow/">YSlow</a> and <a rel="external nofollow" href="http://stevesouders.com/hammerhead/">Hammerhead</a>). Combining, compressing, and delivering scripts at the end of your page helps in the HTTP request department. On the file size front, below are jQuery plugins that give solid bang for your performance buck.</p>
<p><a rel="external nofollow" href="http://trif3cta.com/blog/entry/jquery-plugins-under-4k/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-79.jpg" alt="Javascript-techniques-79 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://jscott.me/jquery.undoable.html">Undo/Redo in jQuery</a><br />
An easy-to-use plugin for adding undo/redo capabilities to a jQuery application. It is based loosely on the Objective-C/Cocoa way of doing things.</p>
<p><a rel="external nofollow" href="http://jscott.me/jquery.undoable.html"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-81.jpg" alt="Javascript-techniques-81 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://code.google.com/p/editease/">editease</a><br />
editEase – jQuery CMS | no fuss, no database, no worries</p>
<p><a rel="external nofollow" href="http://code.google.com/p/editease/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-78.jpg" alt="Javascript-techniques-78 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://www.jgc.org/blog/2009/10/what-is-jshub.html">jsHub</a><br />
jsHub is a single piece of JavaScript (a “tag”) that can handle reading different sorts of page information and then send them to many different vendors’ products. One piece of code to send to Google Analytics, Omniture SiteCatalyst, WebTrends and Mixpanel. Instead of one piece of JavaScript per vendor, jsHub has a single piece of code (the “hub”) and plugins that know how to translate into the required wire protocol for each vendor. Vendors only maintain the plugin for their product.</p>
<p><a rel="external nofollow" href="http://www.jgc.org/blog/2009/10/what-is-jshub.html"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-22.jpg" alt="Javascript-techniques-22 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<h3>Educational JavaScript Resources and Tutorials</h3>
<p><a rel="external nofollow" href="http://justin.harmonize.fm/index.php/2009/09/an-introduction-to-javascripts-this/">Caffeinated Simpleton </a><br />
JavaScript is an amazing little language, but it’s got some quirks that turn a lot of people off. One of those quirks is <code>this</code>, and how it’s not necessarily what you expect it to be. <code>this</code> isn’t that complicated, but there are very few explanations of how it works on the internet. This article is an attempt to explain how <code>this</code> works and how to use it properly.</p>
<p><a rel="external nofollow" href="http://justin.harmonize.fm/index.php/2009/09/an-introduction-to-javascripts-this/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-07.jpg" alt="Javascript-techniques-07 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://www.smashingmagazine.com/2009/08/01/what-you-need-to-know-about-javascript-scope/">What You Need To Know About JavaScript Scope</a><br />
This article discusses how JavaScript handles scope and how various JavaScript libraries provide methods for dealing with it and how they smooth out a few bumps. We’ll also look at how you can get back to basics and do some interesting scope wrangling without a library, a useful approach if you’re writing code that needs to stand alone.</p>
<p><a rel="external nofollow" href="http://www.smashingmagazine.com/2009/08/01/what-you-need-to-know-about-javascript-scope/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-25.jpg" alt="Javascript-techniques-25 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://ejohn.org/apps/learn/">Learning Advanced JavaScript</a><br />
A very nice tutorial to learn JavaScript, containing code and discussion from the upcoming book Secrets of the JavaScript Ninja by John Resig.</p>
<p><a rel="external nofollow" href="http://ejohn.org/apps/learn/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-30.jpg" alt="Javascript-techniques-30 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://www.brucelawson.co.uk/2010/highlight-search-terms-automagically-with-javascript-and-mark/">Highlight search terms automagically with JavaScript and mark</a><br />
Script surrounding the search term(s) with the <code>mark</code> element rather than a <code>span</code>, although the class <var>searchword</var> is retained in case you want to style these <code>mark</code>s differently from others. In the CSS, the rule <code>article mark </code>is just added to turn it a gentle shade of pink.</p>
<p><a rel="external nofollow" href="http://net.tutsplus.com/tutorials/javascript-ajax/10-super-helpful-traversing-functions-in-jquery/">10 Really Helpful Traversing Functions in jQuery</a><br />
With jQuery, selecting HTML elements is laughably easy. But at times, we may wish to further refine the selection, which can be a hassle when the HTML structure is complicated. In this tutorial, we’ll explore ten ways that we can refine and extend a set of wrapped elements that we wish to operate upon.</p>
<p><a rel="external nofollow" href="http://net.tutsplus.com/tutorials/javascript-ajax/10-super-helpful-traversing-functions-in-jquery/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-74.jpg" alt="Javascript-techniques-74 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://www.catswhocode.com/blog/using-keyboard-shortcuts-in-javascript">Using keyboard shortcuts in Javascript</a><br />
If you want to enhance your web app, Javascript keyboards shortcuts is definitely something to consider. In this article, you’ll learn to use JS keyboard shortcuts, with and without the JQuery framework.</p>
<p><a rel="external nofollow" href="http://www.catswhocode.com/blog/using-keyboard-shortcuts-in-javascript"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-29.jpg" alt="Javascript-techniques-29 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://javascript.crockford.com/code.html">Code Conventions for the JavaScript Programming Language</a><br />
This is a set of coding conventions and rules for use in JavaScript programming.</p>
<p><a rel="external nofollow" href="http://javascript.crockford.com/code.html"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-31.jpg" alt="Javascript-techniques-31 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://www.myphpetc.com/2009/03/jquery-select-element-cheat-sheet.html">jQuery – Select element cheat sheet</a><br />
This cheat sheet helps you to find the index of a selected option, set the selected option by value, set the selected option by text, insert a new option before or after another and get the text or value of the selected option.</p>
<p><a rel="external nofollow" href="http://www.myphpetc.com/2009/03/jquery-select-element-cheat-sheet.html"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-76.jpg" alt="Javascript-techniques-76 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://www.ibm.com/developerworks/web/library/wa-jsframeworks/index.html">Compare JavaScript frameworks</a><br />
Modern Web sites and Web applications tend to rely quite heavily on client-side JavaScript to provide rich interactivity, particularly through the advent of asynchronous HTTP requests that do not require page refreshes to return data or responses from a server-side script or database system. In this article, you will discover how JavaScript frameworks make it easier and faster to create highly interactive and responsive Web sites and Web applications.</p>
<p><a rel="external nofollow" href="http://www.ibm.com/developerworks/web/library/wa-jsframeworks/index.html"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-77.jpg" alt="Javascript-techniques-77 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://dailyjs.com/2010/01/27/pro-practices-1/">Park your Horse, Code Cowboy: Professional JavaScript Workflows, Part 1</a><br />
In this series, we’ll talk about tools &amp; techniques you can use to cover those No’s, and cut a lot of strife &amp; embarrassment from your JavaScript experience.</p>
<p><a rel="external nofollow" href="http://dailyjs.com/2010/01/27/pro-practices-1/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-47.jpg" alt="Javascript-techniques-47 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://www.java2s.com/Code/JavaScriptReference/CatalogJavaScriptReference.htm">JavaScript Reference examples (example source code)</a><br />
JavaScript Reference examples, organized by Objects, Properties, Methods &amp; Collections. Some Event Handlers Reference are also available.</p>
<p><a rel="external nofollow" href="http://www.java2s.com/Code/JavaScriptReference/CatalogJavaScriptReference.htm"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-20.jpg" alt="Javascript-techniques-20 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://dev.opera.com/articles/view/javascript-best-practices/">JavaScript best practices</a><br />
A compilation of best practices and good advice I’ve amassed over the years, much of it learnt the hard way (experimentation and suchlike). Take the advice below to heart and keep it in a part of your brain that has a quick access route so you can apply it without thinking about it. I am sure you will find things to disagree with, and that is a good thing – you should question what you read, and strive to find better solutions. However, I have found that following these principles has made me a more effective developer and allowed other developers to build upon my work more easily.</p>
<p><a rel="external nofollow" href="http://dev.opera.com/articles/view/javascript-best-practices/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-15.jpg" alt="Javascript-techniques-15 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p><a rel="external nofollow" href="http://wtfjs.com/">wtfjs</a><br />
JavaScript is a language we love despite it giving us so much to hate. This is a collection of those very special irregularities, inconstancies and just plain painfully unintuitive moments for the language of the web.</p>
<p><a rel="external nofollow" href="http://wtfjs.com/"><img src="http://slj.me/wp-content/uploads/2010/03/javascript-techniques-41.jpg" alt="Javascript-techniques-41 in 45 Fresh Useful JavaScript and jQuery Techniques and Tools" width="480" height="300" /></a></p>
<p>转自：http://www.smashingmagazine.com/2010/03/12/45-fresh-useful-javascript-and-jquery-techniques-and-tools/</p>
<h2  class="related_post_title">Related Posts / 相关文章</h2><ul class="related_post"><li><a href="http://slj.me/2009/04/jquery-float-menu/" title="一个利用jQuery实现菜单跟随页面滚动而移动的代码">一个利用jQuery实现菜单跟随页面滚动而移动的代码</a></li><li><a href="http://slj.me/2009/04/dreamweaver-jquery-code-association/" title="在Dreamweaver中加入jQuery代码编写联想提示">在Dreamweaver中加入jQuery代码编写联想提示</a></li><li><a href="http://slj.me/2009/03/galleriffic-jquery/" title="Galleriffic-jQuery相片展示插件">Galleriffic-jQuery相片展示插件</a></li><li><a href="http://slj.me/2009/03/nyromodal-jquery-plugin/" title="NyroModal-jQuery的一个遮罩层插件">NyroModal-jQuery的一个遮罩层插件</a></li><li><a href="http://slj.me/2010/12/javascript-select-operations/" title="JavaScript 操作select控件大全（新增、修改、删除、选中、清空、判断存在等）">JavaScript 操作select控件大全（新增、修改、删除、选中、清空、判断存在等）</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2010/03/45-fresh-useful-javascript-and-jquery-techniques-and-tools/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>【好书PDF】：Building iPhone Apps with HTML, CSS, and JavaScript</title>
		<link>http://slj.me/2010/03/building-iphone-apps-with-html-css-and-javascript/</link>
		<comments>http://slj.me/2010/03/building-iphone-apps-with-html-css-and-javascript/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 13:13:40 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[iPhone/Android]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://slj.me/?p=1524</guid>
		<description><![CDATA[出版商: Oreilly &#124; ISBN: 0596805780 &#124; 2010年1月  &#124; PDF &#124; 192页 &#124; 2.8 Mb It’s a fact: if you know HTML, CSS, and JavaScript, you already have the tools you need to develop your own iPhone apps. With this book, you’ll learn how to use these open source web technologies to design and build apps [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://api.photoshop.com/home_8bb0df3698f64d62b5ee0a0a29be8bd1/adobe-px-assets/a066bab4ab804921937ffbe2fa980087" border="0" alt="点击查看下载大图-QuanPC.com全品网" width="320" height="480" /></p>
<p>出版商: Oreilly | ISBN: 0596805780 | 2010年1月  | PDF | 192页 | 2.8 Mb</p>
<p>It’s a fact: if you know HTML, CSS, and JavaScript, you already have the tools you need to develop your own iPhone apps. With this book, you’ll learn how to use these open source web technologies to design and build apps for the iPhone and iPod Touch on the platform of your choice-without using Objective-C or Cocoa.</p>
<p><span id="more-1524"></span>Device-agnostic mobile apps are the wave of the future, and this book shows you how to create one product for several platforms. You’ll find guidelines for converting your product into a native iPhone app using the free PhoneGap framework. And you’ll learn why releasing your product as a web app first helps you find, fix, and test bugs much faster than if you went straight to the App Store with a product built with Apple’s tools.</p>
<p>* Build iPhone apps with tools you already know how to use<br />
* Learn how to make an existing website look and behave like an iPhone app<br />
* Add native-looking animations to your web app using jQTouch<br />
* Take advantage of client-side data storage with apps that run even when the iPhone is offline<br />
* Hook into advanced iPhone features — including the accelerometer, geolocation, and vibration — with JavaScript<br />
* Submit your applications to the App Store with Xcode</p>
<p>PDF下载：</p>
<p><a href="http://rs773.rapidshare.com/files/342236383/Oreilly.Building.iPhone.Apps.with.HTML.CSS.and.JavaScript.Jan.2010.rar" target="_blank">Oreilly.Building.iPhone.Apps.with.HTML.CSS.and.JavaScript.Jan.2010.rar</a></p>
<h2  class="related_post_title">Related Posts / 相关文章</h2><ul class="related_post"><li><a href="http://slj.me/2010/05/html5-new-features/" title="HTML5新功能演示">HTML5新功能演示</a></li><li><a href="http://slj.me/2009/12/html5-css3/" title="揭秘HTML5和CSS3">揭秘HTML5和CSS3</a></li><li><a href="http://slj.me/2009/12/%e7%89%9bx%e6%97%a0%e6%95%8c%ef%bc%81%ef%bc%81%ef%bc%81zen-coding-%e4%b8%80%e7%a7%8d%e5%bf%ab%e9%80%9f%e7%bc%96%e5%86%99htmlcss%e4%bb%a3%e7%a0%81%e7%9a%84%e6%96%b9%e6%b3%95/" title="转牛X无敌！！！Zen Coding: 一种快速编写HTML/CSS代码的方法">转牛X无敌！！！Zen Coding: 一种快速编写HTML/CSS代码的方法</a></li><li><a href="http://slj.me/2009/04/dreamweaver-jquery-code-association/" title="在Dreamweaver中加入jQuery代码编写联想提示">在Dreamweaver中加入jQuery代码编写联想提示</a></li><li><a href="http://slj.me/2009/03/browser_css_hack_ie_ff/" title="关于一些浏览器的的Hack">关于一些浏览器的的Hack</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2010/03/building-iphone-apps-with-html-css-and-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[原创]多选/全选checkbox，AJAX提交。另附IE的onchange BUG</title>
		<link>http://slj.me/2010/03/multiple-selectable-checkbox-ajax-submit/</link>
		<comments>http://slj.me/2010/03/multiple-selectable-checkbox-ajax-submit/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 06:50:17 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[checkbox]]></category>
		<category><![CDATA[MeePlace]]></category>
		<category><![CDATA[onchange]]></category>

		<guid isPermaLink="false">http://slj.me/?p=1501</guid>
		<description><![CDATA[最近在为MeePlace 2.7的后台编写多选功能。在一个接一个的版本中，MeePlace的后台是越来越强大了（不够谦虚，hoho），后台采用纯ajax异步（有的时候觉得编程会有点麻烦，但是从1.0开始就是这样的后台，现在要改的话也麻烦，况且AJAX能给用户带来更好的体验，就继续开发吧：D） 这次后台增加的功能中，有一个是能够多选/全选项目，这个已经是历史遗留问题了，在我所有开发的项目中都是用这套自己开发的后台系统，改一改就成。这次布莱恩吧multi-selectable列在了Milestone里，所以就写了。以前有做过多选，不过由于是原始form的post，所以比较简单。这次用AJAX的后台多选操作，我还是想了一下才开始动手的。 我的想法是，通过遍历checkbox，来得到有被选定了的checkbox的value，然后再传给后端进行多选处理。 下面公开MeePlace的这部分代码。 全选按钮。用户点击全选的那个checkbox后，checkbox的onclick=&#8221;select_item_all(this,&#8221;allitem&#8221;,&#8221;childitem&#8221;)&#8221; 其中&#8221;allitem&#8221;是全选的checkbox的classname，因为也许这个全选会出现两个，或者更多，比如表头和表尾各一。 &#8220;childitem&#8221;是所有的条目前的checkbox的classname。 JS代码： //全选按钮 function select_item_all(whochecked,allitem,childitem) { if(whochecked==true) { $('.'+allitem).attr('checked',true); $('.'+childitem).attr('checked',true); $('.itemtr').addClass('trselected'); } else { $('.'+allitem).attr('checked',false); $('.'+childitem).attr('checked',false); $('.itemtr').removeClass('trselected'); } } 这样通过判断提交全选的checkbox是否被勾选，来达到全选目的。 下面的代码是点击&#8221;Delete selected&#8221;（“删除所选”）之后，扫描所选中的checkbox的value以及发出警告和异步提交的代码 JS代码： function delselected(sheet,where,childitem) { //通过扫描制定childitem（项目前的checkbox的classname），来获取选中了的项目IDs var selected_ids=''; var obj=$("input:checked[class='"+childitem+"']"); $.each(obj, function(i,item){ selected_ids+= $(item).val() +','; }); if(selected_ids) { var a=confirm("CAUTION! You are going to delete a quantity [...]]]></description>
			<content:encoded><![CDATA[<p>    最近在为MeePlace 2.7的后台编写多选功能。在一个接一个的版本中，MeePlace的后台是越来越强大了（不够谦虚，hoho），后台采用纯ajax异步（有的时候觉得编程会有点麻烦，但是从1.0开始就是这样的后台，现在要改的话也麻烦，况且AJAX能给用户带来更好的体验，就继续开发吧：D）</p>
<p>这次后台增加的功能中，有一个是能够多选/全选项目，这个已经是历史遗留问题了，在我所有开发的项目中都是用这套自己开发的后台系统，改一改就成。这次布莱恩吧multi-selectable列在了Milestone里，所以就写了。以前有做过多选，不过由于是原始form的post，所以比较简单。这次用AJAX的后台多选操作，我还是想了一下才开始动手的。</p>
<p>我的想法是，通过遍历checkbox，来得到有被选定了的checkbox的value，然后再传给后端进行多选处理。</p>
<p>下面公开MeePlace的这部分代码。</p>
<p><img src="http://slj.me/wp-content/uploads/2010/03/meeplace-multi-check.png" alt="" title="meeplace-multi-check" width="430" height="270" class="alignnone size-full wp-image-1503" /></p>
<p>全选按钮。用户点击全选的那个checkbox后，checkbox的onclick=&#8221;select_item_all(this,&#8221;allitem&#8221;,&#8221;childitem&#8221;)&#8221;<br />
其中&#8221;allitem&#8221;是全选的checkbox的classname，因为也许这个全选会出现两个，或者更多，比如表头和表尾各一。<br />
&#8220;childitem&#8221;是所有的条目前的checkbox的classname。<br />
JS代码：<br />
<span id="more-1501"></span></p>
<pre name="code" class="js">
//全选按钮
function select_item_all(whochecked,allitem,childitem)
{
 if(whochecked==true)
 {
  $('.'+allitem).attr('checked',true);
  $('.'+childitem).attr('checked',true);
  $('.itemtr').addClass('trselected');
 }
 else
 {
  $('.'+allitem).attr('checked',false);
  $('.'+childitem).attr('checked',false);
  $('.itemtr').removeClass('trselected');
 }
}
</pre>
<p>这样通过判断提交全选的checkbox是否被勾选，来达到全选目的。</p>
<p>下面的代码是点击&#8221;Delete selected&#8221;（“删除所选”）之后，扫描所选中的checkbox的value以及发出警告和异步提交的代码<br />
JS代码：</p>
<pre name="code" class="js">
function delselected(sheet,where,childitem)
{
//通过扫描制定childitem（项目前的checkbox的classname），来获取选中了的项目IDs
   var selected_ids='';
   var obj=$("input:checked[class='"+childitem+"']");
    $.each(obj, function(i,item){
       selected_ids+= $(item).val() +',';
     });  

if(selected_ids)
{
 var a=confirm("CAUTION! You are going to delete a quantity of items.\n\rThese items will never be restored after deleted.\n\rSure to delete these items?");
if(a==0) return ;
}
else   //没有发现选中的checkbox
{
 alert('You have not selected any item.');
 return;
}

 //通过jQuery的$.post来异步提交数据
$.post("/mgt/func/delete.php?"+Math.random(), {
sheet:sheet,
where:where,
equal:selected_ids
},function(data){tips('Items deleted.');nav();});

}
</pre>
<p>对应 delete.php的代码，虽然代码不安全，能够直接注入的样子，直接操作数据库。但是出于是后台的代码，而且MeePlace对SESSION的检验非常严格，所以就这么用了，我想没有一个Admin想用自己的Admin权限黑自己的网站的。LOL<br />
PHP代码：</p>
<blockquote><p>//检查_SESSION</p>
<p>//自己的数据库连接，或者是框架的数据库接口</p>
<p>///传递过来的值，equals是所选ID经过explode()函数之后得出的数组<br />
$sheet=$_REQUEST[sheet]; //<br />
 $where=$_REQUEST[where]; //<br />
 $equal=$_REQUEST[equal]; // </p>
<p> $equals = explode(&#8220;,&#8221;, $equal);<br />
/// 循环删除数据库中的制定条目<br />
$i=0;<br />
while($i<count ($equals)) {<br />
	if($equals[$i]){<br />
		$query="delete from `$sheet` where `$where`= '$equals[$i]'  limit 1";<br />
		$rc=mysql_query("$query") or die("ERROR: $query");<br />
		$output.=$query."\n\r";<br />
	}<br />
	 $i++;<br />
}</p></blockquote>
<h3 style="color:red">另外如果你想通过checkbox的onchange来调用全选函数的话，结果是：IE不支持！最后只好使用onclick来实现了。这个也是历史遗留问题。算是IE的一个不愿解决的BUG</h3>
<p></count></p></blockquote>
<h2  class="related_post_title">Related Posts / 相关文章</h2><ul class="related_post"><li><a href="http://slj.me/2010/05/whats-new-for-meeplace-2-8/" title="What&#8217;s new for Meeplace 2.8">What&#8217;s new for Meeplace 2.8</a></li><li><a href="http://slj.me/2010/02/meeplace-2-6-release-feb-13-2010/" title="Meeplace 2.6 Release [Feb 13, 2010]">Meeplace 2.6 Release [Feb 13, 2010]</a></li><li><a href="http://slj.me/2010/01/%e4%bb%8a%e6%97%a5%e6%96%b0%e9%97%bb%ef%bc%9ameeplace-llc%e5%9c%a8%e5%8c%97%e7%be%8e%e6%b3%a8%e5%86%8c/" title="今日新闻：MeePlace LLC在北美注册">今日新闻：MeePlace LLC在北美注册</a></li><li><a href="http://slj.me/2010/01/%e5%85%b3%e4%ba%8emeeplace-2-4%e7%9a%84%e4%b8%ad%e6%96%87%e7%89%88%e8%af%b4%e6%98%8e/" title="我的近况与MeePlace 2.4说明">我的近况与MeePlace 2.4说明</a></li><li><a href="http://slj.me/2010/01/theme-upgrade-advice-for-meeplace-2-4/" title="Theme Upgrade Advice For MeePlace 2.4">Theme Upgrade Advice For MeePlace 2.4</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2010/03/multiple-selectable-checkbox-ajax-submit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>10个jQuery Lightbox效果插件</title>
		<link>http://slj.me/2010/01/10%e4%b8%aajquery-lightbox%e6%95%88%e6%9e%9c%e6%8f%92%e4%bb%b6/</link>
		<comments>http://slj.me/2010/01/10%e4%b8%aajquery-lightbox%e6%95%88%e6%9e%9c%e6%8f%92%e4%bb%b6/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 06:18:11 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[box]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[light]]></category>
		<category><![CDATA[lightbox]]></category>

		<guid isPermaLink="false">http://slj.me/?p=1471</guid>
		<description><![CDATA[Lightbox弹框效果在很多地方都很有用。而原始的Lightbox脚本已经被无数次的克隆到了所有的流行Javascript库中。本文收集10个最佳的Lightbox效果插件。 jQuery Lightbox Plugin 支持的媒体类型： Images 演示 下载 Fancybox 支持的媒体类型： Images, Inline HTML, iFrame 演示 下载 Shadowbox 支持的媒体类型： Images, Inline HTML, iFrame, AJAX, Flash, Video 演示 下载 ThickBox 支持的媒体类型： Images, Inline HTML, iFrame, AJAX 演示 下载 Slightly Thickerbox 支持的媒体类型： Images, AJAX, Video 演示 下载 Fancy Zoom 支持的媒体类型： Images, Inline HTML, Flash 演示 下载 Facebox 支持的媒体类型： [...]]]></description>
			<content:encoded><![CDATA[<p>Lightbox弹框效果在很多地方都很有用。而原始的Lightbox脚本已经被无数次的克隆到了所有的流行Javascript库中。本文收集10个最佳的Lightbox效果插件。 </p>
<h3><a rel="external nofollow" href="http://leandrovieira.com/projects/jquery/lightbox/">jQuery Lightbox Plugin</a></h3>
<p><a rel="external nofollow" href="http://leandrovieira.com/projects/jquery/lightbox/"><img src="http://slj.me/wp-content/uploads/2010/01/lightbox.jpg" alt="Download Lightbox script" /></a></p>
<p><strong><span id="more-1471"></span>支持的媒体类型：</strong> Images</p>
<p><a rel="external nofollow" href="http://leandrovieira.com/projects/jquery/lightbox/">演示</a></p>
<p><a rel="external nofollow" href="http://leandrovieira.com/projects/jquery/lightbox/">下载</a></p>
<h3><a rel="external nofollow" href="http://fancy.klade.lv/">Fancybox</a></h3>
<p><a rel="external nofollow" href="http://fancy.klade.lv/"><img src="http://slj.me/wp-content/uploads/2010/01/fancybox.jpg" alt="Download Lightbox script" /></a></p>
<p><strong>支持的媒体类型：</strong> Images, Inline HTML, iFrame</p>
<p><a rel="external nofollow" href="http://fancy.klade.lv/example">演示</a></p>
<p><a rel="external nofollow" href="http://fancy.klade.lv/">下载</a></p>
<h3><a rel="external nofollow" href="http://www.shadowbox-js.com/index.html">Shadowbox</a></h3>
<p><a rel="external nofollow" href="http://www.shadowbox-js.com/index.html"><img src="http://slj.me/wp-content/uploads/2010/01/shadowbox.jpg" alt="Download Lightbox script" /></a></p>
<p><strong>支持的媒体类型：</strong> Images, Inline HTML, iFrame, AJAX, Flash, Video</p>
<p><a rel="external nofollow" href="http://www.shadowbox-js.com/index.html">演示</a></p>
<p><a rel="external nofollow" href="http://www.shadowbox-js.com/index.html">下载</a></p>
<h3><a rel="external nofollow" href="http://jquery.com/demo/thickbox/">ThickBox</a></h3>
<p><a rel="external nofollow" href="http://jquery.com/demo/thickbox/"><img src="http://slj.me/wp-content/uploads/2010/01/thickbox.jpg" alt="Download Lightbox script" /></a></p>
<p><strong>支持的媒体类型：</strong> Images, Inline HTML, iFrame, AJAX</p>
<p><a rel="external nofollow" href="http://jquery.com/demo/thickbox/">演示</a></p>
<p><a rel="external nofollow" href="http://jquery.com/demo/thickbox/">下载</a></p>
<h3><a rel="external nofollow" href="http://www.jasons-toolbox.com/SlightlyThickerbox/">Slightly Thickerbox</a></h3>
<p><a rel="external nofollow" href="http://www.jasons-toolbox.com/SlightlyThickerbox/"><img src="http://slj.me/wp-content/uploads/2010/01/slightly.jpg" alt="Download Lightbox script" /></a></p>
<p><strong>支持的媒体类型：</strong> Images, AJAX, Video</p>
<p><a rel="external nofollow" href="http://www.jasons-toolbox.com/SlightlyThickerbox/">演示</a></p>
<p><a rel="external nofollow" href="http://www.jasons-toolbox.com/SlightlyThickerbox/">下载</a></p>
<h3><a rel="external nofollow" href="http://orderedlist.com/articles/fancyzoom-meet-jquery">Fancy Zoom</a></h3>
<p><a rel="external nofollow" href="http://orderedlist.com/articles/fancyzoom-meet-jquery"><img src="http://slj.me/wp-content/uploads/2010/01/fancyzoom.jpg" alt="Download Lightbox script" /></a></p>
<p><strong>支持的媒体类型：</strong> Images, Inline HTML, Flash</p>
<p><a rel="external nofollow" href="http://orderedlist.com/demos/fancy-zoom-jquery/">演示</a></p>
<p><a rel="external nofollow" href="http://orderedlist.com/articles/fancyzoom-meet-jquery">下载</a></p>
<h3><a rel="external nofollow" href="http://famspam.com/facebox">Facebox</a></h3>
<p><a rel="external nofollow" href="http://famspam.com/facebox"><img src="http://slj.me/wp-content/uploads/2010/01/facebox.jpg" alt="Download Lightbox script" /></a></p>
<p><strong>支持的媒体类型：</strong> Images, Inline HTML, AJAX</p>
<p><a rel="external nofollow" href="http://famspam.com/facebox">演示</a></p>
<p><a rel="external nofollow" href="http://famspam.com/facebox">下载</a></p>
<h3><a rel="external nofollow" href="http://nyromodal.nyrodev.com/">nyroModal</a></h3>
<p><a rel="external nofollow" href="http://nyromodal.nyrodev.com/"><img src="http://slj.me/wp-content/uploads/2010/01/nyromodal.jpg" alt="Download Lightbox script" /></a></p>
<p><strong>支持的媒体类型：</strong> Images, Inline HTML, iFrame, AJAX, Video</p>
<p><a rel="external nofollow" href="http://nyromodal.nyrodev.com/">演示</a></p>
<p><a rel="external nofollow" href="http://nyromodal.nyrodev.com/">下载</a></p>
<h3><a rel="external nofollow" href="http://www.intelliance.fr/jquery/imagebox/">Interface Imagebox Demo</a></h3>
<p><a rel="external nofollow" href="http://www.intelliance.fr/jquery/imagebox/"><img src="http://slj.me/wp-content/uploads/2010/01/imagebox.jpg" alt="Download Lightbox script" /></a></p>
<p><strong>支持的媒体类型：</strong> Images</p>
<p><a rel="external nofollow" href="http://www.intelliance.fr/jquery/imagebox/">演示</a></p>
<p><a rel="external nofollow" href="http://www.intelliance.fr/jquery/imagebox/">下载</a></p>
<h3><a rel="external nofollow" href="http://www.pirolab.it/pirobox/">piroBox</a></h3>
<p><a rel="external nofollow" href="http://www.pirolab.it/pirobox/"><img src="http://slj.me/wp-content/uploads/2010/01/piro.jpg" alt="Download Lightbox script" /></a></p>
<p><strong>支持的媒体类型：</strong> Images</p>
<p><a rel="external nofollow" href="http://www.pirolab.it/pirobox/">演示</a></p>
<p><a rel="external nofollow" href="http://www.pirolab.it/pirobox/">下载</a></p>
<h3><a rel="external nofollow" href="http://jquery.com/demo/grey/">Greybox Redux</a></h3>
<p><a rel="external nofollow" href="http://jquery.com/demo/grey/"><img src="http://slj.me/wp-content/uploads/2010/01/greybox.jpg" alt="Download Lightbox script" /></a></p>
<p><strong>支持的媒体类型：</strong> Images, iFrame</p>
<p><a rel="external nofollow" href="http://jquery.com/demo/grey/">演示</a></p>
<p><a rel="external nofollow" href="http://jquery.com/demo/grey/">下载</a></p>
<h3><a rel="external nofollow" href="http://www.no-margin-for-errors.com/projects/prettyPhoto-jquery-lightbox-clone/">prettyPhoto</a></h3>
<p><a rel="external nofollow" href="http://www.no-margin-for-errors.com/projects/prettyPhoto-jquery-lightbox-clone/"><img src="http://slj.me/wp-content/uploads/2010/01/piro.jpg" alt="Download Lightbox script" /></a></p>
<p><strong>支持的媒体类型：</strong> Images</p>
<p><a rel="external nofollow" href="http://www.no-margin-for-errors.com/projects/prettyPhoto-jquery-lightbox-clone/">演示</a></p>
<p><a rel="external nofollow" href="http://www.no-margin-for-errors.com/projects/prettyPhoto-jquery-lightbox-clone/">下载</a></p>
<p>From: <a rel="external nofollow" href="http://line25.com/articles/rounding-up-the-top-10-jquery-lightbox-scripts">Rounding Up the Top 10 jQuery Lightbox Scripts</a></p>
<h2  class="related_post_title">Related Posts / 相关文章</h2><ul class="related_post"><li><a href="http://slj.me/2010/10/20-jquery-new-effects/" title="20个jQuery新效果">20个jQuery新效果</a></li><li><a href="http://slj.me/2010/03/45-fresh-useful-javascript-and-jquery-techniques-and-tools/" title="[英,转]45个新鲜有用的JS与jQuery技术和工具">[英,转]45个新鲜有用的JS与jQuery技术和工具</a></li><li><a href="http://slj.me/2009/12/lazyload/" title="LazyLoad &#8211; jQuery延迟载入插件">LazyLoad &#8211; jQuery延迟载入插件</a></li><li><a href="http://slj.me/2009/12/20-more-beautiful-interactive-website-design-using-jquery/" title="20多个漂亮的使用jQuery交互的网站设计欣赏">20多个漂亮的使用jQuery交互的网站设计欣赏</a></li><li><a href="http://slj.me/2009/12/the-best-jquery-plugins-of-2009/" title="2009 年度最佳 jQuery 插件">2009 年度最佳 jQuery 插件</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2010/01/10%e4%b8%aajquery-lightbox%e6%95%88%e6%9e%9c%e6%8f%92%e4%bb%b6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JS获取浏览器窗口大小 获取屏幕，浏览器，网页高度宽度</title>
		<link>http://slj.me/2010/01/js%e8%8e%b7%e5%8f%96%e6%b5%8f%e8%a7%88%e5%99%a8%e7%aa%97%e5%8f%a3%e5%a4%a7%e5%b0%8f-%e8%8e%b7%e5%8f%96%e5%b1%8f%e5%b9%95%ef%bc%8c%e6%b5%8f%e8%a7%88%e5%99%a8%ef%bc%8c%e7%bd%91%e9%a1%b5%e9%ab%98/</link>
		<comments>http://slj.me/2010/01/js%e8%8e%b7%e5%8f%96%e6%b5%8f%e8%a7%88%e5%99%a8%e7%aa%97%e5%8f%a3%e5%a4%a7%e5%b0%8f-%e8%8e%b7%e5%8f%96%e5%b1%8f%e5%b9%95%ef%bc%8c%e6%b5%8f%e8%a7%88%e5%99%a8%ef%bc%8c%e7%bd%91%e9%a1%b5%e9%ab%98/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 10:46:03 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[js]]></category>

		<guid isPermaLink="false">http://slj.me/2010/01/js%e8%8e%b7%e5%8f%96%e6%b5%8f%e8%a7%88%e5%99%a8%e7%aa%97%e5%8f%a3%e5%a4%a7%e5%b0%8f-%e8%8e%b7%e5%8f%96%e5%b1%8f%e5%b9%95%ef%bc%8c%e6%b5%8f%e8%a7%88%e5%99%a8%ef%bc%8c%e7%bd%91%e9%a1%b5%e9%ab%98/</guid>
		<description><![CDATA[网页可见区域宽：document.body.clientWidth 网页可见区域高：document.body.clientHeight 网页可见区域宽：document.body.offsetWidth (包括边线的宽) 网页可见区域高：document.body.offsetHeight (包括边线的宽) 网页正文全文宽：document.body.scrollWidth 网页正文全文高：document.body.scrollHeight 网页被卷去的高：document.body.scrollTop 网页被卷去的左：document.body.scrollLeft 网页正文部分上：window.screenTop 网页正文部分左：window.screenLeft 屏幕分辨率的高：window.screen.height 屏幕分辨率的宽：window.screen.width 屏幕可用工作区高度：window.screen.availHeight 屏幕可用工作区宽度：window.screen.availWidth HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth scrollHeight: 获取对象的滚动高度。 scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离 scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离 scrollWidth:获取对象的滚动宽度 offsetHeight:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的高度 offsetLeft:获取对象相对于版面或由 offsetParent 属性指定的父坐标的计算左侧位置 offsetTop:获取对象相对于版面或由 offsetTop 属性指定的父坐标的计算顶端位置 event.clientX 相对文档的水平座标 event.clientY 相对文档的垂直座标 event.offsetX 相对容器的水平坐标 event.offsetY 相对容器的垂直坐标 document.documentElement.scrollTop 垂直方向滚动的值 event.clientX+document.documentElement.scrollTop 相对文档的水平座标+垂直方向滚动的量 IE，FireFox 差异如下： IE6.0、FF1.06+： clientWidth = width + padding clientHeight = height + [...]]]></description>
			<content:encoded><![CDATA[<p>网页可见区域宽：document.body.clientWidth<br />
网页可见区域高：document.body.clientHeight<br />
网页可见区域宽：document.body.offsetWidth (包括边线的宽)<br />
网页可见区域高：document.body.offsetHeight (包括边线的宽)<br />
网页正文全文宽：document.body.scrollWidth<br />
网页正文全文高：document.body.scrollHeight<br />
网页被卷去的高：document.body.scrollTop<br />
网页被卷去的左：document.body.scrollLeft<br />
网页正文部分上：window.screenTop<br />
网页正文部分左：window.screenLeft<br />
屏幕分辨率的高：window.screen.height<br />
屏幕分辨率的宽：window.screen.width<br />
屏幕可用工作区高度：window.screen.availHeight<br />
屏幕可用工作区宽度：window.screen.availWidth</p>
<p><span id="more-1468"></span>HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth<br />
scrollHeight: 获取对象的滚动高度。<br />
scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离<br />
scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离<br />
scrollWidth:获取对象的滚动宽度<br />
offsetHeight:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的高度<br />
offsetLeft:获取对象相对于版面或由 offsetParent 属性指定的父坐标的计算左侧位置<br />
offsetTop:获取对象相对于版面或由 offsetTop 属性指定的父坐标的计算顶端位置<br />
event.clientX 相对文档的水平座标<br />
event.clientY 相对文档的垂直座标<br />
event.offsetX 相对容器的水平坐标<br />
event.offsetY 相对容器的垂直坐标<br />
document.documentElement.scrollTop 垂直方向滚动的值<br />
event.clientX+document.documentElement.scrollTop 相对文档的水平座标+垂直方向滚动的量<br />
IE，FireFox 差异如下：</p>
<p>IE6.0、FF1.06+：</p>
<p>clientWidth = width + padding</p>
<p>clientHeight = height + padding</p>
<p>offsetWidth = width + padding + border</p>
<p>offsetHeight = height + padding + border</p>
<p>IE5.0/5.5：<br />
clientWidth = width &#8211; border</p>
<p>clientHeight = height &#8211; border</p>
<p>offsetWidth = width</p>
<p>offsetHeight = height</p>
<p>(需要提一下：CSS中的margin属性，与clientWidth、offsetWidth、clientHeight、offsetHeight均无关)</p>
<p>网页可见区域宽： document.body.clientWidth<br />
网页可见区域高： document.body.clientHeight<br />
网页可见区域宽： document.body.offsetWidth (包括边线的宽)<br />
网页可见区域高： document.body.offsetHeight (包括边线的高)<br />
网页正文全文宽： document.body.scrollWidth<br />
网页正文全文高： document.body.scrollHeight<br />
网页被卷去的高： document.body.scrollTop<br />
网页被卷去的左： document.body.scrollLeft<br />
网页正文部分上： window.screenTop<br />
网页正文部分左： window.screenLeft<br />
屏幕分辨率的高： window.screen.height<br />
屏幕分辨率的宽： window.screen.width<br />
屏幕可用工作区高度： window.screen.availHeight<br />
屏幕可用工作区宽度： window.screen.availWidth</p>
<p>－－－－－－－－－－－－－－－－－－－</p>
<p>技术要点<br />
本节代码主要使用了Document对象关于窗口的一些属性，这些属性的主要功能和用法如下。</p>
<p>要得到窗口的尺寸，对于不同的浏览器，需要使用不同的属性和方法：若要检测窗口的真实尺寸，在Netscape下需要使用Window的属性；在IE下需要深入Document内部对body进行检测；在DOM环境下，若要得到窗口的尺寸，需要注意根元素的尺寸，而不是元素。</p>
<p>Window对象的innerWidth属性包含当前窗口的内部宽度。Window对象的innerHeight属性包含当前窗口的内部高度。</p>
<p>Document对象的body属性对应HTML文档的标签。Document对象的documentElement属性则表示HTML文档的根节点。</p>
<p>document.body.clientHeight表示HTML文档所在窗口的当前高度。document.body. clientWidth表示HTML文档所在窗口的当前宽度。</p>
<p>实现代码</p>
<div><sup><a title="WP-CodeBox HowTo?" href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank">?</a></sup><a onclick="copycode('p1199code1');" href="http://www.cnblogs.com/ie421/admin/javascript:;"><span style="color: #ffffff;">[Copy to clipboard]</span></a>Download <a href="http://www.52004.com.cn/wp-content/plugins/wp-codebox/wp-codebox.php?p=1199&amp;download=52004.txt"><span style="color: #ffffff;">52004.txt</span></a></div>
<div>
<table width="100%">
<tbody>
<tr id="p11991">
<td width="1%">
<pre>1
            2
            3
            4
            5
            6
            7
            8
            9
            10
            11
            12
            13
            14
            15
            16
            17
            18
            19
            20
            21
            22
            23
            24
            25
            26
            27
            28
            29
            30
            31
            32
            33
            34
            35
            36
            37
            38
            39
            40
            41
            42
            43
            44
            45
            46
            47
            48</pre>
</td>
<td id="p1199code1">
<pre>&lt; !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
            &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
            &lt;head&gt;
            &lt;title&gt;请调整浏览器窗口&lt;/title&gt;
            &lt;meta http-equiv="content-type" content="text/html; charset=gb2312"&gt;
            &lt;/meta&gt;&lt;/head&gt;
            &lt;body&gt;
            &lt;h2 align="center"&gt;请调整浏览器窗口大小&lt;/h2&gt;&lt;hr /&gt;
            &lt;form action="#" method="get" name="form1" id="form1"&gt;
            &lt;!--显示浏览器窗口的实际尺寸--&gt;
            浏览器窗口 的 实际高度: &lt;input type="text" name="availHeight" size="4"/&gt;&lt;br /&gt;
            浏览器窗口 的 实际宽度: &lt;input type="text" name="availWidth" size="4"/&gt;&lt;br /&gt;
            &lt;/form&gt;
            &lt;script type="text/javascript"&gt;
            &lt;!--
            var winWidth = 0;
            var winHeight = 0;
            function findDimensions() //函数：获取尺寸
            {
            //获取窗口宽度
            if (window.innerWidth)
            winWidth = window.innerWidth;
            else if ((document.body) &amp;&amp; (document.body.clientWidth))
            winWidth = document.body.clientWidth;
            //获取窗口高度
            if (window.innerHeight)
            winHeight = window.innerHeight;
            else if ((document.body) &amp;&amp; (document.body.clientHeight))
            winHeight = document.body.clientHeight;
            //通过深入Document内部对body进行检测，获取窗口大小
            if (document.documentElement  &amp;&amp; document.documentElement.clientHeight &amp;&amp; document.documentElement.clientWidth)
            {
            winHeight = document.documentElement.clientHeight;
            winWidth = document.documentElement.clientWidth;
            }
            //结果输出至两个文本框
            document.form1.availHeight.value= winHeight;
            document.form1.availWidth.value= winWidth;
            }
            findDimensions();
            //调用函数，获取数值
            window.onresize=findDimensions;

            //--&gt;
            &lt;/script&gt;
            &lt;/body&gt;
            &lt;/html&gt;</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>源程序解读</p>
<p>（1）程序首先建立一个表单，包含两个文本框，用于显示窗口当前的宽度和高度，并且，其数值会随窗口大小的改变而变化。</p>
<p>（2）在随后的JavaScript代码中，首先定义了两个变量winWidth和winHeight，用于保存窗口的高度值和宽度值。</p>
<p>（3）然后，在函数findDimensions ( )中，使用window.innerHeight和window.innerWidth得到窗口的高度和宽度，并将二者保存在前述两个变量中。</p>
<p>（4）再通过深入Document内部对body进行检测，获取窗口大小，并存储在前述两个变量中。</p>
<p>（5）在函数的最后，通过按名称访问表单元素，结果输出至两个文本框。</p>
<p>（6）在JavaScript代码的最后，通过调用findDimensions ( )函数，完成整个操作。<br />
<img src="http://images.cnblogs.com/cnblogs_com/ie421/jswidth.jpg" border="0" alt="" width="609" height="602" /></p>
<h2  class="related_post_title">Related Posts / 相关文章</h2><ul class="related_post"><li><a href="http://slj.me/2010/12/javascript-select-operations/" title="JavaScript 操作select控件大全（新增、修改、删除、选中、清空、判断存在等）">JavaScript 操作select控件大全（新增、修改、删除、选中、清空、判断存在等）</a></li><li><a href="http://slj.me/2010/03/45-fresh-useful-javascript-and-jquery-techniques-and-tools/" title="[英,转]45个新鲜有用的JS与jQuery技术和工具">[英,转]45个新鲜有用的JS与jQuery技术和工具</a></li><li><a href="http://slj.me/2010/03/building-iphone-apps-with-html-css-and-javascript/" title="【好书PDF】：Building iPhone Apps with HTML, CSS, and JavaScript">【好书PDF】：Building iPhone Apps with HTML, CSS, and JavaScript</a></li><li><a href="http://slj.me/2009/07/javascript-pic-reflection-glossy-effect/" title="Javascript 实现图像倒影、发光效果">Javascript 实现图像倒影、发光效果</a></li><li><a href="http://slj.me/2009/04/javascript-md5-encrypt/" title="JavaScript MD5 加密">JavaScript MD5 加密</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2010/01/js%e8%8e%b7%e5%8f%96%e6%b5%8f%e8%a7%88%e5%99%a8%e7%aa%97%e5%8f%a3%e5%a4%a7%e5%b0%8f-%e8%8e%b7%e5%8f%96%e5%b1%8f%e5%b9%95%ef%bc%8c%e6%b5%8f%e8%a7%88%e5%99%a8%ef%bc%8c%e7%bd%91%e9%a1%b5%e9%ab%98/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LazyLoad &#8211; jQuery延迟载入插件</title>
		<link>http://slj.me/2009/12/lazyload/</link>
		<comments>http://slj.me/2009/12/lazyload/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 08:08:17 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[LazyLoad]]></category>
		<category><![CDATA[延迟载入]]></category>
		<category><![CDATA[插件]]></category>

		<guid isPermaLink="false">http://kiya.cn/?p=1401</guid>
		<description><![CDATA[不知道大家有没有发现，在浏览一些网站时，只有当你滚动到相应的地方，本该在那里显示的图片才会开始载入并显示，这明显减少了服务器的压力和流量，也能够减小浏览器的负担。 今天推荐一个 jQuery 的插件，就是用来 Lazy Load 的，大家看下面的官方页面学习使用方法吧。 http://www.appelsiini.net/projects/lazyload Related Posts / 相关文章20个jQuery新效果[英,转]45个新鲜有用的JS与jQuery技术和工具10个jQuery Lightbox效果插件20多个漂亮的使用jQuery交互的网站设计欣赏2009 年度最佳 jQuery 插件]]></description>
			<content:encoded><![CDATA[<p>不知道大家有没有发现，在浏览一些网站时，只有当你滚动到相应的地方，本该在那里显示的图片才会开始载入并显示，这明显减少了服务器的压力和流量，也能够减小浏览器的负担。<br />
今天推荐一个 jQuery 的插件，就是用来 Lazy Load 的，大家看下面的官方页面学习使用方法吧。<br />
<a href="http://www.appelsiini.net/projects/lazyload" target="_blank"> http://www.appelsiini.net/projects/lazyload</a></p>
<h2  class="related_post_title">Related Posts / 相关文章</h2><ul class="related_post"><li><a href="http://slj.me/2010/10/20-jquery-new-effects/" title="20个jQuery新效果">20个jQuery新效果</a></li><li><a href="http://slj.me/2010/03/45-fresh-useful-javascript-and-jquery-techniques-and-tools/" title="[英,转]45个新鲜有用的JS与jQuery技术和工具">[英,转]45个新鲜有用的JS与jQuery技术和工具</a></li><li><a href="http://slj.me/2010/01/10%e4%b8%aajquery-lightbox%e6%95%88%e6%9e%9c%e6%8f%92%e4%bb%b6/" title="10个jQuery Lightbox效果插件">10个jQuery Lightbox效果插件</a></li><li><a href="http://slj.me/2009/12/20-more-beautiful-interactive-website-design-using-jquery/" title="20多个漂亮的使用jQuery交互的网站设计欣赏">20多个漂亮的使用jQuery交互的网站设计欣赏</a></li><li><a href="http://slj.me/2009/12/the-best-jquery-plugins-of-2009/" title="2009 年度最佳 jQuery 插件">2009 年度最佳 jQuery 插件</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2009/12/lazyload/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>转牛X无敌！！！Zen Coding: 一种快速编写HTML/CSS代码的方法</title>
		<link>http://slj.me/2009/12/%e7%89%9bx%e6%97%a0%e6%95%8c%ef%bc%81%ef%bc%81%ef%bc%81zen-coding-%e4%b8%80%e7%a7%8d%e5%bf%ab%e9%80%9f%e7%bc%96%e5%86%99htmlcss%e4%bb%a3%e7%a0%81%e7%9a%84%e6%96%b9%e6%b3%95/</link>
		<comments>http://slj.me/2009/12/%e7%89%9bx%e6%97%a0%e6%95%8c%ef%bc%81%ef%bc%81%ef%bc%81zen-coding-%e4%b8%80%e7%a7%8d%e5%bf%ab%e9%80%9f%e7%bc%96%e5%86%99htmlcss%e4%bb%a3%e7%a0%81%e7%9a%84%e6%96%b9%e6%b3%95/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 16:09:11 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[markup]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://kiya.cn/?p=1394</guid>
		<description><![CDATA[在本文中我们将展示一种新的使用仿CSS选择器的语法来快速开发HTML和CSS的方法。它由Sergey Chikuyonok开发。 你在写HTML代码(包括所有标签、属性、引用、大括号等)上花费多少时间？如果你的编辑器有代码提示功能，你编写的时候就会容易些，但即便如此你还是要手动敲入很多代码。 在JavaScript方面，当我们想要在一个页面上获取某个特定的元素时，我们就会遇到同样的问题，我们必须写很多代码，这就变得难于维护和重用。JavaScript框架应运而生，它们同时引入了CSS选择器引擎。现在，你可以使用简单的CSS表达式来获取DOM元素，这相当酷。 但是，如果你不仅仅可以用CSS的选择器布局和定位元素，还能生成代码会怎么样？比如，如果你这样写： div#content&#62;h1+p …然后就可以看到这样的输出： &#60;div id="content"&#62; &#60;h1&#62;&#60;/h1&#62; &#60;p&#62;&#60;/p&#62; &#60;/div&#62; 有些迷惑吧？今天，我将向你介绍Zen Coding，一组用于快速HTML和CSS编码的工具。最初由Vadim Makeev在2009年4月提出(文章为俄语)，由鄙人(也就是我)开发了数月并最终达到比较成熟的状态。Zen Coding由两个核心组件组成：一个缩写扩展器(缩写为像CSS一样的选择器)和上下文无关的HTML标签对匹配器。看一下这个演示视频来看一下它们能为你做些什么。 注意：该视频原版位于Vimeo，但是要看的话需要翻[和谐]墙先，地址在这里：http://vimeo.com/7405114，上面的视频是我费尽周折从Vimeo上下载下来上传到优酷的，上传后质量竟被大打折扣了，囧。youtube上也有一份视频，是基于Aptana的演示，一样很精彩：http://www.youtube.com/watch?v=ug84Ypwqfzk。PS:貌似youtube要比Vimeo翻[和谐]墙容易些，不过如何翻[和谐]墙不在本站讨论范围。 如果你想跳转到详细介绍和使用指南，请看一下演示页面并立刻下载你适用的插件： Demo Demo (使用 Ctrl + , 展开缩写，需要JavaScript支持) 中文版演示 下载(完全支持) Aptana (跨平台); Coda, via TEA for Coda (Mac); Espresso, via TEA for Espresso (Mac); 下载(部分支持，只支持“展开缩写”) TextMate (只能用于Mac机,Windows可以使用E-text编辑器替代); TopStyle; Sublime Text; GEdit; Dreamweaver CS4 editArea在线编辑器; Zen Coding在线编辑器中文版 现在让我们看一下这些工具是如何工作的吧。 展开缩写 [...]]]></description>
			<content:encoded><![CDATA[<p>在本文中我们将展示一种新的使用仿CSS选择器的语法来快速开发HTML和CSS的方法。它由<a rel="external nofollow" href="http://www.smashingmagazine.com/author/sergey-chikuyonok/">Sergey Chikuyonok</a>开发。</p>
<p>你在写HTML代码(包括所有标签、属性、引用、大括号等)上花费多少时间？如果你的编辑器有代码提示功能，你编写的时候就会容易些，但即便如此你还是要手动敲入很多代码。</p>
<p><span id="more-1394"></span><span id="more-11599"> </span></p>
<p>在JavaScript方面，当我们想要在一个页面上获取某个特定的元素时，我们就会遇到同样的问题，我们必须写很多代码，这就变得难于维护和重用。JavaScript框架应运而生，它们同时引入了CSS选择器引擎。现在，你可以使用简单的CSS表达式来获取DOM元素，这相当酷。</p>
<p>但是，如果你不仅仅可以用CSS的选择器布局和定位元素，还能<strong>生成代码</strong>会怎么样？比如，如果你这样写：</p>
<div>
<div>
<pre style="FONT-FAMILY: monospace">div<span style="COLOR: #cc00cc">#content</span><span style="COLOR: #00aa00">&gt;</span>h1<span style="COLOR: #00aa00">+</span>p</pre>
</div>
</div>
<p>…然后就可以看到这样的输出：</p>
<div>
<div>
<pre style="FONT-FAMILY: monospace"><span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">div</span> <span style="COLOR: #000066">id</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"content"</span>&gt;</span>
<span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">h1</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">h1</span>&gt;</span>
<span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">p</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">p</span>&gt;</span>
<span style="COLOR: #009900">&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">div</span>&gt;</span></pre>
</div>
</div>
<p>有些迷惑吧？今天，我将向你介绍<a rel="external nofollow" href="http://code.google.com/p/zen-coding/">Zen Coding</a>，一组用于快速HTML和CSS编码的工具。最初由<a rel="external nofollow" href="http://pepelsbey.net/2009/04/zen-coding-concept/">Vadim Makeev在2009年4月提出</a>(文章为俄语)，由鄙人(也就是我)开发了数月并最终达到比较成熟的状态。Zen Coding由两个核心组件组成：一个缩写扩展器(缩写为像CSS一样的选择器)和上下文无关的HTML标签对匹配器。看一下这个演示视频来看一下它们能为你做些什么。</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="650" height="480" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="align" value="middle" /><param name="src" value="http://player.youku.com/player.php/sid/XMTM4NDQwNzgw/v.swf" /><param name="quality" value="high" /><embed type="application/x-shockwave-flash" width="650" height="480" src="http://player.youku.com/player.php/sid/XMTM4NDQwNzgw/v.swf" quality="high" align="middle"></embed></object></p>
<p><strong>注意：</strong>该视频原版位于Vimeo，但是要看的话需要翻[和谐]墙先，地址在这里：<a rel="external nofollow" href="http://vimeo.com/7405114" target="_blank">http://vimeo.com/7405114</a>，上面的视频是我费尽周折从Vimeo上下载下来上传到优酷的，上传后质量竟被大打折扣了，囧。youtube上也有一份视频，是基于Aptana的演示，一样很精彩：<a rel="external nofollow" href="http://www.youtube.com/watch?v=ug84Ypwqfzk" target="_blank">http://www.youtube.com/watch?v=ug84Ypwqfzk</a>。PS:貌似youtube要比Vimeo翻[和谐]墙容易些，不过如何翻[和谐]墙不在本站讨论范围。</p>
<p>如果你想跳转到详细介绍和使用指南，请看一下演示页面并立刻下载你适用的插件：</p>
<h4>Demo</h4>
<ul>
<li><a rel="external nofollow" href="http://zen-coding.ru/demo/">Demo</a> (使用 <em>Ctrl + ,</em> 展开缩写，需要JavaScript支持)</li>
<li><a rel="external nofollow" href="http://labs.qianduan.net/zencoding/">中文版演示</a></li>
</ul>
<h4>下载(完全支持)</h4>
<ul>
<li><a rel="external nofollow" href="http://code.google.com/p/zen-coding/downloads/detail?name=Zen.Coding-Aptana.v0.5.zip">Aptana</a> (跨平台);</li>
<li>Coda, via <a rel="external nofollow" href="http://github.com/sergeche/tea-for-coda/downloads">TEA for Coda</a> (Mac);</li>
<li>Espresso, via <a rel="external nofollow" href="http://github.com/sergeche/tea-for-espresso/downloads">TEA for Espresso</a> (Mac);</li>
</ul>
<h4>下载(部分支持，只支持“展开缩写”)</h4>
<ul>
<li><a rel="external nofollow" href="http://code.google.com/p/zen-coding/downloads/detail?name=Zen%20Coding%20for%20TextMate%20v0.3.1.zip">TextMate</a> (只能用于Mac机,Windows可以使用E-text编辑器替代);</li>
<li><a rel="external nofollow" href="http://code.google.com/p/zen-coding/downloads/detail?name=TopStyle.Zen.Coding.1.0.zip">TopStyle</a>;</li>
<li><a rel="external nofollow" href="http://code.google.com/p/zen-coding/downloads/detail?name=Sublime.Zen.Coding.1.1.3.zip">Sublime Text</a>;</li>
<li><a rel="external nofollow" href="http://www.kryogenix.org/days/2009/09/21/zen-coding-for-gedit">GEdit</a>;</li>
<li><a rel="external nofollow" href="http://zen-coding.googlecode.com/files/Zen.Coding-Dreamweaver.v0.4.zip">Dreamweaver CS4</a></li>
<li><a rel="external nofollow" href="http://zen-coding.ru/demo/">editArea在线编辑器</a>;</li>
<li><a rel="external nofollow" href="http://labs.qianduan.net/zencoding/">Zen Coding在线编辑器中文版</a></li>
</ul>
<p>现在让我们看一下这些工具是如何工作的吧。</p>
<h3>展开缩写</h3>
<p>展开缩写功能将类似CSS的选择器转换为XHTML代码。术语“缩写”可能会有点儿难以理解。为什么不直接称之为“CSS选择器”呢？嗯，首要原因是语义化：“选择器”意为<em>选择</em>一些东西，但是在这里我们事实上是<em>生成</em> 一些东西，<strong>是写一个长代码的较短的替代</strong>。其次，它只是使用真实的CSS选择器语法的一个小的子集，并添加了一些新的操作符。</p>
<p>这里是一个支持的属性和操作符的列表：</p>
<ul>
<li>E<br />
元素名称(div, p);</li>
<li>E#id<br />
使用id的元素(div#content, p#intro, span#error);</li>
<li>E.class<br />
使用类的元素(div.header, p.error.critial). 你也可以联合使用class和idID: div#content.column.width;</li>
<li>E&gt;N<br />
子代元素(div&gt;p, div#footer&gt;p&gt;span);</li>
<li>E+N<br />
兄弟元素(h1+p, div#header+div#content+div#footer);</li>
<li>E*N<br />
元素倍增(ul#nav&gt;li*5&gt;a);</li>
<li>E$*N<br />
条目编号 (ul#nav&gt;li.item-$*5);</li>
</ul>
<p>正如你能看到的，你已经知道如何使用Zen Coding了：只是些一个简单的仿CSS选择器(呃，“缩写”抱歉)，就像这样…</p>
<div>
<div>
<pre style="FONT-FAMILY: monospace">div<span style="COLOR: #cc00cc">#header</span><span style="COLOR: #00aa00">&gt;</span>img.logo<span style="COLOR: #00aa00">+</span>ul<span style="COLOR: #cc00cc">#nav</span><span style="COLOR: #00aa00">&gt;</span>li<span style="COLOR: #00aa00">*</span><span style="COLOR: #cc66cc">4</span><span style="COLOR: #00aa00">&gt;</span>a</pre>
</div>
</div>
<p>…然后调用”展开缩写”行为。</p>
<p>这里有两个新增的操作符：元素倍增和条目编号。比如，如果你想生成5个&lt;li&gt;元素，你可以简单的写位li*5。它也将同样重写全部子代元素。如果你想写4个&lt;li&gt;元素，每个里面都有一个&lt;a&gt;标签，你就可以简单的写为li*4&gt;a，这样会生成以下HTML代码：</p>
<div>
<table border="0">
<tbody>
<tr>
<td>
<pre>1
2
3
4</pre>
</td>
<td>
<pre style="FONT-FAMILY: monospace"><span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">li</span>&gt;&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">a</span> <span style="COLOR: #000066">href</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">""</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">a</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">li</span>&gt;</span>
<span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">li</span>&gt;&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">a</span> <span style="COLOR: #000066">href</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">""</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">a</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">li</span>&gt;</span>
<span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">li</span>&gt;&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">a</span> <span style="COLOR: #000066">href</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">""</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">a</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">li</span>&gt;</span>
<span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">li</span>&gt;&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">a</span> <span style="COLOR: #000066">href</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">""</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">a</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">li</span>&gt;</span></pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>最后一个——条目编号用于当你想用索引标记重复的元素的情况。假设你想生成class为item1、item2和item3的3个&lt;div&gt;元素。你可以写成这样的缩写，div.item$*3:</p>
<div>
<table border="0">
<tbody>
<tr>
<td>
<pre>1
2
3</pre>
</td>
<td>
<pre style="FONT-FAMILY: monospace"><span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">div</span> <span style="COLOR: #000066">class</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"item1"</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">div</span>&gt;</span>
<span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">div</span> <span style="COLOR: #000066">class</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"item2"</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">div</span>&gt;</span>
<span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">div</span> <span style="COLOR: #000066">class</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"item3"</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">div</span>&gt;</span></pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>只需在你想要索引出现的任何class或id属性上添加一个美元符号即可，而且想要多少都可以。那么，这样…</p>
<div>
<div>
<pre style="FONT-FAMILY: monospace"> div<span style="COLOR: #cc00cc">#i</span>$-test.class$$$<span style="COLOR: #00aa00">*</span><span style="COLOR: #cc66cc">5</span></pre>
</div>
</div>
<p>会被转换成为:</p>
<div>
<table border="0">
<tbody>
<tr>
<td>
<pre>1
2
3
4
5</pre>
</td>
<td>
<pre style="FONT-FAMILY: monospace"><span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">div</span> <span style="COLOR: #000066">id</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"i1-test"</span> <span style="COLOR: #000066">class</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"class111"</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">div</span>&gt;</span>
<span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">div</span> <span style="COLOR: #000066">id</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"i2-test"</span> <span style="COLOR: #000066">class</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"class222"</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">div</span>&gt;</span>
<span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">div</span> <span style="COLOR: #000066">id</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"i3-test"</span> <span style="COLOR: #000066">class</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"class333"</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">div</span>&gt;</span>
<span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">div</span> <span style="COLOR: #000066">id</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"i4-test"</span> <span style="COLOR: #000066">class</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"class444"</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">div</span>&gt;</span>
<span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">div</span> <span style="COLOR: #000066">id</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"i5-test"</span> <span style="COLOR: #000066">class</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"class555"</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">div</span>&gt;</span></pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>你会看到，当你写a的缩写的时候，输出是&lt;a href=”&#8221;&gt;&lt;/a&gt;。或者，如果你写img，输出就是&lt;img src=”&#8221; alt=”&#8221; /&gt;。</p>
<p>Zen Coding是如何知道什么时候应该为生成的标签添加默认的属性或者跳过关闭标签的？有一个专门的文件，名为<em><a rel="external nofollow" href="http://code.google.com/p/zen-coding/source/browse/branches/serge.che/aptana/zen_settings.js">zen_settings.js</a></em>描述了输出元素。这是一个简单的JSON文件，描述每种语言的缩写(是的，你可以为不同的句法定义缩写，比如HTML、XSL、CSS等)。通用的语言缩写定义看起来就像这样：</p>
<div>
<table border="0">
<tbody>
<tr>
<td>
<pre>1
2
3
4
5
6
7</pre>
</td>
<td>
<pre style="FONT-FAMILY: monospace"><span style="COLOR: #3366cc">'html'</span><span style="COLOR: #339933">:</span> <span style="COLOR: #009900">{</span> <span style="COLOR: #3366cc">'snippets'</span><span style="COLOR: #339933">:</span> <span style="COLOR: #009900">{</span> <span style="COLOR: #3366cc">'cc:ie6'</span><span style="COLOR: #339933">:</span> <span style="COLOR: #3366cc">'&lt;!--[if lte IE 6]&gt;<span style="COLOR: #000099; FONT-WEIGHT: bold">\n</span><span style="COLOR: #000099; FONT-WEIGHT: bold">\t</span>${child}|<span style="COLOR: #000099; FONT-WEIGHT: bold">\n</span>&lt;![endif]--&gt;'</span><span style="COLOR: #339933">,</span>
			...
			<span style="COLOR: #009900">}</span><span style="COLOR: #339933">,</span>
			  <span style="COLOR: #3366cc">'abbreviations'</span><span style="COLOR: #339933">:</span> <span style="COLOR: #009900">{</span> <span style="COLOR: #3366cc">'a'</span><span style="COLOR: #339933">:</span> <span style="COLOR: #3366cc">'&lt;a href=""&gt;&lt;/a&gt;'</span><span style="COLOR: #339933">,</span> <span style="COLOR: #3366cc">'img'</span><span style="COLOR: #339933">:</span> <span style="COLOR: #3366cc">'&lt;img src="" alt="" /&gt;'</span><span style="COLOR: #339933">,</span>
			...
			<span style="COLOR: #009900">}</span>
			<span style="COLOR: #009900">}</span></pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>元素类型</h4>
<p>Zen Coding有两个主要的元素类型：<strong>“片段(snippets)” 和 “缩写(abbreviations)”。</strong>片段就是随意的代码碎片，而缩写是标签定义。通过片段，你可以写出你想要的任何代码，它也会照你写的格式输出；但是你必须手动的格式化它(使用\n 和\t实现换行和缩进) 并将${child}变量放到你想要输出子元素的地方，就像这样：cc:ie6&gt;style。如果你不使用${child}变量，子元素将会输出于代码片段的<strong>后面</strong>。</p>
<p>有了缩写，您必须编写标记定义，而且语法是非常重要的。通常，你必须写一个简单的带有所有默认的属性的标签，比如: &lt;a href=”&#8221;&gt;&lt;/a&gt;。当Zen Coding被加载后，它会解析一个标签定义到一个描述该标签的名字、属性(包括它们的顺序)以及该标签是否为空的特定的对象中。所以，如果你写&lt;img src=”&#8221; alt=”&#8221; /&gt;，你会告诉Zen Coding这个标签必须是空的，然后“扩展缩写”行为就会在输出之前为它使用特定的规则。</p>
<p>对于片段和缩写，你可以添加一个管道符号，它告诉Zen Coding当缩写被展开的时候光标会被定位到哪里。默认的，Zen Coding 将光标放在空属性的引号中间以及开始和关闭标签的中间。</p>
<h4>例子</h4>
<p>那么，这里解释一下当你写了一个缩写并召唤“展开缩写”行动时发生的事情。首先，它将一个完整的缩写分开为独立的元素：这样div&gt;a 会被分成div 和a 元素，当然也会维持他们的关系。然后，每个元素，解析器先在代码片段内而后在缩写中寻找定义。如果它找不到，将会使用元素的名字作为新的标签，并为其添加缩写中定义的id和class。比如，如果你写mytag#example，解析器在片段或缩写中找不到mytag定义，它就会输出&lt;mytag id=”example”&gt;&lt;mytag&gt;。</p>
<p>我们制作了很多<a rel="external nofollow" href="http://code.google.com/p/zen-coding/wiki/ZenCSSPropertiesEn">默认的CSS</a>和<a rel="external nofollow" href="http://code.google.com/p/zen-coding/wiki/ZenHTMLElementsEn">HTML缩写和片段</a>。你会发现学习使用Zen Coding可以增加你的生产力。</p>
<h3>HTML 标签对匹配器</h3>
<p>对于HTML编码者的另一个非常常见的任务是寻找一个元素的标签对。例如你想选择整个&lt;div id=”content”&gt;标签并将其移动到其它地方或者删除它。或者有可能你在寻找一个关闭标签并想知道它属于那个开始标签。</p>
<p>不幸的是，很多现代开发工具在该功能方面有所欠缺。那么我就决定写一个我自己的标签对匹配器作为Zen Coding的一部分。不过它依然在beta阶段并尚存一些问题，但它可以工作的很不错并很快。不是浏览整个文档(像通常的那种HTML标签对匹配器的做法)，它从光标的当前位置开始寻找相关的标签。这使得它非常快并且<em>上下文无关</em>：它甚至可以用于这段<strong>JavaScript代码片段</strong>：</p>
<div>
<table border="0">
<tbody>
<tr>
<td>
<pre>1
2
3
4
5
6
7</pre>
</td>
<td>
<pre style="FONT-FAMILY: monospace"><span style="COLOR: #003366; FONT-WEIGHT: bold">var</span> table <span style="COLOR: #339933">=</span> <span style="COLOR: #3366cc">'&lt;table&gt;'</span><span style="COLOR: #339933">;</span> <span style="COLOR: #000066; FONT-WEIGHT: bold">for</span> <span style="COLOR: #009900">(</span><span style="COLOR: #003366; FONT-WEIGHT: bold">var</span> i <span style="COLOR: #339933">=</span> <span style="COLOR: #cc0000">0</span><span style="COLOR: #339933">;</span> i <span style="COLOR: #339933">&lt;</span> <span style="COLOR: #cc0000">3</span><span style="COLOR: #339933">;</span> i<span style="COLOR: #339933">++</span><span style="COLOR: #009900">)</span> <span style="COLOR: #009900">{</span>
	table <span style="COLOR: #339933">+=</span> <span style="COLOR: #3366cc">'&lt;tr&gt;'</span><span style="COLOR: #339933">;</span> <span style="COLOR: #000066; FONT-WEIGHT: bold">for</span> <span style="COLOR: #009900">(</span><span style="COLOR: #003366; FONT-WEIGHT: bold">var</span> j <span style="COLOR: #339933">=</span> <span style="COLOR: #cc0000">0</span><span style="COLOR: #339933">;</span> j <span style="COLOR: #339933">&lt;</span> <span style="COLOR: #cc0000">5</span><span style="COLOR: #339933">;</span> j<span style="COLOR: #339933">++</span><span style="COLOR: #009900">)</span> <span style="COLOR: #009900">{</span>
		table <span style="COLOR: #339933">+=</span> <span style="COLOR: #3366cc">'&lt;td&gt;'</span> <span style="COLOR: #339933">+</span> j <span style="COLOR: #339933">+</span> <span style="COLOR: #3366cc">'&lt;/td&gt;'</span><span style="COLOR: #339933">;</span>
	<span style="COLOR: #009900">}</span>
	table <span style="COLOR: #339933">+=</span> <span style="COLOR: #3366cc">'&lt;/tr&gt;'</span><span style="COLOR: #339933">;</span>
<span style="COLOR: #009900">}</span>
table <span style="COLOR: #339933">+=</span> <span style="COLOR: #3366cc">'&lt;/table&gt;'</span><span style="COLOR: #339933">;</span></pre>
</td>
</tr>
</tbody>
</table>
</div>
<h3>使用缩写包裹</h3>
<p>这真的是一个很酷的特性，它将缩写和标签对匹配器的功能合并到一起了。你有多少才发现你需要<strong>添加一个包裹元素以修正一个浏览器bug</strong>？或者你需要添加一个装饰，比如一个背景图片或者边框到一个块级内容？你必须写开始标签，临时打断你的代码，找到相关的点然后关闭标签。这就是“使用缩写包裹”能帮助你的地方。</p>
<p>该功能相当简单：它要求你输入缩写，然后执行适当的“展开缩写”行动并将你期望的文本放到你缩写的<em>最后一个元素里面</em>。如果你没有选择任何文本，它就会启动标签对匹配器并使用结果。它同样能搞清楚你的光标的位置：标签的内容里面或者是开始和关闭标签中间。依赖于它的位置，它会包裹标签的内容或标签本身。</p>
<p>缩写包裹为包裹个别行引入了一个特定的缩写句法。简单跳转到倍增操作符后面的数字，比如：ul#nav&gt;li*&gt;a。当Zen Coding 发现一个使用未定义的倍增数的时候，它会将它作为一个<em>重复元素</em>：你的章节中有多少行，它就会输出多少次，并将每行的内容放到重复元素的<em>最后一个子元素</em>里面。</p>
<p>如果你在这段文本外面包裹这段缩写div#header&gt;ul#navigation&gt;li.item$*&gt;a&gt;span：</p>
<div>
<table border="0">
<tbody>
<tr>
<td>
<pre>1
2
3
4
5</pre>
</td>
<td>
<pre style="FONT-FAMILY: monospace">About Us
Products
News
Blog
Contact Up</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>你将会得到以下结果：</p>
<div>
<table border="0">
<tbody>
<tr>
<td>
<pre>1
2
3
4
5
6
7
8
9</pre>
</td>
<td>
<pre style="FONT-FAMILY: monospace"><span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">div</span> <span style="COLOR: #000066">id</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"header"</span>&gt;</span>
	<span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">ul</span> <span style="COLOR: #000066">id</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"navigation"</span>&gt;</span>
		<span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">li</span> <span style="COLOR: #000066">class</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"item1"</span>&gt;&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">a</span> <span style="COLOR: #000066">href</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">""</span>&gt;&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">span</span>&gt;</span>About Us<span style="COLOR: #009900">&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">span</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">a</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">li</span>&gt;</span>
		<span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">li</span> <span style="COLOR: #000066">class</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"item2"</span>&gt;&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">a</span> <span style="COLOR: #000066">href</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">""</span>&gt;&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">span</span>&gt;</span>Products<span style="COLOR: #009900">&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">span</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">a</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">li</span>&gt;</span>
		<span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">li</span> <span style="COLOR: #000066">class</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"item3"</span>&gt;&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">a</span> <span style="COLOR: #000066">href</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">""</span>&gt;&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">span</span>&gt;</span>News<span style="COLOR: #009900">&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">span</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">a</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">li</span>&gt;</span>
		<span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">li</span> <span style="COLOR: #000066">class</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"item4"</span>&gt;&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">a</span> <span style="COLOR: #000066">href</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">""</span>&gt;&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">span</span>&gt;</span>Blog<span style="COLOR: #009900">&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">span</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">a</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">li</span>&gt;</span>
		<span style="COLOR: #009900">&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">li</span> <span style="COLOR: #000066">class</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">"item5"</span>&gt;&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">a</span> <span style="COLOR: #000066">href</span><span style="COLOR: #66cc66">=</span><span style="COLOR: #ff0000">""</span>&gt;&lt;<span style="COLOR: #000000; FONT-WEIGHT: bold">span</span>&gt;</span>Contact Up<span style="COLOR: #009900">&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">span</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">a</span>&gt;&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">li</span>&gt;</span>
	<span style="COLOR: #009900">&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">ul</span>&gt;</span>
<span style="COLOR: #009900">&lt;<span style="COLOR: #66cc66">/</span><span style="COLOR: #000000; FONT-WEIGHT: bold">div</span>&gt;</span></pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>你可以看到，Zen Coding是一个强大的文本处理工具。</p>
<h3>快捷键</h3>
<ul>
<li>Ctrl+,<br />
展开缩写</li>
<li>Ctrl+M<br />
匹配对</li>
<li>Ctrl+H<br />
使用缩写包括</li>
<li>Shift+Ctrl+M<br />
合并行</li>
<li>Ctrl+Shift+?<br />
上一个编辑点</li>
<li>Ctrl+Shift+?<br />
下一个编辑点</li>
<li>Ctrl+Shift+?<br />
定位匹配对</li>
</ul>
<p>这些快捷键是可以自定义的。</p>
<h3>在线演示</h3>
<p>你已经学到很多关于Zen Coding如何工作以及它是如何使你的编码更容易了。现在为什么不自己尝试一下呢？因为Zen Coding是用纯JavaScript开发并迁移到Python，它甚至可以用于浏览器内部，这令它成为引入到CMS的首选。</p>
<ul>
<li><a rel="external nofollow" href="http://zen-coding.ru/demo/">Demo</a> (使用 <em>Ctrl + ,</em> 展开缩写，需要JavaScript支持)</li>
<li><a rel="external nofollow" href="http://labs.qianduan.net/zencoding/">中文版演示</a></li>
</ul>
<h3>支持的编辑器</h3>
<p>Zen Coding并不依赖某个特定的编辑器。它是一个只处理文本的出色的组件：它获取文本、做一些处理并放回新的文本(或索引，用于标签匹配)。Zen Coding由JavaScript和Python编写，所以它实际上可以运行于任何平台。在Windows，你可以运行JavaScript版本，而Mac和Linux 分支可以使用Python版。</p>
<p>如果让你的编辑器支持Zen Coding，你需要写一个特定的可以在你的编辑器和Zen Coding之间转换数据的插件。问题是一个编辑器可能不会完整的支持Zen Coding因为它本身的插件系统。比如，<a rel="external nofollow" href="http://macromates.com/">TextMate</a>通过使用脚本输出替换当前行很容的就支持了“展开缩写”功能，但是它不能处理标签对匹配因为没有标准的方法请求TextMate来选择内容。</p>
<h4>完全支持</h4>
<ul>
<li><a rel="external nofollow" href="http://code.google.com/p/zen-coding/downloads/detail?name=Zen.Coding-Aptana.v0.5.zip">Aptana</a> (跨平台);</li>
<li>Coda, via <a rel="external nofollow" href="http://github.com/sergeche/tea-for-coda/downloads">TEA for Coda</a> (Mac);</li>
<li>Espresso, via <a rel="external nofollow" href="http://github.com/sergeche/tea-for-espresso/downloads">TEA for Espresso</a> (Mac);</li>
</ul>
<h4>部分支持(只支持“展开缩写”)</h4>
<ul>
<li><a rel="external nofollow" href="http://code.google.com/p/zen-coding/downloads/detail?name=Zen%20Coding%20for%20TextMate%20v0.3.1.zip">TextMate</a> (只能用于Mac机,Windows可以使用E-text编辑器替代);</li>
<li><a rel="external nofollow" href="http://code.google.com/p/zen-coding/downloads/detail?name=TopStyle.Zen.Coding.1.0.zip">TopStyle</a>;</li>
<li><a rel="external nofollow" href="http://code.google.com/p/zen-coding/downloads/detail?name=Sublime.Zen.Coding.1.1.3.zip">Sublime Text</a>;</li>
<li><a rel="external nofollow" href="http://www.kryogenix.org/days/2009/09/21/zen-coding-for-gedit">GEdit</a>;</li>
<li><a rel="external nofollow" href="http://zen-coding.googlecode.com/files/Zen.Coding-Dreamweaver.v0.4.zip">Dreamweaver CS4</a></li>
<li><a rel="external nofollow" href="http://zen-coding.ru/demo/">editArea在线编辑器</a>;</li>
<li><a rel="external nofollow" href="http://labs.qianduan.net/zencoding/">Zen Coding在线编辑器中文版</a></li>
</ul>
<p>Aptana是我主要的开发环境，它使用一个JavaScript版本的Zen Coding。它也包含很多其它的我用于日常工作的工具，所以任何一个新的Zen Coding版本都将会首先对Aptana可用，然后部署到Python并兼容其它的编辑器。</p>
<p>Coda和Espresso 插件被杰出的<a rel="external nofollow" href="http://onecrayon.com/tea/">Text Editor Actions</a> (TEA) 平台支持，由<a rel="external nofollow" href="http://beckism.com/">Ian Beck</a>开发。原始的源代码<a rel="external nofollow" href="http://github.com/onecrayon">在GitHub上</a>，但我还是制作了<a rel="external nofollow" href="http://github.com/sergeche/">我自己的分支</a>以整合Zen Coding的特性。</p>
<h3>总结</h3>
<p>很多尝试过Zen Coding的人都说它改变了他们写页面的方式。当然还有很多事情要做，还有很多的编辑器需要被支持以及一些文档要写。请浏览<a rel="external nofollow" href="http://code.google.com/p/zen-coding/w/list">现在的文档</a> 以及<a rel="external nofollow" href="http://code.google.com/p/zen-coding/source/browse/#svn/branches/serge.che">源代码</a>以寻找你的问题的答案。希望你喜欢Zen Coding!</p>
<h3>附：Zen coding的具体用法</h3>
<p>遗憾的是， 本文原作者并没有说明zen coding的具体用法，神飞认为有必要做以下简要的说明。这里就以Aptana/Eclipse和Dreamweaver为例，其它编辑器平台暂不描述，如有疑问可以在评论中与前端观察的网友交流。</p>
<h4>Aptana/Eclipse</h4>
<p>由于Aptana本身就是基于Eclipse的，所以，Zen Coding也是支持Eclipse的，只是需要一个EclipseMonkey插件的支持，Aptana已经封装了这个插件，所以如果你使用Aptana，下面的第一步可以跳过。</p>
<ol>ni</p>
<li>通过更新网站安装EclipseMonkey: <a rel="nofollow" href="http://download.eclipse.org/technology/dash/update">http://download.eclipse.org/technology/dash/update</a>(如果你使用Aptana，可跳过这一步)</li>
<li>在你的当前工作去创建一个顶级的项目，给它命名，比如，就叫<strong>zencoding</strong></li>
<li>在新创建的项目中创建<strong>scripts</strong>文件夹</li>
<li>解压缩下载的ZIP插件包到该文件夹。项目结构看起来就像这样:<img src="http://kiya.cn/wp-content/uploads/2009/12/aptana-proj-structure.png" alt="" /></li>
<li>安装之后，Aptana的菜单栏中的“脚本(Script)”菜单中将会出现Zen coding相关子菜单</li>
</ol>
<p>注意事项：</p>
<ul>
<li>Aptana版的官方插件是基于MAC机的，如果你用的是Windows，需要手动更改快捷键(在每个文件头部的注释片段中更改)</li>
<li>官方的文件编码有点儿乱，修改官方js的时候，请注意<strong>编码问题</strong>，修改不当会造成相关功能的丢失；</li>
</ul>
<h4>DreamWeaver</h4>
<p>好消息是，现在已经有了Zen coding for DreamWeaver插件，坏消息是，该插件支持的功能很少，只支持展开缩写功能。而且默认的快捷键是无效的。只能在“命令”菜单中点击操作。另外，没有测试该插件是不是只支持CS4版本。不过比较好的是，作者将本插件的源码也放出了，你可以自定义一个Dreamweaver的插件。</p>
<p>事实上，官方的DW插件在Windows下有点儿bug，就是会出现空白的行，我简单的修正了下，重新编译了个包，在本机测试没问题，感兴趣的童鞋可以下载尝试：<a rel="external nofollow" href="http://www.boxcn.net/shared/c71z7x7sfe" target="_blank">http://www.boxcn.net/shared/c71z7×7sfe</a></p>
<h3>原作者介绍：</h3>
<p>Sergey Chikuyonok是一位俄罗斯的前端开发工程师和作者，他在优化方面有很大的热情：从图片、JavaScript效果到工作流程和节省时间的编码。访问<a rel="external nofollow" href="http://chikuyonok.ru/" target="_blank">他的主页</a>和<a rel="external nofollow" href="http://twitter.com/chikuyonok" target="_blank">他的Twitter</a>。</p>
<div>原文：<a rel="external nofollow" href="http://www.smashingmagazine.com/2009/11/21/zen-coding-a-new-way-to-write-html-code/" rel="external nofollow">Smashing Magazine</a><br />
<br />
翻译：<a rel="external nofollow" href="http://www.qianduan.net/zen-coding-a-new-way-to-write-html-code.html" rel="external nofollow">Zen Coding: 一种快速编写HTML/CSS代码的方法</a>
</div>
<h2  class="related_post_title">Related Posts / 相关文章</h2><ul class="related_post"><li><a href="http://slj.me/2009/03/browser_css_hack_ie_ff/" title="关于一些浏览器的的Hack">关于一些浏览器的的Hack</a></li><li><a href="http://slj.me/2010/05/html5-new-features/" title="HTML5新功能演示">HTML5新功能演示</a></li><li><a href="http://slj.me/2010/03/building-iphone-apps-with-html-css-and-javascript/" title="【好书PDF】：Building iPhone Apps with HTML, CSS, and JavaScript">【好书PDF】：Building iPhone Apps with HTML, CSS, and JavaScript</a></li><li><a href="http://slj.me/2009/12/html5-css3/" title="揭秘HTML5和CSS3">揭秘HTML5和CSS3</a></li><li><a href="http://slj.me/2010/07/css-rgba/" title="CSS中的RGBa色彩">CSS中的RGBa色彩</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2009/12/%e7%89%9bx%e6%97%a0%e6%95%8c%ef%bc%81%ef%bc%81%ef%bc%81zen-coding-%e4%b8%80%e7%a7%8d%e5%bf%ab%e9%80%9f%e7%bc%96%e5%86%99htmlcss%e4%bb%a3%e7%a0%81%e7%9a%84%e6%96%b9%e6%b3%95/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>20多个漂亮的使用jQuery交互的网站设计欣赏</title>
		<link>http://slj.me/2009/12/20-more-beautiful-interactive-website-design-using-jquery/</link>
		<comments>http://slj.me/2009/12/20-more-beautiful-interactive-website-design-using-jquery/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 15:42:47 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://kiya.cn/?p=1367</guid>
		<description><![CDATA[jQuery是使用最多的JS库之一，它有很多优点，比如轻量、易用、完善的Ajax、良好的浏览器兼容，以及它有健壮的选择器等。 这些优点使得jQuery成为帮助前端开发人员的有力工具。越来越多的大型网站开始使用jQuery及其插件实现其前端交互。 今天展示的20个jQuery交互的网站设计不仅交互效果很酷，界面设计的也很棒，希望能够给你的设计提供某些参考。 当然，使用jQuery的优秀的网站并不只这些，如果你知道有很不错的基于jQuery的网站设计，欢迎与我们共享，多谢。 翻页、滑动、lightbox – serialcut.com 滑动、导航 – tearoundapp.com 滑动、导航 – mtvsticky.com 滑动、动画 – worldofmerix.com 滑动、拖拽 – icondock.com 滑动、导航 – directdesign.it 翻页、弹出 – jumpstartforbusiness.co.uk 滑动, Lightbox – 10bestthings.com 滑动 – paramoreredd.com 滑动 – bulletpr.co.uk 滑动、淡出、Ajax、导航 – bestbefore.ro lightbox、Ajax – www.geochirp.com 滑动、导航 – eyedraw.eu LightBox、Ajax、拖拽 – rachelbloch.ch 滑动、动画 – marfil.me 动画、提示 – jquerystyle.com 弹出、Ajax、提示 – [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>jQuery是使用最多的JS库之一，它有很多优点，比如轻量、易用、完善的Ajax、良好的浏览器兼容，以及它有健壮的选择器等。</p>
<p>这些优点使得jQuery成为帮助前端开发人员的有力工具。越来越多的大型网站开始使用jQuery及其插件实现其前端交互。</p>
<p><span id="more-1367"></span><span> </span></p>
<p>今天展示的20个jQuery交互的网站设计不仅交互效果很酷，界面设计的也很棒，希望能够给你的设计提供某些参考。</p>
<p>当然，使用jQuery的优秀的网站并不只这些，如果你知道有很不错的基于jQuery的网站设计，欢迎与我们共享，多谢。</p>
<h4>翻页、滑动、lightbox – serialcut.com</h4>
<p><a title="serialcut.com" href="http://www.serialcut.com/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/serialcut.jpg" alt="serialcut.com" /></a></p>
<h4>滑动、导航 – tearoundapp.com</h4>
<p><a title="tearoundapp.com - 滑动、导航" href="http://tearoundapp.com/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/tearoundapp.jpg" alt="tearoundapp.com - 滑动、导航" /></a></p>
<h4>滑动、导航 – mtvsticky.com</h4>
<p><a title="mtvsticky.com - 滑动、导航" href="http://www.mtvsticky.com/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/mtv-sticky.jpg" alt="mtvsticky.com - 滑动、导航" /></a></p>
<h4>滑动、动画 – worldofmerix.com</h4>
<p><a title="worldofmerix.com - 滑动、动画" href="http://www.worldofmerix.com/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/worldofmerix.jpg" alt="worldofmerix.com - 滑动、动画" /></a></p>
<h4>滑动、拖拽 – icondock.com</h4>
<p><a title="icondock.com - 滑动、拖拽" href="http://icondock.com/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/icondock.jpg" alt="icondock.com - 滑动、拖拽" /></a></p>
<h4>滑动、导航 – directdesign.it</h4>
<p><a title="directdesign.it - 滑动、导航" href="http://www.directdesign.it/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/directdesign.jpg" alt="directdesign.it - 滑动、导航" /></a></p>
<h4>翻页、弹出 – jumpstartforbusiness.co.uk</h4>
<p><a title="jumpstartforbusiness.co.uk - 翻页、弹出" href="http://www.jumpstartforbusiness.co.uk/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/jumpstartforbusiness.jpg" alt="jumpstartforbusiness.co.uk - 翻页、弹出" /></a></p>
<h4>滑动, Lightbox – 10bestthings.com</h4>
<p><a title="10bestthings.com - 滑动, Lightbox" href="http://www.10bestthings.com/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/10bestthings.jpg" alt="10bestthings.com - 滑动, Lightbox" /></a></p>
<h4>滑动 – paramoreredd.com</h4>
<p><a title="paramoreredd.com - 滑动" href="http://paramoreredd.com/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/paramoreredd.jpg" alt="paramoreredd.com - Slide-Effects" /></a></p>
<h4>滑动 – bulletpr.co.uk</h4>
<p><a title="bulletpr.co.uk - 滑动" href="http://bulletpr.co.uk/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/bulletpr.jpg" alt="bulletpr.co.uk - 滑动" /></a></p>
<h4>滑动、淡出、Ajax、导航 – bestbefore.ro</h4>
<p><a title="bestbefore.ro" href="http://bestbefore.ro/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/bestbefore.jpg" alt="bestbefore.ro" /></a></p>
<h4>lightbox、Ajax – www.geochirp.com</h4>
<p><a title="www.geochirp.com" href="http://www.geochirp.com/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/geochirp.jpg" alt="www.geochirp.com" /></a></p>
<h4>滑动、导航 – eyedraw.eu</h4>
<p><a title="eyedraw.eu - 滑动、导航" href="http://eyedraw.eu/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/eyedraw.jpg" alt="eyedraw.eu - 滑动、导航" /></a></p>
<h4>LightBox、Ajax、拖拽 – rachelbloch.ch</h4>
<p><a title="rachelbloch.ch" href="http://rachelbloch.ch/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/rachelbloch.jpg" alt="rachelbloch.ch" /></a></p>
<h4>滑动、动画 – marfil.me</h4>
<p><a title="marfil.me" href="http://marfil.me/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/marfil.jpg" alt="marfil.me" /></a></p>
<h4>动画、提示 – jquerystyle.com</h4>
<p><a title="jquerystyle.com" href="http://jquerystyle.com/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/jquerystyle.jpg" alt="jquerystyle.com" /></a></p>
<h4>弹出、Ajax、提示 – virtuousquare.fr</h4>
<p><a title="virtuousquare.fr" href="http://www.virtuousquare.fr/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/virtuousquare.jpg" alt="virtuousquare.fr" /></a></p>
<h4>滑动、动画 – bonadiesarchitect.com</h4>
<p><a title="bonadiesarchitect.com" href="http://bonadiesarchitect.com/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/bonadiesarchitect.jpg" alt="bonadiesarchitect.com" /></a></p>
<h4>滑动、热键 – pauljnoble.com</h4>
<p><a title="pauljnoble.com" href="http://www.pauljnoble.com/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/pauljnoble.jpg" alt="pauljnoble.com" /></a></p>
<h4>翻页、滑动、lightbox – ormanclark.com</h4>
<p><a title="ormanclark.com" href="http://www.ormanclark.com/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/ormanclark.jpg" alt="ormanclark.com" /></a></p>
<h4>提示、lightbox – tedxbucharest.com</h4>
<p><a title="tedxbucharest.com" href="http://www.tedxbucharest.com/" target="_blank"><img src="http://kiya.cn/wp-content/uploads/2009/12/tedxbucharest.jpg" alt="tedxbucharest.com" /></a></div>
<h2  class="related_post_title">Related Posts / 相关文章</h2><ul class="related_post"><li><a href="http://slj.me/2010/10/20-jquery-new-effects/" title="20个jQuery新效果">20个jQuery新效果</a></li><li><a href="http://slj.me/2010/03/45-fresh-useful-javascript-and-jquery-techniques-and-tools/" title="[英,转]45个新鲜有用的JS与jQuery技术和工具">[英,转]45个新鲜有用的JS与jQuery技术和工具</a></li><li><a href="http://slj.me/2010/01/10%e4%b8%aajquery-lightbox%e6%95%88%e6%9e%9c%e6%8f%92%e4%bb%b6/" title="10个jQuery Lightbox效果插件">10个jQuery Lightbox效果插件</a></li><li><a href="http://slj.me/2009/12/lazyload/" title="LazyLoad &#8211; jQuery延迟载入插件">LazyLoad &#8211; jQuery延迟载入插件</a></li><li><a href="http://slj.me/2009/12/the-best-jquery-plugins-of-2009/" title="2009 年度最佳 jQuery 插件">2009 年度最佳 jQuery 插件</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2009/12/20-more-beautiful-interactive-website-design-using-jquery/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>2009 年度最佳 jQuery 插件</title>
		<link>http://slj.me/2009/12/the-best-jquery-plugins-of-2009/</link>
		<comments>http://slj.me/2009/12/the-best-jquery-plugins-of-2009/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 17:15:28 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Plugins]]></category>

		<guid isPermaLink="false">http://kiya.cn/?p=1329</guid>
		<description><![CDATA[jQuery 是个宝库，而 jQuery 的插件体系是个取之不竭的宝库，众多开发者在 jQuery 框架下，设计了数不清的插件，jQuery  的特长是网页效果，因此，它的插件库也多与 UI 有关。本文是 webdesignledger.com 网站推选的2009年度最佳 jQuery 插件。 拉洋片 在一个固定区域，循环显示几段内容，这种方式很像旧时的拉洋片，2009年，这种 Web 效果大行其道，jQuery 有大量与此有关的插件，以下插件无疑是最佳的。 AnythingSlider 由 CSS-Tricks 的 Chris Coyier 设计，功能齐全，应用十分广泛。 Easy Slider 这个 Content Slider 插件既包含传统“前后”导航模式，又包含页码式导航。 Coda-Slider 2.0 Coda-Slider 2.0 是对 Panic Coda 网站上对应效果的模仿。 图片库 那些需要借助 Flash 实现滑动与渐入渐出效果图片库的日子已经去过，借助 jQuery，这种效果已经可以在本地实现，以下是本年度备受欢迎的几个 jQuery 图片库插件。 Galleria 这是一个基于 jQuery 的图片库，可以逐个加载图片并显示缩略图。 jQuery Panel Gallery 一个可以高度定义的图片库插件，无需对单个图片进行任何处理，这个插件会帮你完成一切。 slideViewer [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-1391" title="jquery_2009" src="http://kiya.cn/wp-content/uploads/2009/12/jquery_2009.jpg" alt="jquery_2009" width="485" height="161" /></p>
<p>jQuery 是个宝库，而 jQuery 的插件体系是个取之不竭的宝库，众多开发者在 jQuery 框架下，设计了数不清的插件，jQuery  的特长是网页效果，因此，它的插件库也多与 UI 有关。本文是 <a rel="external nofollow" href="http://www.webdesignledger.com/">webdesignledger.com</a> 网站推选的2009年度最佳 jQuery 插件。</p>
<p>拉洋片<br />
在一个固定区域，循环显示几段内容，这种方式很像旧时的拉洋片，2009年，这种 Web 效果大行其道，jQuery 有大量与此有关的插件，以下插件无疑是最佳的。<br />
<span id="more-1329"></span><a rel="external nofollow" href="http://css-tricks.com/anythingslider-jquery-plugin/">AnythingSlider</a><br />
<a rel="external nofollow" href="http://css-tricks.com/anythingslider-jquery-plugin/"><img style="border: #c0c0c0 1px solid;" src="http://kiya.cn/wp-content/uploads/2009/12/jquery_2009_1.jpg" alt="jquery plugins" /></a></p>
<p>由 CSS-Tricks 的 Chris Coyier 设计，功能齐全，应用十分广泛。<br />
<a rel="external nofollow" href="http://cssglobe.com/post/5780/easy-slider-17-numeric-navigation-jquery-slider">Easy Slider</a><br />
<a rel="external nofollow" href="http://cssglobe.com/post/5780/easy-slider-17-numeric-navigation-jquery-slider"><img style="border: #c0c0c0 1px solid;" src="http://kiya.cn/wp-content/uploads/2009/12/jquery_2009_3.jpg" alt="jquery plugins" /></a></p>
<p>这个 Content Slider 插件既包含传统“前后”导航模式，又包含页码式导航。<br />
<a rel="external nofollow" href="http://www.ndoherty.biz/tag/coda-slider/">Coda-Slider 2.0</a><br />
<a rel="external nofollow" href="http://www.ndoherty.biz/tag/coda-slider/"><img style="border: #c0c0c0 1px solid;" src="http://kiya.cn/wp-content/uploads/2009/12/jquery_2009_7.jpg" alt="jquery plugins" /></a></p>
<p>Coda-Slider 2.0 是对 Panic Coda 网站上对应效果的模仿。<br />
图片库<br />
那些需要借助 Flash 实现滑动与渐入渐出效果图片库的日子已经去过，借助 jQuery，这种效果已经可以在本地实现，以下是本年度备受欢迎的几个 jQuery 图片库插件。<br />
<a rel="external nofollow" href="http://devkick.com/lab/galleria/">Galleria</a><br />
<a rel="external nofollow" href="http://devkick.com/lab/galleria/"><img src="http://kiya.cn/wp-content/uploads/2009/12/jquery_2009_4.jpg" alt="jquery plugins" /></a></p>
<p>这是一个基于 jQuery 的图片库，可以逐个加载图片并显示缩略图。<br />
<a rel="external nofollow" href="http://www.catchmyfame.com/2009/08/13/jquery-panel-gallery-1-1-plugin-released/">jQuery Panel Gallery</a><br />
<a rel="external nofollow" href="http://www.catchmyfame.com/2009/08/13/jquery-panel-gallery-1-1-plugin-released/"><img src="http://kiya.cn/wp-content/uploads/2009/12/jquery_2009_5.jpg" alt="jquery plugins" /></a></p>
<p>一个可以高度定义的图片库插件，无需对单个图片进行任何处理，这个插件会帮你完成一切。<br />
<a rel="external nofollow" href="http://www.gcmingati.net/wordpress/wp-content/lab/jquery/imagestrip/imageslide-plugin.html">slideViewer</a><br />
<a rel="external nofollow" href="http://www.gcmingati.net/wordpress/wp-content/lab/jquery/imagestrip/imageslide-plugin.html"><img src="http://kiya.cn/wp-content/uploads/2009/12/jquery_2009_10.jpg" alt="jquery plugins" /></a></p>
<p>slideViewer 会检查你的图片列表中的编号，动态创建各个图片的页码浏览导航。<br />
<a rel="external nofollow" href="http://www.buildinternet.com/project/supersized/">Supersized</a><br />
<a rel="external nofollow" href="http://www.buildinternet.com/project/supersized/"><img src="http://kiya.cn/wp-content/uploads/2009/12/jquery_2009_6.jpg" alt="jquery plugins" /></a></p>
<p>一个令人惊讶的图片循环展示插件，包含各种变换效果和预加载选项，会对图片自动改变尺寸以适应浏览器窗口。<br />
导航<br />
我们相信，作为网站的导航系统，应该越简单，越易用越好，然而，假如你确实希望实现一些更炫的效果，jQuery 就是最好的选项，以下插件是09年最好的 jQuery 导航插件。<br />
<a rel="external nofollow" href="http://pupunzi.open-lab.com/mb-jquery-components/mb-_menu/">jquery mb.menu</a><br />
<a rel="external nofollow" href="http://pupunzi.open-lab.com/mb-jquery-components/mb-_menu/"><img style="border: #c0c0c0 1px solid;" src="http://kiya.cn/wp-content/uploads/2009/12/jquery_2009_8.jpg" alt="jquery plugins" /></a><br />
<a rel="external nofollow" href="http://www.queness.com/post/256/horizontal-scroll-menu-with-jquery-tutorial">Horizontal Scroll Menu with jQuery </a><br />
<a rel="external nofollow" href="http://www.queness.com/post/256/horizontal-scroll-menu-with-jquery-tutorial"><img style="border: #c0c0c0 1px solid;" src="http://kiya.cn/wp-content/uploads/2009/12/jquery_2009_16.jpg" alt="jquery plugins" /></a><br />
<a rel="external nofollow" href="http://www.newmediacampaigns.com/page/autosprites-jquery-menu-plugin">AutoSprites</a><br />
<a rel="external nofollow" href="http://www.newmediacampaigns.com/page/autosprites-jquery-menu-plugin"><img style="border: #c0c0c0 1px solid;" src="http://kiya.cn/wp-content/uploads/2009/12/jquery_2009_9.jpg" alt="jquery plugins" /></a><br />
表单和表格<br />
在 Web 设计中，表单和表格都是不是很讨人喜欢的东西，但你不得不面对，本年度出现几个不错的 jQuery 插件帮你完成这些任务。<br />
<a rel="external nofollow" href="http://www.unwrongest.com/projects/password-strength/">Password Strength</a><br />
<a rel="external nofollow" href="http://www.unwrongest.com/projects/password-strength/"><img src="http://kiya.cn/wp-content/uploads/2009/12/jquery_2009_12.jpg" alt="jquery plugins" /></a></p>
<p>这个插件帮你评估用户输入的密码是否足够强壮。<br />
<a rel="external nofollow" href="http://www.webdesignbeach.com/beachbar/ajax-fancy-captcha-jquery-plugin">Ajax Fancy Capcha</a><br />
<a rel="external nofollow" href="http://www.webdesignbeach.com/beachbar/ajax-fancy-captcha-jquery-plugin"><img style="border: #c0c0c0 1px solid;" src="http://kiya.cn/wp-content/uploads/2009/12/jquery_2009_13.jpg" alt="jquery plugins" /></a></p>
<p>顾名思义，一个支持 Ajax 又很炫的 jQuery Captcha 插件，它使用了很人性化的验证机制。<br />
<a rel="external nofollow" href="http://www.chromaloop.com/posts/chromatable-jquery-plugin">Chromatable</a><br />
<a rel="external nofollow" href="http://www.chromaloop.com/posts/chromatable-jquery-plugin"><img style="border: #c0c0c0 1px solid;" src="http://webdesignledger.com/wp-content/uploads/2009/11/jquery_tables_10.jpg" alt="jquery tables" /></a></p>
<p>这个插件可以帮助你在表格上实现滚动条。<br />
<a rel="external nofollow" href="http://www.dfc-e.com/metiers/multimedia/opensource/jqtransform/">jqTransform</a><br />
<a rel="external nofollow" href="http://www.dfc-e.com/metiers/multimedia/opensource/jqtransform/"><img style="border: #c0c0c0 1px solid;" src="http://kiya.cn/wp-content/uploads/2009/12/jquery_2009_14.jpg" alt="jquery plugins" /></a></p>
<p>一个式样插件，帮助你对表单中的控件进行式样控制。<br />
<a rel="external nofollow" href="http://www.uploadify.com/">Uploadify</a><br />
<a rel="external nofollow" href="http://www.uploadify.com/"><img style="border: #c0c0c0 1px solid;" src="http://kiya.cn/wp-content/uploads/2009/12/jquery_2009_15.jpg" alt="jquery plugins" /></a></p>
<p>实现多个文件同时上传。<br />
<a rel="external nofollow" href="http://www.jankoatwarpspeed.com/post/2009/07/20/Expand-table-rows-with-jQuery-jExpand-plugin.aspx">jExpand </a><br />
<a rel="external nofollow" href="http://www.jankoatwarpspeed.com/post/2009/07/20/Expand-table-rows-with-jQuery-jExpand-plugin.aspx"><img style="border: #c0c0c0 1px solid;" src="http://webdesignledger.com/wp-content/uploads/2009/11/jquery_tables_1.jpg" alt="jquery tables" /></a></p>
<p>一个很轻量的 jQuery 插件，使你的表格可以扩展，在一些商业应用中，可以让表格更容易组织其中的内容。</p>
<p>英文原版：<a rel="external nofollow" href="http://webdesignledger.com/resources/the-best-jquery-plugins-of-2009">http://webdesignledger.com/resources/the-best-jquery-plugins-of-2009</a></p>
<h2  class="related_post_title">Related Posts / 相关文章</h2><ul class="related_post"><li><a href="http://slj.me/2010/10/20-jquery-new-effects/" title="20个jQuery新效果">20个jQuery新效果</a></li><li><a href="http://slj.me/2010/03/45-fresh-useful-javascript-and-jquery-techniques-and-tools/" title="[英,转]45个新鲜有用的JS与jQuery技术和工具">[英,转]45个新鲜有用的JS与jQuery技术和工具</a></li><li><a href="http://slj.me/2010/01/10%e4%b8%aajquery-lightbox%e6%95%88%e6%9e%9c%e6%8f%92%e4%bb%b6/" title="10个jQuery Lightbox效果插件">10个jQuery Lightbox效果插件</a></li><li><a href="http://slj.me/2009/12/lazyload/" title="LazyLoad &#8211; jQuery延迟载入插件">LazyLoad &#8211; jQuery延迟载入插件</a></li><li><a href="http://slj.me/2009/12/20-more-beautiful-interactive-website-design-using-jquery/" title="20多个漂亮的使用jQuery交互的网站设计欣赏">20多个漂亮的使用jQuery交互的网站设计欣赏</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2009/12/the-best-jquery-plugins-of-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>YUI 2.8.0 发布</title>
		<link>http://slj.me/2009/09/yui-2-8-0-released/</link>
		<comments>http://slj.me/2009/09/yui-2-8-0-released/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 05:58:01 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Structure]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[YUI]]></category>
		<category><![CDATA[发布]]></category>

		<guid isPermaLink="false">http://kiya.cn/?p=770</guid>
		<description><![CDATA[这次发布共增加了 4 个组件： 1. Storage Utility 这个组件实现了本地存储的功能，提供了一个HTML5风格的借口，你可以利用这个接口进行本地存储，它提供三种解决方案：HTML5 存储、利用Google Gears存储 和 利用 Flash Share Object 存储。随着支持 HTML5 标准的浏览器越来越多，这三种存储方案可以覆盖大部分的用户了。 2. SWFStore Utility 这个组件为上个组件 Storage Utility 提供 Flash Share Object 存储的功能，并且包括了一个利用 Flash Share Object 存储文本的 JavaScript API 。它对存储的键值对 支持即时的 gzip 压缩，这可以让你不会很容易超过 100KB 的 Flash 默认的本地存储上限（当然，如果用户同意的话这个上限是可以更改的） ，可以有效地帮助你节省空间。 3. SWF Utility 这个组件是一个用来把 Flash 嵌入到页面中的轻量级工具。需要注意的是，它只使用&#60;object&#62;标签来嵌入 Flash，而并不是所有的浏览器都支持这个标签。 4. ProgressBar Control 一个高度可定制的进度条组件。 此外，在 [...]]]></description>
			<content:encoded><![CDATA[<p>这次发布共增加了 4 个组件：</p>
<p>1. <a href="http://developer.yahoo.com/yui/storage/" rel="external nofollow">Storage Utility</a><br />
这个组件实现了本地存储的功能，提供了一个HTML5风格的借口，你可以利用这个接口进行本地存储，它提供三种解决方案：HTML5 存储、利用Google Gears存储 和 利用 Flash Share Object 存储。随着支持 HTML5 标准的浏览器越来越多，这三种存储方案可以覆盖大部分的用户了。</p>
<p>2. <a href="http://developer.yahoo.com/yui/swfstore/" rel="external nofollow">SWFStore Utility</a><br />
这个组件为上个组件 <a href="http://developer.yahoo.com/yui/storage/" rel="external nofollow">Storage Utility</a> 提供 Flash Share Object 存储的功能，并且包括了一个利用 Flash Share Object 存储文本的 JavaScript API 。它对存储的键值对 支持即时的 gzip 压缩，这可以让你不会很容易超过 100KB 的 Flash 默认的本地存储上限（当然，如果用户同意的话这个上限是可以更改的） ，可以有效地帮助你节省空间。<br />
<span id="more-770"></span><br />
3. <a href="http://developer.yahoo.com/yui/swf/" rel="external nofollow">SWF Utility</a><br />
这个组件是一个用来把 Flash 嵌入到页面中的轻量级工具。需要注意的是，它只使用&lt;object&gt;标签来嵌入 Flash，而并不是所有的浏览器都支持这个标签。</p>
<p>4. <a href="http://developer.yahoo.com/yui/progressbar/" rel="external nofollow">ProgressBar Control</a><br />
一个高度可定制的进度条组件。</p>
<p>此外，在 YUI 2.8.0 中还有很多bug fix 以及重要改进：</p>
<p>1. Connection Manager 支持跨域。 Connection Manager 利用 Flash 实现了跨域请求的功能，并且Connection Manager 的核心功能也被剥离到了 connection-core 这个模块中，如果你只是想用 Connection Manager 实现简单的 XHR ，可以只使用 connection-core 这个模块。</p>
<p>2. <a href="http://developer.yahoo.com/yui/charts/" rel="external nofollow">YUI Charts</a> 开始支持多个坐标轴。</p>
<p>3. 更多改进请看 <a href="http://yuilibrary.com/projects/yui2/wiki/ReadMe/Rollup_2.8.0" rel="external nofollow">YUI 2.8.0 的 README</a></p>
<p>这次发布一个有意思的事情是，有一些重要的组件其实是 Yahoo 之外的人编写的，YUI 开源绝对是个明智之举啊。现在 <a href="http://github.com/yui/yui3/tree/master" rel="external nofollow">YUI 的源码都在 github 上</a>，你要是有热情有能力，也可以参与一下。如果你不了解Git，可以到<a href="http://git-scm.com/" rel="external nofollow">Git官方网站</a>上学习一下，这个版本控制系统很强大，学了肯定用得着。</p>
<p><a href="http://www.yuiblog.com/blog/2009/09/14/yui-2-8-0/" rel="external nofollow">更多请看 YUI Blog</a> 。</p>
<p>转：http://www.zhuoqun.net/html/y2009/1375.html</p>
<h2  class="related_post_title">Related Posts / 相关文章</h2><ul class="related_post"><li><a href="http://slj.me/2010/10/debug-and-release-iphone-app/" title="如何联机调试和发布 iPhone App">如何联机调试和发布 iPhone App</a></li><li><a href="http://slj.me/2009/04/yui-reset-css/" title="Reset CSS &#8211; 复位(重置) CSS">Reset CSS &#8211; 复位(重置) CSS</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2009/09/yui-2-8-0-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>【转】使用 Dojo 的 Ajax 应用开发进阶教程 : 富含语义的 HTML</title>
		<link>http://slj.me/2009/07/dojo-ajax-semanticize-html/</link>
		<comments>http://slj.me/2009/07/dojo-ajax-semanticize-html/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 12:16:40 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[语义化]]></category>

		<guid isPermaLink="false">http://kiya.cn/?p=663</guid>
		<description><![CDATA[HTML 语言是互联网的基础。如何正确合理的编写 HTML 文档，是很多 Web 开发人员关心的问题。富含语义的 HTML 是一种 Web 应用开发的实践，它强调从文档所需要表达的语义出发，使用 HTML 语法中表示文档结构和富含语义的元素来编写 HTML 文档，从而使得 Web 应用的结构与展示分离，降低各部分之间的耦合度。随着 Ajax 应用的流行，这种实践越来越为 Web 开发人员所接受。本文详细介绍富含语义的 HTML 这一开发实践，供 Web 开发人员参考。 HTML 是开发 Web 应用的基础。目前已经有数以千亿的使用 HTML 语言编写的网页。HTML 语言的规范也不断在演进和更新。HTML 语言虽然上手比较简单，但是如何开发出组织良好、结构清晰和可维护性高的 HTML 文档，对很多 Web 开发人员来说，也是一个值得探讨的话题。随着 Ajax 应用的流行，一种称为“富含语义的 HTML（Semantic HTML）”的最佳实践，逐渐被广大 Web 开发人员所推崇。这种实践的主要思想是还 HTML 以本来面目，只使用 HTML 来描述文档的结构，而把与展示相关的部分从 HTML 文档中剥离出去，交给 CSS 来处理。本文将详细介绍这一最佳实践，涉及的内容包括 HTML 规范的演化历史、推荐使用的 HTML 元素和属性、一系列具体的最佳实践和微格式。 下面从富含语义的 [...]]]></description>
			<content:encoded><![CDATA[<p>HTML 语言是互联网的基础。如何正确合理的编写 HTML 文档，是很多 Web 开发人员关心的问题。富含语义的 HTML 是一种 Web 应用开发的实践，它强调从文档所需要表达的语义出发，使用 HTML 语法中表示文档结构和富含语义的元素来编写 HTML 文档，从而使得 Web 应用的结构与展示分离，降低各部分之间的耦合度。随着 Ajax 应用的流行，这种实践越来越为 Web 开发人员所接受。本文详细介绍富含语义的 HTML 这一开发实践，供 Web 开发人员参考。<br />
<span id="more-663"></span></p>
<p>HTML 是开发 Web 应用的基础。目前已经有数以千亿的使用 HTML 语言编写的网页。HTML 语言的规范也不断在演进和更新。HTML 语言虽然上手比较简单，但是如何开发出组织良好、结构清晰和可维护性高的 HTML 文档，对很多 Web 开发人员来说，也是一个值得探讨的话题。随着 Ajax 应用的流行，一种称为“富含语义的 HTML（Semantic HTML）”的最佳实践，逐渐被广大 Web 开发人员所推崇。这种实践的主要思想是还 HTML 以本来面目，只使用 HTML 来描述文档的结构，而把与展示相关的部分从 HTML 文档中剥离出去，交给 CSS 来处理。本文将详细介绍这一最佳实践，涉及的内容包括 HTML 规范的演化历史、推荐使用的 HTML 元素和属性、一系列具体的最佳实践和微格式。</p>
<p> 下面从富含语义的 HTML 的简要介绍开始，所涉及的内容包括 HTML 规范历史以及它与 CSS 和 JavaScript 的关系。</p>
<p><a name="N100A3"><span class="atitle"> 富含语义的 HTML 介绍 </span></a></p>
<p> 富含语义的 HTML（Semantic HTML）指的是编写 HTML 文档的一种很好的实践。这种实践要求在编写 HTML 文档时，尽可能的使用 HTML 规范中定义的与文档结构相关的富含语义的元素，而避免使用与展示相关的元素，将展示相关的内容交给 CSS 去处理。通过应用这种实践，可以将 HTML 文档的结构与展示分离，使两者达到松散耦合。这种松散耦合带来的好处是使得结构和展示可以分别独立变化，不会杂糅在一起。当只需要修改 Web 应用的外观时，理想情况下，Web 应用的 HTML 文档都不需要修改，只需要修改 CSS 文件即可。</p>
<p>Ajax 应用的流行，从一个方面推动了这种实践的流行。目前的 Web 2.0 应用都要求快速上线，并且以渐进的方式不断推出新功能，即所谓的“永远 beta 版（perpetual beta）”。这种需求对于 Web 应用的架构有比较高的要求。只有在各个部分松散耦合的情况下，快速添加新功能或改进已有功能才是可能的。富含语义的 HTML 的实践促进了 Web 应用的松散耦合，因此越来越被广大 Web 开发人员所接受。另外，HTML 语言自身的演化发展，也从一个侧面反映出了这个趋势。下面将从简要介绍 HTML 语言的历史开始，并介绍富含语义的 HTML 与 CSS 和 Ajax 应用的关系。</p>
<p><a name="N100AF"><span class="smalltitle">HTML 的历史 </span></a></p>
<p>HTML 语言从诞生之日起一直在不断演化，其规范的版本也有很多。HTML 的发展历史可以简要地概括如下。可以在 <a rel="external nofollow" href="#resources"> 参考资料 </a> 中找到这些规范的链接。</p>
<dl>
<dt><b>HTML 最初的草案 </b></dt>
<dd>	HTML 最早使用在欧洲核子能研究机构中，用来方便研究人员使用和共享文档。在 1991 年出现的关于 HTML 的最早的说明中，HTML 中共包含 22 个元素，其中的 13 个保留到了 HTML 4 中。由于 HTML 最初是用来描述科学文档的，这 22 个元素基本都是用来描述文档的结构的。比如 &lt;a&gt; 用来表示文档之间的超链接；&lt;p&gt; 表示文档中的段落；&lt;h1&gt;、&lt;h2&gt;、&lt;h3&gt;、&lt;h4&gt;、&lt;h5&gt; 和 &lt;h6&gt; 用来表示不同级别的标题。
		</dd>
<dt><b>HTML 2.0</b></dt>
<dd>HTML 2.0 规范在 1995 年 11 月发布为 RFC 1866。2.0 规范中增加了 &lt;img&gt; 和与表单提交相关的 &lt;form&gt;、&lt;input&gt; 和 &lt;select&gt; 等元素。</dd>
<dt><b>HTML 3.2</b></dt>
<dd>HTML 3.2 规范在 1997 年 1 月作为 W3C 的推荐规范发布。正是在这个版本中，由 Netscape 和微软的 Internet Explorer 引入的很多与展示相关的元素被规范化。这些元素包括 &lt;font&gt;、&lt;basefont&gt;、&lt;strong&gt;、&lt;strike&gt;、&lt;u&gt;、&lt;b&gt; 和 &lt;center&gt; 等。这些元素使得 HTML 页面的结构与展示被杂糅在一起。</dd>
<dt><b>HTML 4.01</b></dt>
<dd>HTML 4.01 规范在 1999 年 12 月作为 W3C 的推荐规范发布，并于 2000 年 5 月成为国际标准。HTML 4.01 规范试图解决 HTML 3.2 规范中引入的与展示相关的元素的问题，与此同时，又需要考虑规范的向后兼容性。HTML 4.01 规范把许多与表示相关的元素标记为废弃的，不推荐使用。同时引入了三种“风格（flavor）”。在“严格（Strict）”风格中，废弃的元素是不能使用的；在“过渡性（Transitional）”风格中，废弃的元素是可以使用的；在“框架（Frameset）”风格中，只允许使用与框架相关的元素。</dd>
<dt><b>HTML 5</b></dt>
<dd> 作为 HTML 规范的下一个版本，HTML 5 引入了更多富含语义的元素，如 &lt;nav&gt; 表示网站的导航栏，&lt;section&gt; 表示文档中的章节；与此同时，在 HTML 4.01 中被废弃的一些元素，如 &lt;center&gt; 和 &lt;font&gt; 等被移除了。</dd>
</dl>
<p> 从上面列出的 HTML 规范的历史中可以看出，HTML 从仅包含表示文档结构的元素，到后来引入了与展示相关的元素，再到目前两者并存，以及下一个版本中展示相关的元素部分被移除。HTML 规范的发展趋势是与展示相关的元素将逐步消失。HTML 文档应该描述文档本身，而不应该描述文档如何展示给用户。HTML 规范的发展以一种螺旋式上升的方式实践着这个最初的目标。</p>
<p><a name="N100DF"><span class="smalltitle"> 富含语义的 HTML 与 CSS</span></a></p>
<p> 在 HTML 中，与展示相关的元素的引入，主要是由于当时并没有好的方式来指明 HTML 文档中元素的样式。比如将一段文本用加粗或倾斜的字体来显示。在 CSS 广泛应用之前，只能通过 HTML 元素或属性来实现。由此引入了 &lt;b&gt; 和 &lt;i&gt; 这样的元素。随着 CSS 规范在浏览器中得到广泛的支持，Web 开发人员有了更好的方式来指明 HTML 文档中元素的样式。比如将一段文本加粗显示可以使用 CSS 语法 <code>{font-weight : bold;}</code> 来实现。正是由于 CSS 的出现与流行，富含语义的 HTML 实践才成为可能。</p>
<p><a name="N100EB"><span class="smalltitle"> 富含语义的 HTML 与 Ajax 应用 </span></a></p>
<p> 目前 Ajax 应用非常流行，越来越多的应用采用 Ajax 技术来提高自身的用户体验。Ajax 虽然是基于原有的 HTML、JavaScript 和 CSS 等技术，但是它重新定义了这三种技术在 Web 应用开发中的定位。一个典型的 Ajax 应用的结构如 <a rel="external nofollow" href="#fig-app-structure"> 图 1</a> 所示。</p>
<p><a name="fig-app-structure"><b> 图 1. Ajax 应用的典型结构图 </b></a><br />
	 <img alt="Ajax 应用的典型结构图 " height="273" src="http://kiya.cn/wp-content/uploads/2009/07/app-structure.jpg" width="572"/></p>
<p> 在 <a rel="external nofollow" href="#fig-app-structure"> 图 1</a> 中可以看到，Ajax 应用由三个部分组成，分别是结构、展示和行为。结构指的是应用的基本内容结构，由 HTML 来描述；展示指的是应用的外观，包括颜色、字体大小等样式，由 CSS 来描述；行为指的是应用与用户的交互，包括界面的部分刷新、处理与服务器端的交互等，由 JavaScript 来描述。在这三个部分中，由 HTML 描述的文档结构是整个 Ajax 应用的基础，CSS 通过各种选择器为文档应用样式，而 JavaScript 则通过 DOM 操作来修改文档结构。</p>
<p> 富含语义的 HTML 为 Ajax 应用提供了描述结构的最佳方式。在开发 Ajax 应用时，从一系列富含语义的 HTML 文档出发，将为后面的开发打下良好的基础。HTML 规范中元素和属性众多，而富含语义的 HTML 的实践则推荐使用 HTML 规范中表示文档结构和富含语义的元素和属性。下面将详细介绍这些推荐使用的元素和属性，同时也会讨论那些不建议使用的与展示相关的元素和属性，并说明如何用 CSS 替换它们。</p>
<p>
<p><a name="N1010E"><span class="atitle">HTML 元素与属性 </span></a></p>
<p> 下面将介绍 HTML 4.01 规范中的一些重要的元素与属性。这些元素与属性大致上分成两类，一类是表示文档结构和富含语义的，是推荐使用的；另一类是与文档的展示相关的，是不推荐使用的，而应该用 CSS 来实现相应的展示效果。</p>
<p><a name="N10116"><span class="smalltitle"> 文档结构和富含语义的元素 </span></a></p>
<p> 文档结构和富含语义的元素的介绍见 <a rel="external nofollow" href="#stable"> 表 1</a>。</p>
<p><a name="stable"><b> 表 1. 文档结构和富含语义的元素介绍 </b></a></p>
<table border="1" cellpadding="0" cellspacing="0" class="data-table-1" summary=" 文档结构和富含语义的元素介绍 " width="100%">
<tr>
<th scope="col"> 元素 </th>
<th scope="col"> 说明 </th>
</tr>
<tr>
<td>&lt;h1&gt;、&lt;h2&gt;、&lt;h3&gt;、&lt;h4&gt;、&lt;h5&gt; 和 &lt;h6&gt;</td>
<td>&lt;h1&gt;、&lt;h2&gt;、&lt;h3&gt;、&lt;h4&gt;、&lt;h5&gt; 和 &lt;h6&gt; 等六个元素用来表示不同级别的标题。&lt;h1&gt; 表示重要性最高的，&lt;h6&gt; 表示重要性最低的。浏览器对于不同重要性的标题会有默认的显示样式，一般是通过字体大小来区分。当需要表示文档中每个部分的标题时，推荐使用这六个元素。</td>
</tr>
<tr>
<td>&lt;p&gt;</td>
<td>&lt;p&gt; 元素用来表示文档中的一个段落。HTML 文档中的自然段落推荐使用该元素来表示。</td>
</tr>
<tr>
<td>&lt;em&gt;、&lt;strong&gt;</td>
<td>&lt;em&gt; 和 &lt;strong&gt; 两个元素用来表示对文档中文本的强调。在强调性方面，&lt;strong&gt; 要高于 &lt;em&gt;。浏览器一般把 &lt;em&gt; 中的文本显示为斜体，把 &lt;strong&gt; 中的文本显示为粗体。</td>
</tr>
<tr>
<td>&lt;abbr&gt;、&lt;acronym&gt;</td>
<td>&lt;abbr&gt; 和 &lt;acronym&gt; 元素用来表示缩写词，其中 &lt;abbr&gt; 表示一般的缩写词，如“Inc.”是“incorporated”的缩写；而 &lt;acronym&gt; 表示由首字母组成的缩写词，如“UN”是“United Nations”的缩写。这两个元素的文本是缩写词本身，一般通过 title 属性来说明完整的词组。如 <code>&lt;acronym title="United Nations"&gt;UN&lt;/acronym&gt;。</code></td>
</tr>
<tr>
<td>&lt;blockquote&gt;、&lt;q&gt;</td>
<td>&lt;blockquote&gt; 和 &lt;q&gt; 元素用来表示文档中的引用。如果在文档中需要引用其它人说过的话或是来自其它文献资料的内容，应该使用这两个元素。&lt;blockquote&gt; 用来表示较长的引用，一般自成一个段落；&lt;q&gt; 则表示较短的引用，一般嵌在原始文本中。两个元素的 cite 属性用来给出引用文本的出处（URI）。浏览器通常会把 &lt;blockquote&gt; 显示在缩进的块中，会为 &lt;q&gt; 元素的内容添加引号。下面给出两个元素的示例：&lt;blockquote uri=&#8221;http://americancivilwar.com/north/lincoln.html&#8221;&gt;Four score and seven years ago our fathers brought forth, upon this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.&lt;/blockquote&gt;；&lt;p&gt;As Abraham Lincoln said, &lt;q&gt;all men are created equal&lt;/q&gt;.&lt;/p&gt;</td>
</tr>
<tr>
<td>&lt;ul&gt;、&lt;ol&gt;、&lt;li&gt;</td>
<td>&lt;ul&gt; 和 &lt;ol&gt; 元素用来表示列表型的内容。&lt;ul&gt; 表示的是无序列表；&lt;ol&gt; 表示的是有序列表；&lt;li&gt; 表示列表中的条目。
		 </td>
</tr>
<tr>
<td>&lt;dl&gt;、&lt;dt&gt;、&lt;dd&gt;</td>
<td>&lt;dt&gt; 和 &lt;dd&gt; 元素分别表示术语及其描述。&lt;dl&gt; 表示 &lt;dt&gt; 和 &lt;dd&gt; 对的列表。</td>
</tr>
<tr>
<td>&lt;cite&gt;</td>
<td>&lt;cite&gt; 元素表示对外部资料的引用。与 &lt;blockquote&gt; 和 &lt;q&gt; 元素不同的是，&lt;cite&gt; 里面包含的是资料的名称，而不是内容。如 &lt;cite&gt;JavaScript 高级程序设计 &lt;/cite&gt;</td>
</tr>
<tr>
<td>&lt;code&gt;</td>
<td>&lt;code&gt; 元素表示程序源代码。如果需要在 HTML 文档中嵌入一段计算机代码，应该使用该元素。如 &lt;code&gt;System.out.println(&#8220;Hello World!&#8221;);&lt;/code&gt;</td>
</tr>
</table>
<p><a name="N1018F"><span class="smalltitle"> 与展示相关的元素和属性 </span></a></p>
<p> 与展示相关的元素和属性的介绍见 <a rel="external nofollow" href="#ptable"> 表 2</a>。<a rel="external nofollow" href="#ptable"> 表 2</a> 中给出了相应的 CSS 替代实现方式。</p>
<p><a name="ptable"><b> 表 2. 展示相关的元素和属性介绍 </b></a></p>
<table border="1" cellpadding="0" cellspacing="0" class="data-table-1" summary=" 展示相关的元素和属性介绍 " width="100%">
<tr>
<th scope="col"> 元素或属性 </th>
<th scope="col"> 说明 </th>
<th scope="col"> 替代实现 </th>
</tr>
<tr>
<td>&lt;center&gt;</td>
<td>&lt;center&gt; 元素用来将文档中的一个部分居中显示。</td>
<td> 将一个元素水平居中显示的方式有很多。其中一种做法是使用自动空白边，即：{margin : 0 auto;}</td>
</tr>
<tr>
<td>&lt;font&gt;</td>
<td>&lt;font&gt; 元素用来设置文本的字体。如 &lt;font size=12&gt;Font&lt;/font&gt;</td>
<td> 使用 CSS 来实现：{font : bold 12px;}</td>
</tr>
<tr>
<td>&lt;strike&gt;、&lt;s&gt;</td>
<td>&lt;strike&gt; 和 &lt;s&gt; 元素用来实现在文本中间划线的效果。如 &lt;strike&gt;Sample&lt;/strike&gt;。</td>
<td> 使用 CSS 来实现：{text-decoration:line-through;}</td>
</tr>
<tr>
<td>&lt;u&gt;</td>
<td>&lt;u&gt; 元素用来实现在文本下添加下划线的效果。如 &lt;u&gt;Sample&lt;/u&gt;</td>
<td> 使用 CSS 来实现：{text-decoration:underline;}</td>
</tr>
<tr>
<td>&lt;b&gt;</td>
<td>&lt;b&gt; 元素用来实现文本加粗的效果。</td>
<td> 使用 CSS 来实现：{font-weight : bold;}</td>
</tr>
<tr>
<td>&lt;i&gt;</td>
<td>&lt;i&gt; 元素用来实现文本倾斜的效果。</td>
<td> 使用 CSS 来实现：{font-style: italic;}</td>
</tr>
<tr>
<td>&lt;tt&gt;</td>
<td>&lt;tt&gt; 元素用来表示与打字机效果一样的等宽字体显示。如 &lt;tt&gt;Sample&lt;/tt&gt;</td>
<td> 使用 CSS 中的 font 来设置等宽字体。</td>
</tr>
<tr>
<td>&lt;big&gt;</td>
<td>&lt;big&gt; 元素用来使得文本的字体变大。</td>
<td> 使用 CSS 来实现：{font-size : 200%;}</td>
</tr>
<tr>
<td>&lt;small&gt;</td>
<td>&lt;small&gt; 元素用来使得文本的字体变小。</td>
<td> 使用 CSS 来实现：{font-size : 50%;}</td>
</tr>
<tr>
<td>&lt;hr&gt;</td>
<td>&lt;hr&gt; 元素用来在页面上添加一条水平线。</td>
<td> 可以用 &lt;div&gt; 元素代替 &lt;hr&gt;。通过设置 &lt;div&gt; 的大小和背景颜色来达到同样的效果。</td>
</tr>
<tr>
<td>@color</td>
<td>color 属性用在 &lt;font&gt; 中用来表示字体的颜色。</td>
<td> 使用 CSS 来实现：{color : red;}</td>
</tr>
<tr>
<td>@bgcolor</td>
<td>bgcolor 属性用来设置元素的背景颜色。</td>
<td> 使用 CSS 来实现：{background-color : red;}</td>
</tr>
<tr>
<td>@align</td>
<td>align 属性用来设置元素内容的水平对齐方式。根据所应用的元素的不同，其可选的值也不同。</td>
<td> 需要根据不同的元素选用不同的 CSS 样式。一般情况下，可以用 text-align 来代替。</td>
</tr>
<tr>
<td>@valign</td>
<td>valign 属性用来设置表格中一行的垂直对齐方式。</td>
<td> 根据属性的值不同，使用不同的 CSS。如 <code>valign = bottom</code> 的情况，可以采用绝对定位并设置 bottom 为 0 来实现。</td>
</tr>
<tr>
<td>@face, @size</td>
<td>face 和 size 都是 &lt;font&gt; 元素的属性，分别用来表示字体家族和大小。</td>
<td> 使用 CSS 来实现：{font-family : verdana; font-size : 12px;}</td>
</tr>
</table>
<p />
<p> 上面介绍的这些元素和属性，为编写富含语义的 HTML 文档提供了最基础的构建元素。除此之外，在编写富含语义的 HTML 文档时，还有很多不错的最佳实践可以参考。运用这些实践，将可以从更加宏观的角度来看待富含语义的 HTML。下面将具体介绍这些实践。</p>
<p>
<p><a name="N10279"><span class="atitle"> 最佳实践 </span></a></p>
<p> 在编写富含语义的 HTML 文档时，有一些比较好的做法可以借鉴。遵循这些做法，将帮助避免很多常见的问题。这些好的实践包括在编写 HTML 文档之前需要选用合适的 DTD，编写完成之后需要验证 HTML 文档的语法，在编写过程中需要选用适合的元素和 <code>class</code> 属性来表示语义等。下面将具体介绍如何在具体的 HTML 文档编写过程中应用这些最佳实践。</p>
<p><a name="N10285"><span class="smalltitle"> 选用合适的 DTD</span></a></p>
<p>HTML 文档中的文档类型声明（Document type declaration，DTD）用来声明该文档所使用的 HTML 规范的版本。该声明可以帮助浏览器确定如何显示该文档。目前主流的 HTML 规范版本是 4.01，同时 HTML 4.01 提供三种风格，因此比较常用的 HTML 文档类型声明有 <a rel="external nofollow" href="#dtdtable"> 表 3</a> 中所示的三种。</p>
<p><a name="dtdtable"><b> 表 3. HTML 4.01 规范对应的 DTD 说明 </b></a></p>
<table border="1" cellpadding="0" cellspacing="0" class="data-table-1" summary="HTML 4.01 规范对应的 DTD 说明 " width="100%">
<tr>
<th scope="col"> 文档类型 </th>
<th scope="col"> 文档类型声明 </th>
<th scope="col"> 说明 </th>
</tr>
<tr>
<td>HTML 4.01 严格型 </td>
<td>&lt;!DOCTYPE HTML PUBLIC &#8220;-//W3C//DTD HTML 4.01//EN&#8221;<br />
&#8220;http://www.w3.org/TR/html4/strict.dtd&#8221;&gt;
</td>
<td> 不允许使用废弃的与展示相关的元素与属性 </td>
</tr>
<tr>
<td>HTML 4.01 过渡型 </td>
<td>&lt;!DOCTYPE HTML PUBLIC &#8220;-//W3C//DTD HTML 4.01 Transitional//EN&#8221;<br />
&#8220;http://www.w3.org/TR/html4/loose.dtd&#8221;&gt; </td>
<td> 可以使用所有元素和属性 </td>
</tr>
<tr>
<td>HTML 4.01 框架型 </td>
<td>&lt;!DOCTYPE HTML PUBLIC &#8220;-//W3C//DTD HTML 4.01 Frameset//EN&#8221;<br />
&#8220;http://www.w3.org/TR/html4/frameset.dtd&#8221;&gt;</td>
<td> 可以使用与框架相关的元素和属性 </td>
</tr>
</table>
<p> 对于富含语义的 HTML 文档来说，通常来说是不应该使用与展示相关的元素与属性的。因此，HTML 4.01 严格型的文档类型声明是最适合的。不过有些文档结构语义，只使用 HTML 4.01 严格型中规定的元素和属性的话，是无法实现的。（关于这一点的具体说明，见 <a rel="external nofollow" href="#darkarea"> 绕开“灰色地带”</a>）。综合来说，比较好的折衷方案是使用 HTML 4.01 过渡型的文档类型声明，但是在文档中避免使用废弃的元素和属性。如果可以确定 HTML 4.01 严格型中规定的元素和属性已经足够的话，使用该类型的文档类型声明是最好不过的选择。</p>
<p> 需要说明的是，目前的浏览器都有很强的容错性和向后兼容性。因此，即便没有正确的声明文档类型，浏览器也能正确的显示。但这并不意味着可以放弃使用正确的文档类型声明。</p>
<p><a name="N102DC"><span class="smalltitle"> 验证你的 HTML</span></a></p>
<p> 在选择好了文档类型声明之后，另外一个必须要做的步骤是使用 HTML 语法验证器来验证 HTML 文档。W3C 提供了一个 HTML 文档验证器。（见 <a rel="external nofollow" href="#resources"> 参考资料 </a>）。该验证器可以根据 URL 来验证，也可以验证用户上传的 HTML 文件或是直接输入的 HTML 代码。该验证器会根据文档的类型声明进行校验，并给出详细的信息。可以根据验证的结果进一步的修改 HTML 文档。<a rel="external nofollow" href="#fig-w3c-validator"> 图 2</a> 中给出了对一段不符合 HTML 4.01 严格型语法的 HTML 文档进行验证的结果。</p>
<p><a name="fig-w3c-validator"><b> 图 2. 使用 W3C HTML 语法验证器的结果 </b></a><br />
	 <img alt=" 使用 W3C HTML 语法验证器的结果 " height="557" src="http://kiya.cn/wp-content/uploads/2009/07/w3c-validator.jpg" width="572"/></p>
<p><a rel="external nofollow" href="#fig-w3c-validator"> 图 2</a> 中的 HTML 文档在 &lt;ol&gt; 元素中使用了属性 <code>start</code>，因此不符合 HTML 4.01 严格型规范。如果改成 HTML 4.01 过渡型的文档类型声明就是合法的。</p>
<p><a name="N10303"><span class="smalltitle"> 使用合适的元素 </span></a></p>
<p>HTML 4.01 规范中提供了不少语义丰富的元素，应该把这些元素应用在适合其语义的地方。大多数 Web 开发人员对于常用的 HTML 元素比较熟悉，使用也较多。对于一些不太常见的元素则很少使用，而用其它元素来代替。比如 &lt;div&gt; 和 &lt;span&gt; 就在很多情况下被用来代替其它元素。虽然将 &lt;div&gt; 和 &lt;span&gt; 和 CSS 相结合，都可以达到预期的显示效果，但是这样会削弱文档本身的语义。<a rel="external nofollow" href="#code1"> 代码清单 1</a> 和 <a rel="external nofollow" href="#code2"> 清单 2</a> 中给出两种 HTML 文档的写法。<a rel="external nofollow" href="#code1"> 代码清单 1</a> 中使用 &lt;span&gt; 元素，并通过 <code>class</code> 属性为 <code>header</code> 来表明该 &lt;span&gt; 元素的语义是“标题”。这种情况下，采用 <a rel="external nofollow" href="#code2"> 代码清单 2</a> 中给出的做法，使用 HTML 规范提供的 &lt;h3&gt; 元素会更合适。因为 &lt;h3&gt; 本身就已经包含了“标题”的语义，就不需要再通过 <code>class</code> 属性来说明了。</p>
<p><a name="code1"><b> 清单 1. 错误的 HTML 元素选择 </b></a></p>
<table width="100%" cellpadding="0" cellspacing="0" border="1">
<tr>
<td class="code-outline">
<pre class="displaycode">
&lt;style&gt;
 .header {
 font-size : 1.2em;
 }
&lt;/style&gt;	

&lt;div class="container"/&gt;
 &lt;span class="header"&gt; 标题 &lt;/span&gt;
 &lt;div class="content"&gt; 内容 &lt;/div&gt;
&lt;/div&gt;
	</pre>
</td>
</tr>
</table>
<p><a name="code2"><b> 清单 2. 正确的 HTML 元素选择 </b></a></p>
<table width="100%" cellpadding="0" cellspacing="0" border="1">
<tr>
<td class="code-outline">
<pre class="displaycode">
&lt;div class="container"/&gt;
 &lt;h3&gt; 标题 &lt;/h3&gt;
 &lt;div class="content"&gt; 内容 &lt;/div&gt;
&lt;/div&gt;
	</pre>
</td>
</tr>
</table>
<p></p>
<p><a name="N10339"><span class="smalltitle"> 避免错误的元素使用 </span></a></p>
<p> 对于 HTML 中的元素，浏览器会有默认的展示样式。比如 &lt;blockquote&gt; 元素，通常来说浏览器会以缩进的方式来显示其中被引用的文本；而 &lt;em&gt; 元素，浏览器则会把其中的文本显示为斜体。这种默认的展示样式会造成一种错误的元素使用方式，即为了达到某种展示效果而使用该元素，而忽略元素本身的语义。比如希望将一段文本以缩进的方式显示，就使用 &lt;blockquote&gt; 元素，即使该段文本并非是引用自外部文档的。</p>
<p> 这种方式的问题在于过分依赖于浏览器的默认样式而忽视元素的语义。一旦浏览器的默认样式发生变化或是被其它 CSS 样式所修改，原本预期的展示效果就无法实现。</p>
<p><a name="N10344"><span class="smalltitle"> 使用富含语义的 class 属性 </span></a></p>
<p>HTML 元素的 <code>class</code> 属性为使用 CSS 来修改元素的样式提供了切入点。一个好的 class 属性可以为已有的 HTML 元素增加语义。比如 <code>&lt;h1 class="important"&gt;</code> 中，&lt;h1&gt; 本身的语义是表示标题，而通过使用 <code>important</code> 这样一个 class 属性的值，进一步说明该标题是比较重要的。可以通过 CSS 为该标题添加加粗、不同的颜色等样式来突出该语义。对于类似 &lt;div&gt; 和 &lt;span&gt; 这样并没有附加语义，而只是单纯作为容器使用的 HTML 元素来说，好的 class 属性可以为其添加语义。比如 <code>&lt;div class="summary"&gt;</code>，通过 <code>class</code> 属性就为该 &lt;div&gt; 添加语义，说明其表示的是一段摘要。</p>
<p> 一个好的 <code>class</code> 属性值应该要说明其对应的 HTML 元素的作用，而不应该说明该元素的展现样式。由于 <code>class</code> 属性会在 CSS 中作为选择器来使用，因此很容易就误用一些表示展现样式的名称。比如 <code>redTextBlueBorder</code> 这样的名称，虽然清晰的描述了其展现样式是红色文字加上蓝色边框，但是并没有描述元素的作用，是不好的名称。如果需要对样式进行修改，比如改成蓝色文字加上红色边框，那么名称也需要相应的修改，变成 <code>blueTextRedBorder</code>。一个好的名称，在所描述的元素的作用没有变化时，即便展现的样式发生改变，就不需要修改。</p>
<p><a name="darkarea"><span class="smalltitle"> 绕开“灰色地带”</span></a></p>
<p> 尽管推荐使用表示文档结构和富含语义的 HTML 元素和属性来编写 HTML 文档，但是在有些情况下，不得不使用与展示相关的元素和属性来完成特定的功能。这是实践富含语义的 HTML 中的“灰色地带”。下面列举几个常见的情况：</p>
<ul>
<li> 有序列表元素 &lt;ol&gt; 的属性 <code>start</code> 和 &lt;li&gt; 元素的 <code>value</code> 属性在 HTML 4.01 严格型文档类型声明中是被废弃的。但是这两个属性是用来控制有序列表的数字编号顺序的惟一方式。</li>
<li>&lt;iframe&gt; 元素在 4.01 严格型文档类型声明中是不被允许的。</li>
<li>&lt;b&gt; 和 &lt;i&gt; 元素虽然是与展示相关，但是在 HTML 4.01 严格型文档类型声明中仍然是合法的。</li>
<li> 在很多时候，&lt;table&gt; 元素被用来作为布局的手段。然而从语义上来说，&lt;table&gt; 更适合用来显示表格型的数据。推荐的方式是使用 &lt;div&gt; 元素来进行页面布局。CSS 3 中引入了复杂的网格布局。</li>
</ul>
<p> 正是由于上面所述这些“灰色地带”的存在，通常来说，目前最适用的是 HTML 4.01 过渡型文档类型声明。</p>
<p> 之前关于富含语义的 HTML 的介绍，都是从基本元素和属性的角度出发，下面将介绍富含语义的 HTML 组件：微格式。</p>
<p>
<p><a name="N10398"><span class="atitle"> 微格式（Microformat）</span></a></p>
<p> 微格式（Microformat）是满足特定模式的有组织的 HTML 片断，用来描述网页中富含语义的实体。在编写 HTML 文档时，经常会需要包含某些富含语义的实体，包括人、事件、评论、地理位置和个人简历等。比如在个人博客中经常会包括作者本人的基本信息。微格式定义了描述这些实体的 HTML 应该具有的格式。通过使用微格式，这些实体的语义得以在 HTML 中保留。微格式是富含语义的 HTML 这一指导原则的良好实践。它将对语义的保留提升到了 HTML 片断的层次。微格式使用富含语义的 HTML 元素和 <code>class</code> 属性。下面通过一个实例来说明微格式的用法。</p>
<p>hCard 是一种用来描述人、公司、组织机构和地点的微格式。<a rel="external nofollow" href="#code3"> 代码清单 3</a> 中给出了一个实例。</p>
<p><a name="code3"><b> 清单 3. hCard 微格式实例 </b></a></p>
<table width="100%" cellpadding="0" cellspacing="0" border="1">
<tr>
<td class="code-outline">
<pre class="displaycode">
&lt;div class="vcard"&gt;
 &lt;span class="fn"&gt;成富&lt;/span&gt;
 &lt;div class="adr"&gt;
 &lt;span class="type"&gt;工作&lt;/span&gt;:
 &lt;div class="street-address"&gt;东北旺西路8号&lt;/div&gt;
 &lt;span class="locality"&gt;海淀区&lt;/span&gt;,
 &lt;span class="region"&gt;北京市&lt;/span&gt;,
 &lt;span class="postal-code"&gt;100193&lt;/span&gt;
 &lt;div class="country-name"&gt;中国&lt;/div&gt;
 &lt;/div&gt;
 &lt;div class="tel"&gt;
 &lt;span class="type"&gt;工作&lt;/span&gt;8245xxxx
 &lt;/div&gt;
 &lt;div class="tel"&gt;
 &lt;span class="type"&gt;家庭&lt;/span&gt;138xxxxxxx
 &lt;/div&gt;
 &lt;div&gt;电子邮件:
 &lt;span class="email"&gt;chengfbj@cn.ibm.com&lt;/span&gt;
 &lt;/div&gt;
&lt;/div&gt;
	</pre>
</td>
</tr>
</table>
<p></p>
<p> 在 <a rel="external nofollow" href="#code3"> 代码清单 3</a> 中，微格式 hCard 使用了 &lt;div&gt; 和 &lt;span&gt; 这两个通用 HTML 元素，加上富含语义的 street-address、postal-code、country-name、tel 和 email 等 <code>class</code> 属性。<a rel="external nofollow" href="#code3"> 代码清单 3</a> 中的 HTML 片断清晰的表达了“人”这样一个实体的语义。Web 开发人员可以使用不同的样式来显示这样一个实体。</p>
<p> 在编写 HTML 文档时，如果需要描述的实体已经有相关的微格式的规范，应该按照相应的规范来使用合适的 HTML 元素和 <code>class</code> 属性。更多微格式的信息见 <a rel="external nofollow" href="#resources"> 参考资料 </a>。</p>
<p> 至此，关于富含语义的 HTML 的主要内容就已经介绍完毕，下面介绍一些相关的其它话题。</p>
<p>
<p><a name="N103D2"><span class="atitle"> 其它话题 </span></a></p>
<p> 下面介绍与富含语义的 HTML 相关的其它话题，主要与可访问性（Accessibility）相关。</p>
<p><a name="N103DA"><span class="smalltitle"> 可访问性 </span></a></p>
<p> 可访问性指的是网页内容应该可以被残障人士所访问。对于失明的用户来说，他需要使用屏幕阅读器这样的设备来读取网页的内容。富含语义的 HTML 文档可以有效的为屏幕阅读器提供语义信息，从而帮助它更好的将文档的含义传达给用户。由于文档的展示对用户是不可见的，因此文档的语义就显得尤为重要。</p>
<p> 比如，在文档中经常需要对一段文字进行着重强调。如果使用与展示相关的元素，可以写成 <code>&lt;b&gt;Text&lt;/b&gt;</code>。通常来说，浏览器会用粗体来显示这段文本，从而传达给用户强调的语义。但是对于屏幕阅读器来说，它并不能很好的理解 &lt;b&gt; 所要传达的语义，可能是表示强调，也可能只是用粗体显示的普通文本。但是使用 <code>&lt;strong&gt;Text&lt;/strong&gt;</code> 的话就不一样了，因为 &lt;strong&gt; 元素本身就包含了强调的语义，屏幕阅读器可以采用合适的方式来传达出来，比如加重朗读时的语调等。</p>
<p> 富含语义的 HTML 文档也能更好的被搜索引擎所理解。</p>
<p>
<p><a name="N103F0"><span class="atitle"> 总结 </span></a></p>
<p> 本文详细介绍了目前 Ajax 应用开发中的一个最佳实践“富含语义的 HTML”，即 HTML 文档应该只表示 Web 应用的结构，而不是展示。在编写 HTML 文档的时候，应该尽量使用 HTML 规范中表示文档结构和富含语义的元素和属性。本文中介绍了 HTML 规范的历史以及规范中哪些元素和属性是推荐使用的。与此同时，还给出了一系列编写 HTML 文档时的最佳实践。最后，介绍了微格式以及可访问性相关的内容。</p>
<p>
<p><a name="N103F9"><span class="atitle"> 声明 </span></a></p>
<p>
本人所发表的内容仅为个人观点，不代表 IBM 公司立场、战略和观点。
</p>
<p><a name="resources"><span class="atitle">参考资料 </span></a></p>
<p><b>学习</b>
<ul>
<li>
 <a rel="external nofollow" href="http://www.w3.org/History/19921103-hypertext/hypertext/WWW/MarkUp/Tags.html">HTML 最初的草案 </a></p>
</li>
<li>
 <a rel="external nofollow" href="http://www.ietf.org/rfc/rfc1866.txt">HTML 2.0 规范 </a></p>
</li>
<li>
 <a rel="external nofollow" href="http://www.w3.org/TR/REC-html32">HTML 3.2 规范 </a></p>
</li>
<li>
 <a rel="external nofollow" href="http://www.w3.org/TR/html401/">HTML 4.01 规范 </a></p>
</li>
<li>
 <a rel="external nofollow" href="http://www.w3.org/TR/html5/">HTML 5 规范 </a></p>
</li>
<li> 在 <a rel="external nofollow" href="http://microformats.org"> 微格式网站 </a> 中查看已有的微格式规范
</li>
<li>
 <a rel="external nofollow" href="http://www.ibm.com/developerworks/cn/web/">developerWorks Web development<br />
 专区 </a>：通过专门关于 Web 技术的文章和教程，扩展您在网站开发方面的技能。</p>
</li>
<li>developerWorks <a rel="external nofollow" href="http://www.ibm.com/developerworks/cn/offers/techbriefings/"> 技术活动 </a> 和 <a rel="external nofollow" href="http://www.ibm.com/developerworks/cn/swi/"> 网络广播 </a>：随时关注 developerWorks 技术活动和网络广播。
</li>
</ul>
<p><b>获得产品和技术</b>
<ul>
<li> 使用 <a rel="external nofollow" href="http://validator.w3.org/">W3C HTML 语法验证器 </a></p>
</li>
</ul>
<p><b>讨论</b>
<ul>
<li> 查看“<a rel="external nofollow" href="http://groups.google.com/group/comp.infosystems.www.authoring.html/topics"> 编写 HTML 文档 </a>”讨论组中的最新内容 </p>
</li>
</ul>
<p><a name="author"><span class="atitle">关于作者</span></a></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td colspan="3"></td>
</tr>
<tr align="left" valign="top">
<td>
<p /></td>
<td></td>
<td width="100%">
<p>成富任职于 IBM 中国软件开发中心，目前在 Lotus 部门从事 IBM Mashup Center 的开发工作。他毕业于北京大学信息科学技术学院，获得计算机软件与理论专业硕士学位。</p>
</td>
</tr>
</table>
<h2  class="related_post_title">Related Posts / 相关文章</h2><ul class="related_post"><li><a href="http://slj.me/2009/07/semantic-html/" title="语义化的HTML结构到底有何好处? ">语义化的HTML结构到底有何好处? </a></li><li><a href="http://slj.me/2010/05/html5-new-features/" title="HTML5新功能演示">HTML5新功能演示</a></li><li><a href="http://slj.me/2010/03/%e4%b8%8b%e8%bd%bd-dojo-%e4%b8%ad%e6%96%87%e6%89%8b%e5%86%8c%e3%80%8a%e5%ae%9e%e6%88%98dojo%e5%b7%a5%e5%85%b7%e5%8c%85%e3%80%8bpdf/" title="[下载] Dojo 中文手册《实战Dojo工具包》PDF">[下载] Dojo 中文手册《实战Dojo工具包》PDF</a></li><li><a href="http://slj.me/2010/03/zen-coding%e8%b5%84%e6%ba%90%e6%9b%b4%e6%96%b0/" title="Zen Coding资源更新">Zen Coding资源更新</a></li><li><a href="http://slj.me/2010/03/building-iphone-apps-with-html-css-and-javascript/" title="【好书PDF】：Building iPhone Apps with HTML, CSS, and JavaScript">【好书PDF】：Building iPhone Apps with HTML, CSS, and JavaScript</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2009/07/dojo-ajax-semanticize-html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript 实现图像倒影、发光效果</title>
		<link>http://slj.me/2009/07/javascript-pic-reflection-glossy-effect/</link>
		<comments>http://slj.me/2009/07/javascript-pic-reflection-glossy-effect/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 03:30:10 +0000</pubDate>
		<dc:creator>SLJ</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[glossy]]></category>
		<category><![CDATA[pic]]></category>
		<category><![CDATA[reflection]]></category>
		<category><![CDATA[倒影]]></category>
		<category><![CDATA[发光]]></category>
		<category><![CDATA[图像]]></category>
		<category><![CDATA[效果]]></category>

		<guid isPermaLink="false">http://kiya.cn/?p=623</guid>
		<description><![CDATA[图像倒影效果 下载地址：http://www.netzgesta.de/reflex/reflex.zip 图片发光效果 下载地址：http://www.netzgesta.de/glossy/glossy.zip Related Posts / 相关文章JavaScript 操作select控件大全（新增、修改、删除、选中、清空、判断存在等）[英,转]45个新鲜有用的JS与jQuery技术和工具【好书PDF】：Building iPhone Apps with HTML, CSS, and JavaScriptJS获取浏览器窗口大小 获取屏幕，浏览器，网页高度宽度 JavaScript MD5 加密]]></description>
			<content:encoded><![CDATA[<p><img src="http://kiya.cn/wp-content/uploads/2009/07/reflection.gif" alt="reflection" title="reflection" width="500" height="321" /></p>
<p>图像倒影效果<br />
<span id="more-623"></span>下载地址：<a href="http://www.netzgesta.de/reflex/reflex.zip" rel="external nofollow">http://www.netzgesta.de/reflex/reflex.zip</a></p>
<p><img title="reflection" src="http://kiya.cn/wp-content/uploads/2009/07/glossy.gif" alt="glossy" /></p>
<p>图片发光效果<br />
下载地址：<a href="http://www.netzgesta.de/glossy/glossy.zip" rel="external nofollow">http://www.netzgesta.de/glossy/glossy.zip</a></p>
<h2  class="related_post_title">Related Posts / 相关文章</h2><ul class="related_post"><li><a href="http://slj.me/2010/12/javascript-select-operations/" title="JavaScript 操作select控件大全（新增、修改、删除、选中、清空、判断存在等）">JavaScript 操作select控件大全（新增、修改、删除、选中、清空、判断存在等）</a></li><li><a href="http://slj.me/2010/03/45-fresh-useful-javascript-and-jquery-techniques-and-tools/" title="[英,转]45个新鲜有用的JS与jQuery技术和工具">[英,转]45个新鲜有用的JS与jQuery技术和工具</a></li><li><a href="http://slj.me/2010/03/building-iphone-apps-with-html-css-and-javascript/" title="【好书PDF】：Building iPhone Apps with HTML, CSS, and JavaScript">【好书PDF】：Building iPhone Apps with HTML, CSS, and JavaScript</a></li><li><a href="http://slj.me/2010/01/js%e8%8e%b7%e5%8f%96%e6%b5%8f%e8%a7%88%e5%99%a8%e7%aa%97%e5%8f%a3%e5%a4%a7%e5%b0%8f-%e8%8e%b7%e5%8f%96%e5%b1%8f%e5%b9%95%ef%bc%8c%e6%b5%8f%e8%a7%88%e5%99%a8%ef%bc%8c%e7%bd%91%e9%a1%b5%e9%ab%98/" title="JS获取浏览器窗口大小 获取屏幕，浏览器，网页高度宽度 ">JS获取浏览器窗口大小 获取屏幕，浏览器，网页高度宽度 </a></li><li><a href="http://slj.me/2009/04/javascript-md5-encrypt/" title="JavaScript MD5 加密">JavaScript MD5 加密</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2009/07/javascript-pic-reflection-glossy-effect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript 图片切割效果</title>
		<link>http://slj.me/2009/07/javascript-%e5%9b%be%e7%89%87%e5%88%87%e5%89%b2%e6%95%88%e6%9e%9c/</link>
		<comments>http://slj.me/2009/07/javascript-%e5%9b%be%e7%89%87%e5%88%87%e5%89%b2%e6%95%88%e6%9e%9c/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 14:39:55 +0000</pubDate>
		<dc:creator>龙</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://kiya.cn/?p=616</guid>
		<description><![CDATA[现在社区网越来越多,注册可以上传照片,并进行切割,形成较小的图片(头像),这样对自动的后台是有好处的. 我就开始到网上到处去搜索,下面是自己找到的两个JS代码.前个是用原javacript写的,后个是用框架jquery的一个插件写的.感觉都不错.(其实这些JS都不是真正的能对图片进行切割,他们只是提供一个从那点开始切割,要切割的长各宽.把这些参数传到后台由后台语言去操作.)也不多说了,下面就给出这两下例子吧. 这个是cloudgamer博客的,这个解释的很清楚 http://www.cnblogs.com/cloudgamer/archive/2008/07/21/ImgCropper.html 下面的一个是用jquery框架的一个插件.这个是英语的,不过还好啦,看jquery代码应该还是没有问题的 http://odyniec.net/projects/imgareaselect/ Other Posts / 其他文章关于一些浏览器的的HackCSS Sprites 技巧 23个iPhone App Store中的开源App及其源码免费的Photoshop高分辨率笔刷40个迹象表明你还是PHP菜鸟]]></description>
			<content:encoded><![CDATA[<p>现在社区网越来越多,注册可以上传照片,并进行切割,形成较小的图片(头像),这样对自动的后台是有好处的.</p>
<p>我就开始到网上到处去搜索,下面是自己找到的两个JS代码.前个是用原javacript写的,后个是用框架jquery的一个插件写的.感觉都不错.(其实这些JS都不是真正的能对图片进行切割,他们只是提供一个从那点开始切割,要切割的长各宽.把这些参数传到后台由后台语言去操作.)也不多说了,下面就给出这两下例子吧.</p>
<p>这个是cloudgamer博客的,这个解释的很清楚</p>
<p><a rel="external nofollow" href="http://www.cnblogs.com/cloudgamer/archive/2008/07/21/ImgCropper.html">http://www.cnblogs.com/cloudgamer/archive/2008/07/21/ImgCropper.html</a></p>
<p>下面的一个是用jquery框架的一个插件.这个是英语的,不过还好啦,看jquery代码应该还是没有问题的</p>
<p><a rel="external nofollow" href="http://odyniec.net/projects/imgareaselect/">http://odyniec.net/projects/imgareaselect/</a></p>
<h2  class="related_post_title">Other Posts / 其他文章</h2><ul class="related_post"><li><a href="http://slj.me/2009/07/iphone-webpage-design/" title="关于 iPhone 网页开发">关于 iPhone 网页开发</a></li><li><a href="http://slj.me/2009/07/%e8%bd%ac%e5%a6%82%e4%bd%95%e5%81%9a%e5%a5%bd%e4%b8%80%e4%bb%bd%e5%89%8d%e7%ab%af%e5%b7%a5%e7%a8%8b%e5%b8%88%e7%9a%84%e7%ae%80%e5%8e%86%ef%bc%9f/" title="[转]如何做好一份前端工程师的简历？">[转]如何做好一份前端工程师的简历？</a></li><li><a href="http://slj.me/2009/04/base64-javascript-encode-decode-2/" title="Base64 javascript encode decode 另一种不错的方法">Base64 javascript encode decode 另一种不错的方法</a></li><li><a href="http://slj.me/2011/03/21andy-centos-repo/" title="分享21Andy的CentOS的repo">分享21Andy的CentOS的repo</a></li><li><a href="http://slj.me/2009/12/css-shadow/" title="CSS阴影详解">CSS阴影详解</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://slj.me/2009/07/javascript-%e5%9b%be%e7%89%87%e5%88%87%e5%89%b2%e6%95%88%e6%9e%9c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

