建站学 - 轻松建站从此开始!

建站学-个人建站指南,网页制作,网站设计,网站制作教程

Javascript Tab选项卡切换代码

时间:2011-04-23 12:25来源: 作者: 点击:
一个Javascript Tab选项卡切换的代码 <!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>

一个Javascript Tab选项卡切换的代码

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>建站学_选项卡切换控件演示</title>
<style type="text/css">

.tabBox{ width:200px; height:200px; border:1px solid #ccc;}
.tab{ color:#00F}
.on{ color:#F00; font-weight:bold}
.panel{}
.none{display:none}
</style>
</head>
<body>
<div class="tabBox">
  <ul id="tabs">
    <li class="tab on"><a href="#">A</a></li>
    <li class="tab"><a href="#">B</a></li>
    <li class="tab"><a href="#">C</a></li>
  </ul>
  <div id="panels">
    <div class="panel">T_A</div>
    <div class="panel none">T_B</div>
    <div class="panel none">T_C</div>
  </div>
</div>

<script type="text/javascript">
(function(){
    function TabView() {
        this.tabs = [];
        this.panels = [];
        this.eventName = "";
    }
   
    TabView.prototype.init = function (eventName,onFocusClassName){
        var tabs = this.tabs;
        var panels = this.panels;
        eventName = eventName || "mouseover";
        for(var i=0; i<tabs.length; i++)
        {
            tabs[i].key = i
            tabs[i]["on"+eventName] = function(){
                //clear tabs
                for(var j = 0; j<tabs.length;j++)
                {
                    tabs[j].className = tabs[j].className.replace(eval("/ ?"+onFocusClassName+" ?/"),"");
                }
               
                //clear panels
                for(var j =0 ;j<panels.length;j++){
                    panels[j].style.display = "none";
                }
               
                //set
                this.className += " "+ onFocusClassName;
                panels[this.key].style.display = "block"
            }
        }
    }
    window.TabView = TabView;         
})();

var test = new TabView();
test.tabs = document.getElementById("tabs").getElementsByTagName("li");
test.panels = document.getElementById("panels").getElementsByTagName("div");
test.init("click","on");
</script>
</body>
</html>

 

(责任编辑:admin)
织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片