zoukankan      html  css  js  c++  java
  • jquery——选项卡

    下面是闭包做选项卡:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>闭包做选项卡</title>
        <style type="text/css">
            .btns{
                500px;
                height:50px;
            }
            .btns input{
                100px;
                height:50px;
                background-color: #ddd;
                color:#666;
                border:0;
            }
            .btns input.cur{
                background-color: gold;
            }
    
            .contents div{
                500px;
                height:300px;
                background-color: gold;
                display: none;
                line-height:300px;
                text-align: center;
            }
    
            .contents div.active{
                display: block;
            }
    
        </style>
        <script type="text/javascript">
    
            window.onload = function(){
    
                var aBtn = document.getElementById('btns').getElementsByTagName('input');
    
                var aContent = document.getElementById('contents').getElementsByTagName('div');
    
                //用闭包存起来,这个i就有1,2,3这个值了,不过实际中不这样用,小题大做了
                for(var i=0;i<aBtn.length;i++){
    
                    (function (i) {
                        aBtn[i].onclick = function () {
    
                            for(var j=0;j<aBtn.length;j++){
                                aBtn[j].className = '';
                                aContent[j].className = '';
                            }
    
                            this.className = 'cur';
                            aContent[i].className = 'active';
                        }
                    })(i)
                }
            }
    
        </script>
    </head>
    <body>
        <div class="btns" id="btns">
            <input type="button" value="tab01" class="cur">
            <input type="button" value="tab02">
            <input type="button" value="tab03">
        </div>
        <div class="contents" id="contents">
            <div class="active">tab文字内容一</div>
            <div>tab文字内容二</div>
            <div>tab文字内容三</div>
        </div>
    
    </body>
    </html>

    jquery库做选项卡:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>js库做选项卡</title>
        <script type="text/javascript" src="jquery-1.12.4.min.js"></script>
        <style type="text/css">
            .btns{
                500px;
                height:50px;
            }
            .btns input{
                100px;
                height:50px;
                background-color: #ddd;
                color:#666;
                border:0;
            }
            .btns input.cur{
                background-color: gold;
            }
    
            .contents div{
                500px;
                height:300px;
                background-color: gold;
                display: none;
                line-height:300px;
                text-align: center;
            }
    
            .contents div.active{
                display: block;
            }
        </style>
        <script type="text/javascript">
            $(function () {
    
                $('#btns input').click(function(){
                    //this是原生的对象
                    $(this).addClass('cur').siblings().removeClass('cur');
                    //alert($(this).index())弹出索引值
                    $('#contents div').eq($(this).index()).addClass('active').
              siblings().removeClass('active') }) }) </script> </head> <body> <div class="btns" id="btns"> <input type="button" value="tab01" class="cur"> <input type="button" value="tab02"> <input type="button" value="tab03"> </div> <div class="contents" id="contents"> <div class="active">tab文字内容一</div> <div>tab文字内容二</div> <div>tab文字内容三</div> </div> </body> </html>
  • 相关阅读:
    Socket异步通信
    以读取博客园随笔备份为例 将xml 序列化成json,再序列化成对象
    NhibernateProfiler写个自动破解工具
    关于下载GAE High Replication Datastore数据
    .text 0.958 数据添加
    C#实现RTP数据包传输参照RFC3550
    在线商城表结构
    相似字符串
    .net 4.0 的Socket写的支持跨平台双工的轻量级通讯组件
    写一个迷你版Smarty模板引擎,对认识模板引擎原理非常好(附代码)
  • 原文地址:https://www.cnblogs.com/gaoquanquan/p/9205653.html
Copyright © 2011-2022 走看看