javascript兼容性较强的选项卡菜单

来源:互联网 发布:eplan软件 编辑:程序博客网 时间:2024/06/05 19:34

http://www.111cn.net/js_a/javascript-dh/42477.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>简洁实用的选项卡菜单</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<!--把下面代码加到<head>与</head>之间-->
<style type="text/css">
ul,li{margin:0;padding:0;}
.tabBox{width:268px;margin:20px;}
ul.tabTag{height:28px;border-bottom:1px solid #000;list-style:none}
ul.tabTag li{float:left;line-height:27px;height:27px;padding:0 18px;color:#ccc;border:1px solid #ccc;border-bottom:none;margin-right:5px;background:#fff;cursor:pointer;}
ul.tabTag li.active{border-color:#000;background:#eee;color:red;position:relative;top:1px;}
.tabCon{border:1px solid #000;border-top:none;background:#fff;}
.tCon{display:none;background:#eee;padding:25px;}
</style>
<script type="text/javascript">
/*
函数功能:实现tab菜单
tabMenu(tabBox,navClass);
参数一:tabBox(tab容器id)
参数二:navClass(当前标签样式class)
备注:依赖指定html结构
Author: wubai,QQ:464216089,By: 2012.4.7
*/
function tabMenu(tabBox,navClass){
var tabNavLi=document.getElementById(tabBox).getElementsByTagName("ul")[0].getElementsByTagName("li");
var tabCon=document.getElementById(tabBox).getElementsByTagName("div")[0].getElementsByTagName("div");
var tabLens=tabCon.length;
for(var i=0;i<tabLens;i++){
//应用js闭包传入参数i作为当前索引值赋值给m
 (function(m){
tabNavLi[m].onmouseover = function(){
for(var j=0; j<tabLens; j++){
tabNavLi[j].className = (j==m)?navClass:"";
tabCon[j].style.display = (j==m)?"block":"";
}
}
 })(i);
}
}
//函数调用
window.onload=function(){
tabMenu("tabBox1","active");
tabMenu("tabBox2","active");
}
</script>
</head>
<body>
<!--把下面代码加到<body>与</body>之间-->
<!--demo1-->
<div id="tabBox1" class="tabBox">
<ul class="tabTag">
<li class="active">新闻1</li>
<li>体育1</li>
<li>财经1</li>
</ul>
<div class="tabCon">
<div class="tCon" style="display:block">新闻1内容</div>
<div class="tCon">体育1内容</div>
<div class="tCon">财经1内容</div>
</div>
</div>
<!--demo2-->
<div id="tabBox2" class="tabBox">
<ul class="tabTag">
<li class="active">新闻2</li>
<li>体育2</li>
<li>财经2</li>
</ul>
<div class="tabCon">
<div class="tCon" style="display:block">新闻2内容</div>
<div class="tCon">体育2内容</div>
<div class="tCon">财经2内容</div>
</div>
</div>
</body>
</html></td>
 </tr>

</table>


原创粉丝点击