﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-J度空间-文章分类-网页设计</title><link>http://www.blogjava.net/jdo/category/24814.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 30 Aug 2007 20:43:14 GMT</lastBuildDate><pubDate>Thu, 30 Aug 2007 20:43:14 GMT</pubDate><ttl>60</ttl><item><title>DOMtab的基本使用方法以及下载地址和完整演示</title><link>http://www.blogjava.net/jdo/articles/140690.html</link><dc:creator>蓝色幽默</dc:creator><author>蓝色幽默</author><pubDate>Tue, 28 Aug 2007 14:45:00 GMT</pubDate><guid>http://www.blogjava.net/jdo/articles/140690.html</guid><wfw:comment>http://www.blogjava.net/jdo/comments/140690.html</wfw:comment><comments>http://www.blogjava.net/jdo/articles/140690.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jdo/comments/commentRss/140690.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jdo/services/trackbacks/140690.html</trackback:ping><description><![CDATA[
		<div class="entry">
				<p>
						<strong>一.什么是DOMtab</strong>
						<br />
DOMtab是一个用javascipt制作的通用可扩展的tab切换显示隐藏内容快的web控件。</p>
				<p>
						<strong>二.怎么使用DOMtab</strong>
						<br />
1.在页面的
</p>
				<div class="hl-surround">
						<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
								<li class="hl-firstline">&lt;head&gt;&lt;/head&gt;</li>
						</ol>
				</div>
				<p>区域加上</p>
				<div class="hl-surround">
						<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
								<li class="hl-firstline">&lt;script type="text/javascript" src="domtab.js"&gt;&lt;/script&gt;</li>
						</ol>
				</div>
				<p>2.在页面主体的
</p>
				<div class="hl-surround">
						<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
								<li class="hl-firstline">&lt;body&gt;&lt;/body&gt;</li>
						</ol>
				</div>
				<p>部分加上</p>
				<div class="hl-surround">
						<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
								<li class="hl-firstline">&lt;div class="domtab"&gt;</li>
								<li> &lt;ul class="domtabs"&gt;</li>
								<li> &lt;li&gt;&lt;a href="#t1"&gt;Test 1&lt;/a&gt;&lt;/li&gt;</li>
								<li> &lt;li&gt;&lt;a href="#t2"&gt;Test 2&lt;/a&gt;&lt;/li&gt; [idea] [idea] </li>
								<li>[... and so on ...]</li>
								<li> &lt;/ul&gt;</li>
								<li> &lt;div&gt;</li>
								<li> &lt;h2&gt;&lt;a name="t1" id="t1"&gt;Proof 1&lt;/a&gt;&lt;/h2&gt;</li>
								<li> &lt;p&gt;Test to prove that more than one menu is possible&lt;/p&gt;</li>
								<li> &lt;p&gt;&lt;a href="#top"&gt;back to menu&lt;/a&gt;&lt;/p&gt;</li>
								<li> &lt;/div&gt;</li>
								<li> &lt;div&gt;</li>
								<li> &lt;h2&gt;&lt;a name="t2" id="t2"&gt;Proof 2&lt;/a&gt;&lt;/h2&gt;</li>
								<li> &lt;p&gt;Test to prove that more than one menu is possible&lt;/p&gt;</li>
								<li> &lt;p&gt;&lt;a href="#top"&gt;back to menu&lt;/a&gt;&lt;/p&gt;</li>
								<li> &lt;/div&gt;</li>
								<li>[... and so on ...]</li>
								<li>&lt;/div&gt;</li>
						</ol>
				</div>
				<p>
						<br />
然后定义各个class的样式就可以了，你也可以加class定义样式，但是代码的结构不能变化<br />
3.更改javascript中控件的属性<br />
tabClass:’domtab’, //目标区域的class名称<br />
listClass:’domtabs’, // 列表菜单的class名称<br />
activeClass:’active’, // 菜单激活状态下的class名称<br />
contentElements:’div’, // 循环内容区域的元素名称<br />
backToLinks:/#top/, // 设置返回顶部的参数<br />
printID:’domtabprintview’, // 显示所有区域内容的id名称<br />
showAllLinkText:’show all content’, // 显示所有区域的文字名称</p>
				<p>
						<strong>三.增加向前向后按钮</strong>
				</p>
				<p>1.在区域的起始class上多增加一个doprevnext</p>
				<div class="hl-surround">
						<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
								<li class="hl-firstline">&lt;div class="domtab doprevnext"&gt;</li>
								<li> &lt;ul class="domtabs"&gt;</li>
								<li> &lt;li&gt;&lt;a href="#t1"&gt;Test 1&lt;/a&gt;&lt;/li&gt;</li>
								<li> &lt;li&gt;&lt;a href="#t2"&gt;Test 2&lt;/a&gt;&lt;/li&gt;</li>
								<li> &lt;li&gt;&lt;a href="#t3"&gt;Test 3&lt;/a&gt;&lt;/li&gt;</li>
								<li> &lt;li&gt;&lt;a href="#t4"&gt;Test 4&lt;/a&gt;&lt;/li&gt;</li>
								<li> &lt;/ul&gt;</li>
								<li> [... ad nauseam...]</li>
								<li>&lt;/div&gt;</li>
						</ol>
				</div>
				<p>2.在页面里面加上下列代码</p>
				<div class="hl-surround">
						<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
								<li class="hl-firstline">&lt;ul class="prevnext"&gt;</li>
								<li> &lt;li class="prev"&gt;&lt;a href="#"&gt;previous&lt;/a&gt;&lt;/li&gt;</li>
								<li> &lt;li class="next"&gt;&lt;a href="#"&gt;next&lt;/a&gt;&lt;/li&gt;</li>
								<li> &lt;/ul&gt;</li>
						</ol>
				</div>
				<p>3.javascript里面的属性定义</p>
				<div class="hl-surround">
						<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
								<li class="hl-firstline">prevNextIndicator:'doprevnext', // 目标容器的class名称</li>
								<li>prevNextClass:'prevnext', // class名称</li>
								<li>prevLabel:'previous', // 上一页的文字</li>
								<li>nextLabel:'next', // 下一页的文字</li>
								<li>prevClass:'prev', // 上一页的class</li>
								<li>nextClass:'next', // 下一页的class</li>
						</ol>
				</div>
				<p>
						<strong>四.DOMtab中的样式控制</strong>
						<br />
你可以强制的控制某一个元素的样式譬如显示和隐藏等等</p>
				<div class="hl-surround">
						<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
								<li class="hl-firstline">&lt;script type="text/javascript"&gt;</li>
								<li> document.write('&lt;style type="text/css"&gt;'); </li>
								<li> document.write('div.domtab div{display:none;}&lt;');</li>
								<li> document.write('/s'+'tyle&gt;'); </li>
								<li>&lt;/script&gt;</li>
						</ol>
				</div>
				<p>
						<strong>五.下载以及演示</strong>
						<br />
						<a href="http://onlinetools.org/tools/domtabdata/domtab.zip" title="http://onlinetools.org/tools/domtabdata/domtab.zip" target="_blank">下载DOMtab version 3.1415927</a>
						<br />
						<a href="http://onlinetools.org/tools/domtabdata/" title="http://onlinetools.org/tools/domtabdata/" target="_blank">DOMtab演示</a>
				</p>
		</div>
<img src ="http://www.blogjava.net/jdo/aggbug/140690.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jdo/" target="_blank">蓝色幽默</a> 2007-08-28 22:45 <a href="http://www.blogjava.net/jdo/articles/140690.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用DIV+Javascript实现标签功能</title><link>http://www.blogjava.net/jdo/articles/140411.html</link><dc:creator>蓝色幽默</dc:creator><author>蓝色幽默</author><pubDate>Tue, 28 Aug 2007 04:47:00 GMT</pubDate><guid>http://www.blogjava.net/jdo/articles/140411.html</guid><wfw:comment>http://www.blogjava.net/jdo/comments/140411.html</wfw:comment><comments>http://www.blogjava.net/jdo/articles/140411.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jdo/comments/commentRss/140411.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jdo/services/trackbacks/140411.html</trackback:ping><description><![CDATA[
		<div>
				<div class="code_title">　　现在很多网站都用到了标签的切换功能，新浪、迅雷等网站都有，应该说用很很泛滥了。其实
标签功能是Windows程序中的一种功能，在Delphi或VB等Windows程序开的环境中，很容易就能创建各种漂亮而又功能强大的标签功能，但在
Web开发中，就没有这种便利了。</div>
		</div>
		<div>　　只需要销加改动，标签的数量可以自由添加，而无需要为标签添加ID，实际上这个功能除了用到Div、Javascript之后，很重要的是要用到CSS样式。</div>
		<div> </div>
		<div align="center">
				<img alt="" src="http://www.conis.cn/UPLOAD/Lesson/Web/Lesson1/001.gif" />
		</div>
		<div align="center"> </div>
		<div align="center">图1</div>
		<div align="left">
				<br />　
　首先我们要确定我们要做什么，我们要做成一个带三个标签的区域(图1)，点击标签标签列表的其中一个标签，内容区域会根据当前点击的标签显示不同的内
容。按照我们一般的做法是每一个标签对应一个内容区域，给每个内容区域增加一个id属性，然后为每一个标签添加一个属性，就像这样：</div>
		<div class="bar"> <div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: rgb(230, 230, 230) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;"><div><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="label1"</span><span style="color: rgb(255, 0, 0);"> onmousemove</span><span style="color: rgb(0, 0, 255);">="dosomething()"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">label1</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="label2"</span><span style="color: rgb(255, 0, 0);"> onmousemove</span><span style="color: rgb(0, 0, 255);">="dosomething()"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">label2</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="label2"</span><span style="color: rgb(255, 0, 0);"> onmousemove</span><span style="color: rgb(0, 0, 255);">="dosomething()"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">label2</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="content1"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">第一个label的内容</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="content2"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">第一个labe2的内容</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="content2"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">第一个labe2的内容</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">     <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">  </span></div></div></div>
		<div>    
你可能没有意识到这种办法会有什么问题，当一个页面有非常多的标签块的话，我们将不得不面临一个问题，那就是id的命名问题，我们将要为每一个内容区域命
名，这样不仅增加了代码量，也增加了javascript编写的难度，我们不可能为每一个标签块写一堆javascript，就算我将
javascript写成一个函数或者一个类，我们也会而临另一个问题，就是调用的时候会有一大堆的参数，因为你需要将这个id传送过去。并且，很容易因
为人为的疏忽造成错误。</div>
		<div>　　下面，来看看我是如何实现这个功能的吧，可能不是最好的方法，如果你有更好的方法，希望你能告诉我，让我们一起进步。</div>
		<div>    　首先，我们要做的是写好基本的html代码，代码如下：</div>
		<div>
				<div class="code_title">
						<div class="bar"> <div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: rgb(230, 230, 230) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;"><div><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">meta </span><span style="color: rgb(255, 0, 0);">http-equiv</span><span style="color: rgb(0, 0, 255);">="Content-Type"</span><span style="color: rgb(255, 0, 0);"> content</span><span style="color: rgb(0, 0, 255);">="text/html; charset=gb2312"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />     <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">ul </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="Label"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);">我们将第一个标签的背景色设置红色，因为默认显示的是第一个标签的内容</span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">li </span><span style="color: rgb(255, 0, 0);">class</span><span style="color: rgb(0, 0, 255);">="CurrentLabel"</span><span style="color: rgb(255, 0, 0);"> style</span><span style="color: rgb(0, 0, 255);">="background-color: red"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">标签1</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">li</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">li</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">标签2</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">li</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">li</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">标签3</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">li</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">ul</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="Container"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">这时里是标签1对应的内容</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />    </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);">因为默认是不显示的，所以要将display属性设置为none</span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">style</span><span style="color: rgb(0, 0, 255);">="display: none"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">这时里是标签2对应的内容</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">style</span><span style="color: rgb(0, 0, 255);">="display: none"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="Content3"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">这时里是标签3对应的内容</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span></div></div><span>   </span></div>
				</div>
		</div>
		<div>    写好基本html代码后，我们还需要做一项重要的工作，那就是css样式，因为li如果没有css样式控制，标签就会以列表的形式出现，基本的CSS样式代码如下：</div>
		<div>
				<div class="code_title"> </div>
				<div class="bar"> <div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: rgb(230, 230, 230) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;"><div><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(128, 0, 0);">&lt;style type="text/css"&gt;    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> #Label li    <br /><img id="_44_317_Open_Image" onclick="this.style.display='none'; document.getElementById('_44_317_Open_Text').style.display='none'; document.getElementById('_44_317_Closed_Image').style.display='inline'; document.getElementById('_44_317_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="_44_317_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('_44_317_Closed_Text').style.display='none'; document.getElementById('_44_317_Open_Image').style.display='inline'; document.getElementById('_44_317_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align="top" /> </span><span id="_44_317_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">{...}</span><span id="_44_317_Open_Text"><span style="color: rgb(0, 0, 0);">{</span><span style="color: rgb(255, 0, 0);">    <br /><img id="_52_153_Open_Image" onclick="this.style.display='none'; document.getElementById('_52_153_Open_Text').style.display='none'; document.getElementById('_52_153_Closed_Image').style.display='inline'; document.getElementById('_52_153_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="_52_153_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('_52_153_Closed_Text').style.display='none'; document.getElementById('_52_153_Open_Image').style.display='inline'; document.getElementById('_52_153_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span><span id="_52_153_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">/**/</span><span id="_52_153_Open_Text"><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);">设置ID为Label的元素下所有li元素样式，主要是要设置float:left这个属性，这样才能将li元素排成一排；同时设置了list-style:none这个属性，目的是防止li元素出现实心圆点</span><span style="color: rgb(0, 128, 0);">*/</span></span><span style="color: rgb(255, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  margin-left</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 255);"> 1px</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(255, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  padding</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 255);"> 3px</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(255, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  width</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 255);"> 40px</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(255, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  background-color</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 255);">#94A5F8</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(255, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  float</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 255);">left</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(255, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  list-style</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 255);">none</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(255, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  cursor</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 255);">pointer</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(255, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /> </span><span style="color: rgb(0, 0, 0);">}</span></span><span style="color: rgb(128, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />&lt;/style&gt;    </span></div></div><span>   </span></div>
		</div>
		<div>　
　下面，我们将要进行最重要的一环了，就是javascript，看到你里，你可能会问，为什么标签li元素没有事件呢？如何实现标签的切换呢，这是因为
我考虑了另一个问题，如果我们需要为每一个标签添加一个事件的话，确实是一件很麻烦的事情，而且当标签块多了的时候，就会增加代码量，所以我考虑使用动态
添加属性的方式为每一个标签添加属性。<div class="code_title"> <div class="bar"> <div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: rgb(230, 230, 230) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;"><div><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> LabelAddEvent()    <br /><img id="_30_630_Open_Image" onclick="this.style.display='none'; document.getElementById('_30_630_Open_Text').style.display='none'; document.getElementById('_30_630_Closed_Image').style.display='inline'; document.getElementById('_30_630_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="_30_630_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('_30_630_Closed_Text').style.display='none'; document.getElementById('_30_630_Open_Image').style.display='inline'; document.getElementById('_30_630_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align="top" /> </span><span id="_30_630_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">...</span><span id="_30_630_Open_Text"><span style="color: rgb(0, 0, 0);">{    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> labels </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> document.getElementById(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Label</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).childNodes;        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取ID为Label无素下的所有子节点，childNodes是DOM的一个属性    </span><span style="color: rgb(0, 128, 0);"><br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">对所有子节点进行循环，增加onmouseover事件，也可以根据需要添加onclick事件    </span><span style="color: rgb(0, 128, 0);"><br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> iLoop </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">; iLoop </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> labels.length; iLoop </span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">)    <br /><img id="_263_623_Open_Image" onclick="this.style.display='none'; document.getElementById('_263_623_Open_Text').style.display='none'; document.getElementById('_263_623_Closed_Image').style.display='inline'; document.getElementById('_263_623_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="_263_623_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('_263_623_Closed_Text').style.display='none'; document.getElementById('_263_623_Open_Image').style.display='inline'; document.getElementById('_263_623_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span><span id="_263_623_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">...</span><span id="_263_623_Open_Text"><span style="color: rgb(0, 0, 0);">{    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />   </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> label </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> labels[iLoop];    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />   </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">LI</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> label.nodeName)   </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">只处理LI的DOM节点，目的是为了兼容Firefox，因为Firefox会把空格与换行与当成一个节点处理    </span><span style="color: rgb(0, 128, 0);"><br /><img id="_398_615_Open_Image" onclick="this.style.display='none'; document.getElementById('_398_615_Open_Text').style.display='none'; document.getElementById('_398_615_Closed_Image').style.display='inline'; document.getElementById('_398_615_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="_398_615_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('_398_615_Closed_Text').style.display='none'; document.getElementById('_398_615_Open_Image').style.display='inline'; document.getElementById('_398_615_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">   </span><span id="_398_615_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">...</span><span id="_398_615_Open_Text"><span style="color: rgb(0, 0, 0);">{    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />    label.value </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> iLoop;        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">为每一个标签的value赋上当前的索引，当点击标签的时候不用循环标签就知道是哪一个标签了    </span><span style="color: rgb(0, 128, 0);"><br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">    label.onmouseover </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">()    <br /><img id="_530_605_Open_Image" onclick="this.style.display='none'; document.getElementById('_530_605_Open_Text').style.display='none'; document.getElementById('_530_605_Closed_Image').style.display='inline'; document.getElementById('_530_605_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="_530_605_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('_530_605_Closed_Text').style.display='none'; document.getElementById('_530_605_Open_Image').style.display='inline'; document.getElementById('_530_605_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="_530_605_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">...</span><span id="_530_605_Open_Text"><span style="color: rgb(0, 0, 0);">{    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />     ChangeLabel(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">);          </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">调用ChangeLabel函数，并把当前对象传过去    </span><span style="color: rgb(0, 128, 0);"><br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">    }</span></span><span style="color: rgb(0, 0, 0);">;    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />   }</span></span><span style="color: rgb(0, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />  }</span></span><span style="color: rgb(0, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /> }</span></span><span style="color: rgb(0, 0, 0);">    </span></div></div></div></div></div>
		<div>　　然后，我们在html页的最后面，调用LabelAddEvent这个函数，即可以为所有标签添加函数了，是不是很简洁，当我们有很多标签块的时候，就不必要为每个标签块添加事件了，下面我们来看看ChangeLabel这个函数：<br /> <div class="bar"> <div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: rgb(230, 230, 230) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;"><div><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> ChangeLabel(oCur)    <br /><img id="_32_638_Open_Image" onclick="this.style.display='none'; document.getElementById('_32_638_Open_Text').style.display='none'; document.getElementById('_32_638_Closed_Image').style.display='inline'; document.getElementById('_32_638_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="_32_638_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('_32_638_Closed_Text').style.display='none'; document.getElementById('_32_638_Open_Image').style.display='inline'; document.getElementById('_32_638_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align="top" /> </span><span id="_32_638_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">...</span><span id="_32_638_Open_Text"><span style="color: rgb(0, 0, 0);">{    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取所有的内容元素子节点    </span><span style="color: rgb(0, 128, 0);"><br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> containers </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> document.getElementById(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Container</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).childNodes;    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />　</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取所有的标签    </span><span style="color: rgb(0, 128, 0);"><br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> labels </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> document.getElementById(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Label</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).childNodes;    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> iLoop </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">; iLoop </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> containers.length; iLoop </span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">)    <br /><img id="_274_631_Open_Image" onclick="this.style.display='none'; document.getElementById('_274_631_Open_Text').style.display='none'; document.getElementById('_274_631_Closed_Image').style.display='inline'; document.getElementById('_274_631_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="_274_631_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('_274_631_Closed_Text').style.display='none'; document.getElementById('_274_631_Open_Image').style.display='inline'; document.getElementById('_274_631_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span><span id="_274_631_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">...</span><span id="_274_631_Open_Text"><span style="color: rgb(0, 0, 0);">{    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />   </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> container </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> containers[iLoop];       <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />   </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> label </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> labels[iLoop];    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />   </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">根据索引是否为li元素的value值来判断是否为当前标签    </span><span style="color: rgb(0, 128, 0);"><br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">   </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> current </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> iLoop </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> oCur.value;      <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />   </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">DIV</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> container.nodeName) container.style.display </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> current </span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">block</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> : </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">none</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />   </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">LI</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> label.nodeName) label.style.backgroundColor </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> current </span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">red</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> : </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">#94A5F8</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />  }</span></span><span style="color: rgb(0, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /> }</span></span><span style="color: rgb(0, 0, 0);">  <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span></div></div></div><p class="alt">　
　主要代码就是这么多了，是不是很简洁呢？当有很多个标签块的候，你就会发现这个方法的优势了，事实下，我们还可以简单修改一下javascript代
码，实现多个标签块在一个页面中的功能，接下来我准备结合Xml及Xslt写一个根据xml配置的多标签块的教程，如果你觉得有什么更好的方法可以实现，
请你与我联系，让我们共同进步。</p></div>
		<div>  <div style="border: 1px dotted rgb(102, 102, 102); padding: 10px; color: red; background-color: rgb(243, 243, 243);">  版权所有©Conis，复制或者转载请保留此信息，任何人未经许可，不得擅自将本文发布作为商业用途。<br />  更多内容更多精彩请您访问<a href="http://www.conis.cn/" target="_blank"><font color="#095c83">http://www.conis.cn</font></a></div></div>
<img src ="http://www.blogjava.net/jdo/aggbug/140411.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jdo/" target="_blank">蓝色幽默</a> 2007-08-28 12:47 <a href="http://www.blogjava.net/jdo/articles/140411.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>javascript操作Select标记中options集合</title><link>http://www.blogjava.net/jdo/articles/137341.html</link><dc:creator>蓝色幽默</dc:creator><author>蓝色幽默</author><pubDate>Thu, 16 Aug 2007 09:24:00 GMT</pubDate><guid>http://www.blogjava.net/jdo/articles/137341.html</guid><wfw:comment>http://www.blogjava.net/jdo/comments/137341.html</wfw:comment><comments>http://www.blogjava.net/jdo/articles/137341.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jdo/comments/commentRss/137341.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jdo/services/trackbacks/137341.html</trackback:ping><description><![CDATA[先来看看options集合的这几个方法：<br />options.add(option)方法向集合里添加一项option对象；<br />options.remove(index)方法移除options集合中的指定项；<br />options(index)或options.item(index)可以通过索引获取options集合的指定项；<br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">    var</span><span style="color: rgb(0, 0, 0);"> selectTag </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">; </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">select标记</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> OPTONLENGTH </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">10</span><span style="color: rgb(0, 0, 0);">; </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">每次填充option数</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> colls </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> [];       </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">对select标记options的引用</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);"><br />    window.onload </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(){<br />        selectTag </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> document.getElementById(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SelectBox</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">); </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取select标记        </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        colls </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> selectTag.options; </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取引用</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">initSelectBox();    //自初始化select.options</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    };<br />    <br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">使用随机数填充select.options</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> initSelectBox(){<br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> random </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> ;<br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> optionItem </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> item </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />        <br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(colls.length </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);"> isClearOption()){<br />             clearOptions(colls);<br />        }<br /><br />        </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> i</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;i</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">OPTONLENGTH;i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">){<br />             <br />            random </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> Math.floor(Math.random()</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">9000</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">1000</span><span style="color: rgb(0, 0, 0);">;<br />            item </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Option(random,random);    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">通过Option()构造函数创建option对象        </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            selectTag.options.add(item); </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">添加到options集合中</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        }    <br />        <br />        watchState();<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">添加新option项前是否清空当前options</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> isClearOption(){<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> document.getElementById(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">chkClear</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).checked;<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">清空options集合</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> clearOptions(colls){<br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> length </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> colls.length;<br />        </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> i</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">length</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;i</span><span style="color: rgb(0, 0, 0);">&gt;=</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;i</span><span style="color: rgb(0, 0, 0);">--</span><span style="color: rgb(0, 0, 0);">){<br />            colls.remove(i);<br />        }<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">添加一项新option</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> addOption(){<br />        colls.add(createOption());<br />        lastOptionOnFocus(colls.length</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);<br />        watchState();<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">创建一个option对象</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> createOption(){<br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> random </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> Math.floor(Math.random()</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">9000</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">1000</span><span style="color: rgb(0, 0, 0);">;<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Option(random,random);<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">删除options集合中指定的一项option</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> removeOption(index){        <br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(index </span><span style="color: rgb(0, 0, 0);">&gt;=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">){<br />            colls.remove(index);<br />            lastOptionOnFocus(colls.length</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);<br />        }<br />        watchState();<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取当前选定的option索引</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> getSelectedIndex(){<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> selectTag.selectedIndex;<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取options集合的总数</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> getOptionLength(){<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> colls.length;<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取当前选定的option文本</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> getCurrentOptionValue(index){<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(index </span><span style="color: rgb(0, 0, 0);">&gt;=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">)<br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> colls(index).value;<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取当前选定的option值</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> getCurrentOptionText(index){<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(index </span><span style="color: rgb(0, 0, 0);">&gt;=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">)<br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> colls(index).text;<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">使用options集合中最后一项获取焦点</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> lastOptionOnFocus(index){<br />        selectTag.selectedIndex </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> index;<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">显示当select标记状态</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> watchState(){<br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> divWatch </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> document.getElementById(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">divWatch</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> innerHtml</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">;<br />        innerHtml  </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">option总数:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> getOptionLength();<br />        innerHtml </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&lt;br/&gt;当前项索引:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> getSelectedIndex();<br />        innerHtml </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&lt;br/&gt;当前项文本:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> getCurrentOptionText(getSelectedIndex());<br />        innerHtml </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&lt;br/&gt;当前项值:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> getCurrentOptionValue(getSelectedIndex());<br />        divWatch.innerHTML </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> innerHtml;<br />        divWatch.align </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">justify</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />    }</span></div><br /><img src ="http://www.blogjava.net/jdo/aggbug/137341.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jdo/" target="_blank">蓝色幽默</a> 2007-08-16 17:24 <a href="http://www.blogjava.net/jdo/articles/137341.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何制作一个漂亮的 CSS 按钮</title><link>http://www.blogjava.net/jdo/articles/135959.html</link><dc:creator>蓝色幽默</dc:creator><author>蓝色幽默</author><pubDate>Fri, 10 Aug 2007 16:34:00 GMT</pubDate><guid>http://www.blogjava.net/jdo/articles/135959.html</guid><wfw:comment>http://www.blogjava.net/jdo/comments/135959.html</wfw:comment><comments>http://www.blogjava.net/jdo/articles/135959.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jdo/comments/commentRss/135959.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jdo/services/trackbacks/135959.html</trackback:ping><description><![CDATA[
		<p style="text-indent: 0pt; text-align: center;">
				<img src="http://img.istef.info/my_blog/uploads/2007/05/2007-5-9.jpg" alt="CSS Button" />
		</p>
		<p>如今 Web Application 横行，在 Web 2.0
网站的各种设计元素中，按钮是无法或缺的。如何用最简洁的方法制作最漂亮的按钮就成为了一个问题。本文讲述的方法，代码上简洁，符合 XHTML
标准，不需要 Javascript，只需要纯 CSS 即可完成，而且通用性很好，使用起来也很方便。上图即为最终成品的例子，您也可以通过<a href="http://blog.istef.info/demo/cssbutton">演示页面</a>体验一下。下面我将详述整个制作过程，相信通过这个教程您肯定可以学会。</p>
		<p>
				<strong>第一步：准备图片</strong>
		</p>
		<p style="text-indent: 0pt; text-align: center;">
				<img src="http://img.istef.info/my_blog/uploads/2007/05/2007-5-9-1.jpg" alt="按钮状态" />
		</p>
		<p>对于一个好的 UI，一个很重要的方面就是要能及时的与用户发生交互。对于按钮来说，我们需要让按钮相应各种鼠标事件，让用户知道<strong>它是可以按下的</strong>。如上图，我们要制作的按钮共有三种状态：<strong>正常状态</strong>、<strong>鼠标划过</strong>、<strong>鼠标按下</strong>。通常情况下，我们会想到利用 onclick、onmouseover 这样的事件来控制，而事实上，我们完全可以利用通用性、便捷性更好的 CSS 代替 Javascript 来完成这个过程。尽可能将表现的事情交给 CSS 来做，这也是良好设计的原则之一。</p>
		<p>为了能够实现这种效果，我们需要准备三个状态的图片。利用 CSS 的 background-position 属性，我们完全可以将三种状态的图片放在一张图片中，这样可以获得更好的缓存效果。</p>
		<p>此外，按钮两侧的圆角也是比较烦人的问题。因为我们要制作的按钮需要<strong>能够自动适应内部文字的长度</strong>，因此我们需要应用一种叫做“<a href="http://alistapart.com/articles/slidingdoors/">拉门技术 (Sliding door technique)</a>”的 CSS 技巧。具体原理不讲了，这里只介绍具体做法：</p>
		<p>我们使用超链接来生成按钮，为了使用 Sliding door technique，我们需要按照如下方式书写 HTML 代码：</p>
		<div class="hl-surround">
				<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
						<li class="hl-firstline">
								<span style="color: Olive;">&lt;</span>
								<span style="color: Green;">a</span>
								<span style="color: Gray;">
								</span>
								<span style="color: rgb(0, 0, 139);">class</span>
								<span style="color: Gray;">=</span>
								<span style="color: rgb(139, 0, 0);">"</span>
								<span style="color: Red;">button</span>
								<span style="color: rgb(139, 0, 0);">"</span>
								<span style="color: Gray;">
								</span>
								<span style="color: rgb(0, 0, 139);">href</span>
								<span style="color: Gray;">=</span>
								<span style="color: rgb(139, 0, 0);">"</span>
								<span style="color: Red;">http://some_where</span>
								<span style="color: rgb(139, 0, 0);">"</span>
								<span style="color: Olive;">&gt;&lt;</span>
								<span style="color: Green;">span</span>
								<span style="color: Olive;">&gt;</span>
								<span style="color: Gray;">Button Text</span>
								<span style="color: Olive;">&lt;/</span>
								<span style="color: Green;">span</span>
								<span style="color: Olive;">&gt;&lt;/</span>
								<span style="color: Green;">a</span>
								<span style="color: Olive;">&gt;</span>
						</li>
				</ol>
		</div>
		<p>随后，我们需要准备两张图片，作为按钮的背景（分别为 span 标签和 a 标签的），具体示意图如下：</p>
		<p style="text-indent: 0pt; text-align: center;">
				<img src="http://img.istef.info/my_blog/uploads/2007/05/2007-5-9-2.jpg" alt="背景图及布局示意图" />
		</p>
		<p>这里需要指出，280px 并不是绝对的，它代表了这个按钮在您的应用中可能用到的最大值。此外，所有的值都可以根据您实际的背景图做出更改。</p>
		<p>
				<strong>第二步：书写 CSS 代码</strong>
		</p>
		<p>为了能够让 A 标签准确的显示我们需要的效果，我们需要设定其 display 属性为
block，但是，很多情况下，我们需要在同一行中显示多个按钮，我们可以通过设定 float:left 或 float:right
来达到。提醒一下，这样设定後，当您放置完按钮后不要忘记 clear 一下 :)。</p>
		<p>首先看看显示基本布局的代码，本例中，两侧圆角部分为 10px，按钮高度为 24px，保留区域为 1px：</p>
		<div class="hl-surround">
				<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
						<li class="hl-firstline">
								<span style="color: Blue;">a.button</span>
								<span style="color: Gray;">
								</span>
								<span style="color: Olive;">{</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">background:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Red;">transparent</span>
								<span style="color: Gray;"> url(a.gif) </span>
								<span style="color: Red;">no-repeat</span>
								<span style="color: Gray;">
								</span>
								<span style="color: Red;">scroll</span>
								<span style="color: Gray;">
								</span>
								<span style="color: Red;">right</span>
								<span style="color: Gray;">
								</span>
								<span style="color: Red;">top</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">color:</span>
								<span style="color: Gray;"> </span>
								<span style="color: rgb(0, 0, 139);">White</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">display:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Red;">block</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">float:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Red;">left</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">height:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Maroon;">24</span>
								<span style="color: Red;">px</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">padding-right:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Maroon;">10</span>
								<span style="color: Red;">px</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">font:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Red;">normal</span>
								<span style="color: Gray;">
								</span>
								<span style="color: Maroon;">12</span>
								<span style="color: Red;">px</span>
								<span style="color: Gray;">
								</span>
								<span style="color: Red;">sans-serif</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">margin-right:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Maroon;">10</span>
								<span style="color: Red;">px</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">text-decoration:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Red;">none</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">    </span>
								<span style="color: Olive;">}</span>
						</li>
						<li>
								<span style="color: Gray;">    </span>
								<span style="color: Blue;">a.button</span>
								<span style="color: Gray;"> </span>
								<span style="color: Blue;">span</span>
								<span style="color: Gray;">
								</span>
								<span style="color: Olive;">{</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">background:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Red;">transparent</span>
								<span style="color: Gray;"> url(span.gif) </span>
								<span style="color: Red;">no-repeat</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">display:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Red;">block</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">padding:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Maroon;">5</span>
								<span style="color: Red;">px</span>
								<span style="color: Gray;">
								</span>
								<span style="color: Maroon;">1</span>
								<span style="color: Red;">px</span>
								<span style="color: Gray;">
								</span>
								<span style="color: Maroon;">5</span>
								<span style="color: Red;">px</span>
								<span style="color: Gray;">
								</span>
								<span style="color: Maroon;">11</span>
								<span style="color: Red;">px</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">line-height:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Maroon;">14</span>
								<span style="color: Red;">px</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">    </span>
								<span style="color: Olive;">}</span>
						</li>
				</ol>
		</div>
		<p>这里需要指出的是：1. 保留区 (1px) 是包含在 SPAN 中的，具体可以注意看 padding 的设置；2. SPAN  的 <em>line-height</em> + <em>padding-top</em> + <em>padding-bottom</em>  = A 的 <em>height</em>。</p>
		<p>经过这样设定后，我们的按钮的基本样式就完成了，但它还没有交互效果，我们通过设定 a:hover 和 a:active 来实现：</p>
		<div class="hl-surround">
				<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
						<li class="hl-firstline">
								<span style="color: Blue;">a.button</span>
								<span style="color: Navy;">:hover</span>
								<span style="color: Gray;">
								</span>
								<span style="color: Olive;">{</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">background-position:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Red;">right</span>
								<span style="color: Gray;"> -</span>
								<span style="color: Maroon;">24</span>
								<span style="color: Red;">px</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">    </span>
								<span style="color: Olive;">}</span>
						</li>
						<li>
								<span style="color: Gray;">    </span>
								<span style="color: Blue;">a.button</span>
								<span style="color: Navy;">:hover</span>
								<span style="color: Gray;"> </span>
								<span style="color: Blue;">span</span>
								<span style="color: Gray;">
								</span>
								<span style="color: Olive;">{</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">background-position:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Red;">left</span>
								<span style="color: Gray;"> -</span>
								<span style="color: Maroon;">24</span>
								<span style="color: Red;">px</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">    </span>
								<span style="color: Olive;">}</span>
						</li>
						<li>
								<span style="color: Gray;">    </span>
								<span style="color: Blue;">a.button</span>
								<span style="color: Navy;">:active</span>
								<span style="color: Gray;"> </span>
								<span style="color: Olive;">{</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">background-position:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Red;">right</span>
								<span style="color: Gray;"> -</span>
								<span style="color: Maroon;">48</span>
								<span style="color: Red;">px</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">    </span>
								<span style="color: Olive;">}</span>
						</li>
						<li>
								<span style="color: Gray;">    </span>
								<span style="color: Blue;">a.button</span>
								<span style="color: Navy;">:active</span>
								<span style="color: Gray;"> </span>
								<span style="color: Blue;">span</span>
								<span style="color: Gray;">
								</span>
								<span style="color: Olive;">{</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">background-position:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Red;">left</span>
								<span style="color: Gray;"> -</span>
								<span style="color: Maroon;">48</span>
								<span style="color: Red;">px</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">padding:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Maroon;">6</span>
								<span style="color: Red;">px</span>
								<span style="color: Gray;">
								</span>
								<span style="color: Maroon;">0</span>
								<span style="color: Gray;">
								</span>
								<span style="color: Maroon;">4</span>
								<span style="color: Red;">px</span>
								<span style="color: Gray;">
								</span>
								<span style="color: Maroon;">12</span>
								<span style="color: Red;">px</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">    </span>
								<span style="color: Olive;">}</span>
						</li>
				</ol>
		</div>
		<p>我们看到，主要是应用了 background-position 属性调整背景图片的位置，这比使用多张图片效果更好。在 <em>a.button:active span</em> 中，我们重新设定了 padding 的值，使字符向右下方移动 1px，按下的效果更明显，这也是之前提到的保留区的作用。</p>
		<p>
				<strong>第三部：最后完善</strong>
		</p>
		<p>其实做完上面两部，我们的按钮基本上已经完工了。但是在各种浏览器中都有一个讨厌的问题，就是当超链接被点击后，会留下一个讨厌的虚线框。这个破坏美观的东西，我们当然要干掉它。</p>
		<p>Firefox、Safari 等支持 W3C CSS2 的浏览器，可以通过设定 CSS 的 outline 属性来做到这一点。在我们这个例子中，只需做如下改动：</p>
		<div class="hl-surround">
				<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
						<li class="hl-firstline">
								<span style="color: Blue;">a.button</span>
								<span style="color: Navy;">:active</span>
								<span style="color: Gray;">
								</span>
								<span style="color: Olive;">{</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">background-position:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Red;">right</span>
								<span style="color: Gray;"> -</span>
								<span style="color: Maroon;">48</span>
								<span style="color: Red;">px</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">      </span>
								<span style="color: Green;">outline:</span>
								<span style="color: Gray;"> </span>
								<span style="color: Red;">none</span>
								<span style="color: Gray;">;</span>
						</li>
						<li>
								<span style="color: Gray;">    </span>
								<span style="color: Olive;">}</span>
						</li>
				</ol>
		</div>
		<p>在 Firefox 中看看，虚框已经消失了。</p>
		<p>但 Internet Explore 不吃这一套，对付它就比较麻烦了，单单 CSS 无法解决问题，需要从 HTML 下手。我们需要将按钮的 HTML 代码改为以下形式：</p>
		<div class="hl-surround">
				<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
						<li class="hl-firstline">
								<span style="color: Olive;">&lt;</span>
								<span style="color: Green;">a</span>
								<span style="color: Gray;">
								</span>
								<span style="color: rgb(0, 0, 139);">class</span>
								<span style="color: Gray;">=</span>
								<span style="color: rgb(139, 0, 0);">"</span>
								<span style="color: Red;">button</span>
								<span style="color: rgb(139, 0, 0);">"</span>
								<span style="color: Gray;">
								</span>
								<span style="color: rgb(0, 0, 139);">href</span>
								<span style="color: Gray;">=</span>
								<span style="color: rgb(139, 0, 0);">"</span>
								<span style="color: Red;">http://some_where</span>
								<span style="color: rgb(139, 0, 0);">"</span>
								<span style="color: Gray;">
								</span>
								<span style="color: rgb(0, 0, 139);">onclick</span>
								<span style="color: Gray;">=</span>
								<span style="color: rgb(139, 0, 0);">"</span>
								<span style="color: Red;">this.blur();</span>
								<span style="color: rgb(139, 0, 0);">"</span>
								<span style="color: Olive;">&gt;&lt;</span>
								<span style="color: Green;">span</span>
								<span style="color: Olive;">&gt;</span>
								<span style="color: Gray;">Button Text</span>
								<span style="color: Olive;">&lt;/</span>
								<span style="color: Green;">span</span>
								<span style="color: Olive;">&gt;&lt;/</span>
								<span style="color: Green;">a</span>
								<span style="color: Olive;">&gt;</span>
						</li>
				</ol>
		</div>
		<p>这样，我们可以让超链接在点击后迅速失去焦点，从而避免虚框的出现。当然，如果我们应用中按钮比较少，这个方法还不错。但按钮比较多的情况下，我们
还是应该用 DOM 方法来为 className 为 button 的 A 修改 onclick 事件（用 jQuery 或
Prototype 实现会很省心），不过这不在本文讨论的范围内了。</p>
		<p>到这里，我们的按钮就算做好了，我相信您一定已经学会了。如果还有什么不明白的地方，您可以参考这个<a href="http://istef.info/demo/cssbutton/">简单的范例</a>，查看它的源代码来解决。当然，您也可以直接在本文後提问，我很乐意为您解答。</p>
		<p>
				<strong>UPDATE:</strong>谢谢 Dan Li 发来邮件提醒，我确实发现本文与<a href="http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html">这篇文章</a>如
出一辙。早看到直接转过来就好了，白白折腾了两个小时。不知道留言中 DV
大侠所指的是不是这篇。不过我在写本文时并没有看过这篇文章，而且本文与原文还是有很大不同，而且原文中 CSS 有误
(background-position 的参数顺序不对)，虽然可以实现它所叙述的效果，但不符合 CSS
标准，也不能够进一步扩展，希望看了原文的朋友能够注意。</p>
<img src ="http://www.blogjava.net/jdo/aggbug/135959.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jdo/" target="_blank">蓝色幽默</a> 2007-08-11 00:34 <a href="http://www.blogjava.net/jdo/articles/135959.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>