当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 一个tab标签切换效果代码

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

Javascript 中的 一个tab标签切换效果代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 547 ::
收藏到网摘: n/a

网上比较流行的一种tab切换效果代码,主要是用于导航的一些栏目。 HTML:
复制代码 代码如下:

<div class="tab">
<div id="tabsK">
<ul id="menu4">
<li onclick="settab(4,0)" class="hover"><a title="最新更新"><span>最新更新</span></a></li>
<li onclick="settab(4,1)"><a title="企业新闻"><span>企业新闻</span></a></li>
<li onclick="settab(4,2)"><a title="行业新闻"><span>行业新闻</span></a></li>
<li onclick="settab(4,3)"><a title="专栏文章"><span>专栏文章</span></a></li>
<li onclick="settab(4,4)"><a title="科技新闻"><span>科技新闻</span></a></li>
</ul>
</div>
<div class="tab2" id="main4">
<ul class="block"></ul>
<ul ></ul>
<ul ></ul>
<ul ></ul>
<ul ></ul>
</div>
</div>

CSS:
复制代码 代码如下:

#tabsK {
float:left;
width:100%;
line-height:normal;
border-bottom:1px solid #54545C;
}
#tabsK ul {
margin:0;
padding:10px 10px 0 10px;
list-style:none;
}
#tabsK li {
display:inline;
margin:0;
padding:0;
cursor:pointer;
}
#tabsK a {
float:left;
background:url("image/tableftK.gif") no-repeat left top;
margin:0;
padding:0 0 0 4px;
text-decoration:none;
}
#tabsK a span {
float:left;
display:block;
background:url("image/tabrightK.gif") no-repeat right top;
padding:8px 16px 4px 6px;
color:#FFF;
}
#tabsK a span {float:none;}
/* End IE5-Mac hack */
#tabsK a:hover span {
cursor:pointer;
color:#FFF;
background-position:100% -42px;
}
#tabsK a:hover {
background-position:0% -42px;
cursor:pointer;
}
#tabsK .hover a
{
background-position:0% -42px;
}
#tabsK .hover span
{
background-position:100% -42px;
}
.tab2 ul
{
display:none;
list-style-type:none;
height:560px;
}
.tab2 ul li
{
text-align:left;
line-height:20px;
text-indent:1em;
}
.tab2 .block
{
display:block;
}

JS:
复制代码 代码如下:

<script language="javascript"><!--
function settab(m,n){
var tli=document.getElementById("menu"+m).getElementsByTagName("li");
var mli=document.getElementById("main"+m).getElementsByTagName("ul");
for(i=0;i<tli.length;i++){
tli[i].className=i==n?"hover":"";
mli[i].style.display=i==n?"block":"none";
}
}
// --></script>

截图和用到的两张图片: