栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

使用javascript实现简单的选项卡切换

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用javascript实现简单的选项卡切换

代码相当简洁、简单易懂,就不多废话了。

直接奉上代码:

复制代码 代码如下:


   
       
        js简单选项卡
       

       
            *{ font-size: 14px;margin: 0px;}
    a{color:#a0b3d6;text-decoration: none;}
    .tabs{border:1px solid #a0b3d6;margin:100px;width:350px;}
    .tabs-nav a{background:#eaf0fd; line-height:30px;padding:0px 20px 0px 20px;display:inline-block;border-right:1px solid #a0b3d6;border-bottom:1px solid #a0b3d6; float:left;}
    .tabs-nav .on{background:white; border-bottom:1px solid white; position:relative;}
    .tabs-content{display: block; padding:20px;border-top:1px solid #a0b3d6; margin-top:-1px;}
    .tabs-content_hide{display: none;}
       

   
   
       
           


                首页
                技术
                生活
                作品
           
           
           

首页


           

技术


           

生活


           

作品


       
   
   


------demo.js---------------

复制代码 代码如下:
window.onload=function(){
    tabs("tabs","mouseover");
}
function tabs(id,trigger){
    var tabBtn = document.getElementById(id).getElementsByTagName("h2")[0].getElementsByTagName("a");
    var tabsContent = document.getElementById(id).getElementsByTagName("p");
    for(var i=0;i         tabBtn[i].index = i;
        if(trigger=='mouseover'){
            tabBtn[i].onmouseover=function(){
                clearClass();
                this.className="on";
                showContent(this.index);
            }
        }
        function showContent(n){
            for (var i=0; i                 tabsContent[i].index = i;
                tabsContent[i].className = "tabs-content_hide";
        }
        tabsContent[n].className="tabs-content";
    }
        function clearClass(){
            for(var i=0;i                 tabBtn[i].className="";
            }
        }
    }
}

是不是很简单就实现了选项卡的切换效果呢,小伙伴们自己美化下就可以用到自己项目中去了。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/104602.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号