• 一个简单的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"><href="#">A</a></li>
        
    <li class="tab"><href="#">B</a></li>
        
    <li class="tab"><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>


  • 相关阅读:
    JS仿淘宝网顶部的导航菜单
    JS+CSS打造高仿XP默认主题菜单样式
    Jquery打造网页右上角可伸缩关闭的菜单
    来自百度百科的目录显示/隐藏效果
    Jquery打造的下拉层式菜单
    javascript小數位四舍五入[IE5.5+]
    css外容器margin問題[IE中height:100%]
    EXEC执行动态SQL时取出变量值[EXEC函数只能是局部变量]
    sql一列变多列
    判斷日期,輸出成YYYY/MM/DD形式
  • 原文地址:https://www.cnblogs.com/rentj1/p/1678379.html
Copyright © 2020-2023  润新知