Code for cross-page tabs Navigation Based on Jquery $. cookie ()

Source: Internet
Author: User

--------- Tabs. js -----------------
Copy codeThe Code is as follows:
$ (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 ----------------------
Copy codeThe Code is as follows:
. 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 -----------------------------------
Copy codeThe Code is as follows:
<! 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> untitled document </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"> page 1 </a> </li>
<Li> <a href = "2.html"> page 2 </a> </li>
<Li> <a href = "3.html"> page 3 </a> </li>
</Ul>
</Body>
</Html>

The other two pages are the same. You can change the file.
Mark Dzone night owl
From: http://www.cnblogs.com/dzone

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.