jQuery学习笔记--标签切换

实现标签切换的代码

.html

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <link href="css/app.css" type="text/css" rel="stylesheet">
    <script src="js/jquery-2.1.4.min.js"></script>
    <script src="js/app.js"></script>
</head>
<body>
    <ul id="tab1">
        <li class="tabin">标签1</li>
        <li>标签2</li>
        <li>标签3</li>
    </ul>
    <div class="content cfirst">
        内容1
    </div>
    <div class="cfirst">
        内容2
    </div>
    <div class="cfirst">
        内容3
    </div>
    <br/>
    <br/>
    <br/>
    <br/>
    <ul id="tab2">
        <li class="tabin">装载完整页面</li>
        <li>装载部分页面</li>
        <li>装载网络数据</li>
    </ul>
    <div id="content2">
        <div id="realc">

        </div>
    </div>
</body>
</html>

. css
ul, li{
    margin: 0;
    padding: 0;
    list-style: none;
}

li{
    float:left;
    background-color: black;
    color: white;
    padding: 5px;
    margin-right: 2px;
    border: 1px solid white;
}

.tabin{
    background-color: #6e6e6e;
    border: 1px solid #6e6e6e;
}

.cfirst{
    clear: both;
    background-color: #6e6e6e;
    color: white;
    width: 300px;
    height: 100px;
    padding: 10px;
    display: none;
}

.content{
    display: block;
}

#tab2 li{
    float: left;
    background-color: #ffffff;
    color: blue;
    padding: 10px;
    margin-right: 2px;
    cursor: pointer;
}

#tab2 li.tabin{
    background-color: #f2f6f8;
    border: 1px solid #000000;
    border-bottom: 0;
    z-index: 100;
    position: relative;
}

#content2{
    width: 500px;
    height: 200px;
    padding: 10px;
    background-color: #f2f6f8;
    clear: both;
    border: 1px solid #000000;
    top: -2px;
    position: relative;
}

. js

$(document).ready(function(){
    $("#tab1 li").each(function(index){
        var liNode = $(this);
        $(this).mouseover(function(){
            timeoutid = setTimeout(function () {
                $("div.content").removeClass("content");
                $("#tab1 li.tabin").removeClass("tabin");
                $("div").eq(index).addClass("content");
                liNode.addClass("tabin");
            },300);
        }).mouseout(function(){
            clearTimeout(timeoutid);
        });
    });

    $("#realc").load("mytab.html");
    $("#tab2 li").each(function (index) {
        $(this).click(function(){
            $("#tab2 li.tabin").removeClass("tabin");
            $(this).addClass("tabin");
            if(index==0){
                $("#realc").load("mytab.html");
            }else if(index==1){
                $("#realc").load("mytab.html");
            }else if(index==2){
                $("#realc").load("mytab.html");
            }
        })
    })

});


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值