Based on jquery tab Toggle (Prevent page refresh) _jquery

Source: Internet
Author: User
I found a lot of jquery effects on the internet, and so I wrote one. Prevents the page from refreshing the tab switch,
HTML code:
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<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>
<body>
<div class= "Tabs" >
<a href= "#xiangmu" > Project information </a> <a href= "#kehu" > Customer </a><a href= "#wenda" > Job questions </a>
</div>
<div id= "Xiangmu" class= "tab" > Project information </div>
<div id= "Kehu" class= "tab" > Customer </div>
<div id= "Wenda" class= "tab" > Job Questions </div>
</body>

JS Code:
Copy Code code as follows:

$ (function () {
$ ("Div.tab"). Hide (); Hide All
$ ("Div.tabs A:first"). AddClass ("current"); The first element is selected
$ ("Div.tab:first"). Show (); The first content displays
$ ("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"); Get Div
$ (Activetab). Show ();
});
Gets the message passed from the URL.
var url = window.location.href;
var reg =/#.+/;
if (reg.test (URL)) {//contains #, defaults to only one #, multiple # situations 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, the idea is very clear, but very practical,
For example, in the previous example, you refresh the page, you want to reposition to the second tab, just need to reassign Xxx.aspx#kehu
Attached screenshot

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.