Js/jQuery simple implementation of the tab Function

Source: Internet
Author: User
Tags acer

The first method is to use the native js Code as follows:
Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> simple tab </title>
<Style type = "text/css">
Body, ul, li {margin: 0; padding: 0 ;}
Body {font: 12px/1.5 Tahoma ;}
# Outer {width: margin PX; margin: 10px auto ;}
# Tab {overflow: hidden; zoom: 1; background: #000; border: 1px solid #000 ;}
# Tab li {float: left; color: # fff; height: 30px; cursor: pointer; line-height: 30px; list-style-type: none; padding: 0 20px ;}
# Tab li. current {color: #000; background: # ccc ;}
# Content {border: 1px solid #000; border-top-width: 0 ;}
# Content ul {line-height: 25px; display: none; margin: 0 30px; padding: 10px 0 ;}
</Style>
<Script type = "text/javascript">
Window. onload = function ()
{
Var oLi = document. getElementById ("tab"). getElementsByTagName ("li ");
Var oUl = document. getElementById ("content"). getElementsByTagName ("ul ");
For (var I = 0; I <oLi. length; I ++)
{
OLi [I]. index = I;
OLi [I]. onmouseover = function (){
For (var n = 0; n <oLi. length; n ++)
{
OLi [n]. className = "";
This. className = "current ";
}
For (var n = 0; n <oUl. length; n ++)
{
OUl [n]. style. display = "none ";
OUl [this. index]. style. display = "block ";

}
}
}
}

</Script>

</Head>
<Body>
<Div id = "outer">
<Ul id = "tab">
<Li class = "current"> Technology </li>
<Li> tourism </li>
<Li> entertainment </li>
</Ul>
<Div id = "content">
<Ul style = "display: block;">
<Li> Acer R7 Dual Axis deformation evaluation: the touchpad design is too alternative (figure) </li>
<Li> Sony Xperia Tablet Z Tablet evaluation </li>
<Li> Nokia Lumia 925 best WP8 smartphone </li>
<Li> Lenovo IdeaPad S405 Performance Evaluation mainstream endurance to be improved </li>
<Li> small chilies M2 smartphone evaluation: we should be old if we don't change the shell </li>
<Li> Lenovo K900's internal structure shows how many domestic artifacts are delivered (photos) </li>
<Li> Lenovo K900's internal structure shows how many domestic artifacts are delivered (photos) </li>
<Li> webpage skin change effect </li>
<Li> Lenovo K900's internal structure shows how many domestic artifacts are delivered (photos) </li>
</Ul>
<Ul>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>

</Ul>
<Ul>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
</Ul>
</Div>
</Div>

</Body>
</Html>

The second method is implemented using jQuery, and the code is simpler than the first method.
Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> simple tab </title>
<Style type = "text/css">
Body, ul, li {margin: 0; padding: 0 ;}
Body {font: 12px/1.5 Tahoma ;}
# Outer {width: margin PX; margin: 10px auto ;}
# Tab {overflow: hidden; zoom: 1; background: #000; border: 1px solid #000 ;}
# Tab li {float: left; color: # fff; height: 30px; cursor: pointer; line-height: 30px; list-style-type: none; padding: 0 20px ;}
# Tab li. current {color: #000; background: # ccc ;}
# Content {border: 1px solid #000; border-top-width: 0 ;}
# Content ul {line-height: 25px; display: none; margin: 0 30px; padding: 10px 0 ;}
</Style>
<Script type = "text/javascript" src = "js/jquery-1.4.2.min.js"> </script>
<Script type = "text/javascript">

$ (Function (){
Var timeid;
$ ("# Tab"). find ("li"). each (function (index ){
Var sLi = $ (this );
SLi. mouseenter (function (){
Timeid = setTimeout (function (){
SLi. addClass ("current"). siblings (). removeClass ("current ");
SLi. parent (). next (). find ("ul: eq (" + index + ")"). show (). siblings (). hide ();
},300 );
}). Mouseleave (function (){
ClearTimeout (timeid );
})

})
})

</Script>

</Head>
<Body>
<Div id = "outer">
<Ul id = "tab">
<Li class = "current"> Technology </li>
<Li> tourism </li>
<Li> entertainment </li>
</Ul>
<Div id = "content">
<Ul style = "display: block;">
<Li> Acer R7 Dual Axis deformation evaluation: the touchpad design is too alternative (figure) </li>
<Li> Sony Xperia Tablet Z Tablet evaluation </li>
<Li> Nokia Lumia 925 best WP8 smartphone </li>
<Li> Lenovo IdeaPad S405 Performance Evaluation mainstream endurance to be improved </li>
<Li> small chilies M2 smartphone evaluation: we should be old if we don't change the shell </li>
<Li> Lenovo K900's internal structure shows how many domestic artifacts are delivered (photos) </li>
<Li> Lenovo K900's internal structure shows how many domestic artifacts are delivered (photos) </li>
<Li> webpage skin change effect </li>
<Li> Lenovo K900's internal structure shows how many domestic artifacts are delivered (photos) </li>
</Ul>
<Ul>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>
<Li> fall in love with Seattle, featured U.S. panoramic tours </li>

</Ul>
<Ul>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
<Li> li an announces his resignation from the American drama "Tyrant": You need to rest. </li>
</Ul>
</Div>
</Div>

</Body>
</Html>

The first method is to use native js for reference and other methods, and the second method is written on the basis of the first method...

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.