zoukankan      html  css  js  c++  java
  • Jquery+$.cookie()实现跨越页面tabs导航

    -

    Jquery+$.cookie()实现跨越页面tabs导航

    ---------tabs.js----------------- 

      $(function(){


            //init seleted tab
            var on= $.cookie('current_tab');
            if(on!="" && !isNaN(on))
            {
                $(".nav li").eq(on).addClass("on").siblings().removeClass();
            }
            //default tab
            else
            { $.cookie('current_tab', 0); }

            //change tab
            $(".nav li").click(function(){
                var current_tab = $(".nav li").index(this);
                $.cookie('current_tab', current_tab);
                window.location = $(this).attr("href");
            });

        })

    ---------------css.css----------------------

    .nav { overflow:hidden; height:20px;}
    .nav li { float:left; display:inline; padding:3px;}
    .nav li a:hover { color:yellow; }
    .nav li.on { background:#900; color:#FFF;}
    .nav li.on a { color:#fff; }
    .nav li.on a:hover { color:yellow; }
    a { text-decoration:none; }

     ---------------------  1.html -----------------------------------

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>

    <link rel="stylesheet" type="text/css" href="css.css" />
    <script type="text/javascript" language="javascript" src="jquery-1.4.4.min.js"></script>
    <script type="text/javascript" language="javascript" src="jquery.cookie.js"></script>
    <script type="text/javascript" language="javascript" src="tabs.js"></script>

    </head>

    <body>
    <ul class="nav">
        <li><a href="1.html">第一页</a></li>
        <li><a href="2.html">第二页</a></li>
        <li><a href="3.html">第三页</a></li>
    </ul>
    </body>
    </html>

    其它两个页面一样,文件改一下可以了

     
  • 相关阅读:
    《JFlow: Practical Mostly-Static Information Flow Control》
    《嵌入式Linux C编程》第一章笔记
    Ansible --- 通过Ansible管理地区机房中的内网机器
    等保审核 --- MySQL密码复杂度
    等保审核 --- MySQL连接控制插件
    等保审核 --- MySQL操作审计记录
    CSS中居中的完全指南(中英对照翻译)
    svn提交报database is locked
    PHP session_cache_expire 会话函数
    MySQL CONCAT_WS 函数
  • 原文地址:https://www.cnblogs.com/dzone/p/1969536.html
Copyright © 2011-2022 走看看