WEB前端:01_Tab选项卡

2020-11-14 22:44

阅读:847

YPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">

标签:com   http   class   blog   div   code   style   img   java   javascript   string   

 

Tab选项卡

 采用两种方法实现选项卡切换功能,目前只提供了最基本的切换效果,后期增加jquery版和渐变切换效果。

 

效果图:

bubuko.com,布布扣

纯JS简化版:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Tab选项卡 - 纯JS简化版
"Content-Type" content="text/html; charset=utf-8">
>
#btn { width: 500px; height: 30px; margin:0;padding: 0; list-style: none;}
#btn li { cursor: pointer; float: left; width: 100px; height: 30px; margin-right: 2px; background: #666; color:#fff; text-align: center; line-height: 30px;}
#btn li.onbtn {background: #f00;}
#tabs div {display: none; width: 500px; height: 100px; border: 1px solid #ccc;}
>
window.onload = function() {
 
    var btn = document.getElementById(‘btn‘);
    var btnli = btn.getElementsByTagName(‘li‘);
    var tabs = document.getElementById(‘tabs‘);
    var tabsdiv = tabs.getElementsByTagName(‘div‘);
 
    for (var a=0; a
        btnli[a].index=a;
        btnli[a].onmouseover = function() {
            for (var b=0; b
                btnli[b].className = "";
                tabsdiv[b].style.display = "none";
            }
            this.className = "onbtn";
            tabsdiv[this.index].style.display = "block";
        }
    }
     
    btnli[0].className = "onbtn";
    tabsdiv[0].style.display = "block";
     
}
 
    "btn">
    
  • 选项一
  •     
  • 选项二
  •     
  • 选项三
  • "tabs">
        
    选项一内容
        
    选项二内容
        
    选项三内容
     

     

     纯JS面向对象版:

    ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    纯JS - 面向对象版
    "Content-Type" content="text/html; charset=utf-8">
    >
    #btn, #btn2 { width: 500px; height: 30px; margin:0;padding: 0; list-style: none;}
    #btn li, #btn2 li { cursor: pointer; float: left; width: 100px; height: 30px; margin-right: 2px; background: #666; color:#fff; text-align: center; line-height: 30px;}
    #btn li.onbtn, #btn2 li.onbtn {background: #f00;}
    #tabs div, #tabs2 div {display: none; width: 500px; height: 100px; border: 1px solid #ccc; margin-bottom:10px;}
    >
     
    function tab(btn, tabs) {
        var _this = this;
        var btn = document.getElementById(btn);
        var tabs = document.getElementById(tabs);
        this.btnli = btn.getElementsByTagName(‘li‘);
        this.tabsdiv = tabs.getElementsByTagName(‘div‘);
     
        for (var a=0; athis.btnli.length; a++) {
            this.btnli[a].index = a;
            this.btnli[a].onmouseover = function() {
                _this.onmouseoverfn(this);
            }
        }
        this.tabsdiv[0].style.display = "block";
        this.btnli[0].className = "onbtn";
    }
     
    tab.prototype.onmouseoverfn = function(obj) {
        for (var b=0; bthis.btnli.length; b++) {
            this.tabsdiv[b].style.display = "none";
            this.btnli[b].className = "";
        }
        this.tabsdiv[obj.index].style.display = "block";
        this.btnli[obj.index].className = "onbtn";
    }
     
    window.onload = function() {
        new tab(‘btn‘, ‘tabs‘);
        new tab(‘btn2‘, ‘tabs2‘);
    }
     
     
      "btn">
        
  • 选项一
  •     
  • 选项二
  •     
  • 选项三
  • "tabs">
        
    选项一内容
        
    选项二内容
        
    选项三内容
     
      "btn2">
        
  • 选项一
  •     
  • 选项二
  •     
  • 选项三
  • "tabs2">
        
    选项一内容
        
    选项二内容
        
    选项三内容
     

     

    WEB前端:01_Tab选项卡,布布扣,bubuko.com

    WEB前端:01_Tab选项卡

    标签:com   http   class   blog   div   code   style   img   java   javascript   string   

    原文地址:http://www.cnblogs.com/haicheng/p/3694684.html


    评论


    亲,登录后才可以留言!