I found a lot of jquery effects on the Internet, so I wrote one myself. Prevents tab switching during page refreshing,
Html code:
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>
<Title> </title>
<Link href = "../Style/admin.css" rel = "stylesheet" type = "text/css"/>
<Script type = "text/javascript" src = "System/js/jquery-1.7.min.js"> </script>
<Script type = "text/javascript" src = "tabs. js"> </script>
<Style type = "text/css">
. Tabs {list-style: none; width: 400px; height: 23px ;}
. Tabs a {display: block; float: left; padding: 2px 3px; background: # eff7ff; text-decoration: none; margin-right: 2px ;}
. Tabs a. current {background: # a1c6de; color: #000 ;}
. Tab {display: block; width: 400px; height: 300px; border: 1px solid # ccc ;}
</Style>
</Head>
<Body>
<Div class = "tabs">
<A href = "# xiangmu"> Project Information </a> <a href = "# kehu"> ask questions about the position of the customer </a> <a href = "# wenda"> </a>
</Div>
<Div id = "xiangmu" class = "tab"> Project Information </div>
<Div id = "kehu" class = "tab"> customer </div>
<Div id = "wenda" class = "tab"> post question </div>
</Body>
</Html>
Js Code:
Copy codeThe Code is as follows:
$ (Function (){
$ ("Div. tab"). hide (); // hide all
$ ("Div. tabs a: first"). addClass ("current"); // select the first element
$ ("Div. tab: first"). show (); // display the first content
$ ("Div. tabs a"). click (function (){
$ ("Div. tabs a"). removeClass ("current"); // remove all tabs from the current style
$ (". Tab"). hide (); // hide all
$ (This). addClass ("current ");
Var activeTab = $ (this). attr ("href"); // obtain the div
$ (ActiveTab). show ();
});
// Obtain
Var url = window. location. href;
Var reg =/#. + /;
If (reg. test (url) {// contains #. The default value is only one #, and multiple # are not considered.
// Hide all
$ ("Div. tabs a"). removeClass ("current"); // remove all tabs from the current style
$ (". Tab"). hide (); // hide all
Var href = url. split ('#') [1];
$ ("Div. tabs [href = #" + href + "]"). addClass ("current ");
$ ("#" + Href). show ();
}
});
The code is very simple and the idea is clear, but it is very practical,
For example, in the previous example, if you want to refresh the page and locate the second tab, you only need to re-specify xxx. aspx # kehu.
Appendix