最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用javascript實(shí)現(xiàn)簡(jiǎn)單的選項(xiàng)卡切換

 更新時(shí)間:2015年01月09日 08:59:47   投稿:hebedich  
本文主要介紹了使用javascript實(shí)現(xiàn)簡(jiǎn)單的選項(xiàng)卡切換的效果,代碼非常的簡(jiǎn)單,兼容性十分棒,這里推薦給小伙伴們。

代碼相當(dāng)簡(jiǎn)潔、簡(jiǎn)單易懂,就不多廢話了。

直接奉上代碼:

復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-type" content="text/html" charset="utf-8">
        <title>js簡(jiǎn)單選項(xiàng)卡</title>
        <script type="text/javascript" src="js/demo.js"></script>

        <style type="text/css">
            *{ 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;}
        </style>

    </head>
    <body>
        <div class="tabs" id="tabs">
            <h2 class="tabs-nav clearfix">
                <a href="javascript:;" class="on">首頁(yè)</a>
                <a href="javascript:;">技術(shù)</a>
                <a href="javascript:;">生活</a>
                <a href="javascript:;">作品</a>
            </h2>
            <div style="clear:both;"></div>
            <p class="tabs-content">首頁(yè)</p>
            <p class="tabs-content_hide">技術(shù)</p>
            <p class="tabs-content_hide">生活</p>
            <p class="tabs-content_hide">作品</p>
        </div>
   
    </body>
<footer></footer>
</html>

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

復(fù)制代碼 代碼如下:

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.length;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.length ;i++) {
                tabsContent[i].index = i;
                tabsContent[i].className = "tabs-content_hide";
        }
        tabsContent[n].className="tabs-content";
    }
        function clearClass(){
            for(var i=0;i<tabBtn.length;i++){
                tabBtn[i].className="";
            }
        }
    }
}

是不是很簡(jiǎn)單就實(shí)現(xiàn)了選項(xiàng)卡的切換效果呢,小伙伴們自己美化下就可以用到自己項(xiàng)目中去了。

相關(guān)文章

最新評(píng)論

龙川县| 大兴区| 垫江县| 大同市| 常山县| 曲周县| 广州市| 宜兰市| 威远县| 武安市| 临海市| 林州市| 平昌县| 岢岚县| 集贤县| 仙桃市| 且末县| 龙胜| 迭部县| 莱西市| 察雅县| 盐山县| 乌兰浩特市| 浪卡子县| 华安县| 阳山县| 白水县| 苍梧县| 四会市| 凌云县| 阳信县| 惠东县| 屯留县| 正安县| 辉南县| 忻州市| 天水市| 合川市| 漳浦县| 平南县| 和平区|