A Simple tab tab

Source: Internet
Author: User

Limited capacity, first write a simple tab, this year is officially the Army JS Army, bought a variety of books to see Ah, look at all kinds of messy ah, first reserve, will continue to come back to optimize, advanced, who see this article can also message paste code, Hao

<! DOCTYPE html>

<style>
*{margin:0;padding:0;}
body{font-size:62.5%;p Adding:20em;}
p {margin-left:10px;}
. Container{width:30em;height:auto;height:auto;}
ul{list-style:none;border-bottom:1px solid #ccc;p adding:0;}
Ul.tabs:before,ul.tabs:after{display:table;line-height:0;content: "";}
ul.tabs:after{Clear:both;}
UL li{/*display:inline-block;*/Float:left;}
UL Li a{line-height:20px;border:1px solid #ccc;p Adding:.8em;border-bottom-color:transparent;display:block;}
UL Li A{color: #000;}
UL li.active A{color: #08c; border-bottom-color:transparent;margin-bottom:-1px;}
. tab-content{padding-top:20px;padding-left:20px;}
. tab-content. Hide{display:none;}
</style>

<body>
<div class= "Container" >
<ul id= "Mytab" class= "tabs" >
<li class= "Active" ><a href= "#hello" >hello</a></li>
<li><a href= "#world" >world</a></li>
</ul>
<div class= "Tab-content" >
<div class= "Tab-pane Tab-hello" >hellohellohellohellohellohellohello</div>
<div class= "Tab-pane tab-world Hide" >worldworldworldworldworldworldworldworld</div>
</div>

</div>

<script src= "Http://code.jquery.com/jquery-latest.js" ></script>
<script>
$ (function () {
$ ("#myTab a"). On ("click", Function (e) {
E.preventdefault ();
var $tab = $ (this);
var pane = $tab. attr ("href"). Replace ("#", ""); This can be used to ID do not need replace ("#", ""), if you want to save the easy a-tag can be removed
$tab. Parent (). addclass ("active"). End (). CSS ({' Background ': ' #f9e590 '}); Using a chained call this end () back to the previous $tab state (purely for use as a chained call)
$tab. Parent (). siblings (). Removeclass ("active"). End (). siblings (). Find ("a"). css ({' Background ': '}); It makes me wonder if it's pointing to not a, but Li making a mark and looking back.

$tab. Parents (). Find (". tab-" +pane). CSS ("Display", "block");
$tab. Parents (). Find (". tab-" +pane). Siblings (). CSS ("display", "none");

});

});

</script>
</body>

The knowledge point is probably a chain call to the relevant api:http://www.jquery123.com/end/

a brief introduction to the chain operation Principle of jquery: http://www.zhangyunling.com/?p=207

A Simple tab tab

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.