JQuery provides several lines of code to implement tab switching.

Source: Internet
Author: User

JQuery provides several lines of code to implement tab switching.

This article describes a simple tab Code implemented by jQuery. It implements tab switching by controlling css familiarity. The idea is clear and we recommend it to you here.

 

 

Today, with a sudden whim, you can think of a very simple method to achieve the tab effect.

In fact, the logic is very simple, but it is basically not written on the Internet.

I wonder if there is any problem in the actual application. Could you please advise?

 

The Code is as follows:


<! Doctype html>
<Html lang = "en">
<Head>
<Meta charset = "UTF-8">
<Title> jQuery simple tab </title>
<Style>
* {Margin: 0; padding: 0 ;}
Body, ul, li {
Margin: 0;
Padding: 0;
}
Body {
Font: 12px/1.5 Tahoma;
}
# Outer {
Width: pixel 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>
</Head>
<Body>
<Div id = "outer">
<Ul id = "tab">
<Li class = "current"> Lesson 1 </li>
<Li> Lesson 2 </li>
<Li> Lesson 3 </li>
</Ul>
<Div id = "content">
<Ul style = "display: block;">
1111
</Ul>
<Ul>
2222
</Ul>
<Ul>
3333
</Ul>
</Div>
</Div>
<Script src = "http://libs.baidu.com/jquery/1.9.0/jquery.js"> </script>
<Script>
$ (Function (){
Window. onload = function ()
{
Var $ li = $ ('# tab li ');
Var $ ul = $ ('# content ul ');
$ Li. click (function (){
$ Li. removeClass ();
Var $ t = $ (this). index ();
$ (This). addClass ('current ');
$Ul.css ('display', 'None ');
$Ul.eq(effect).css ('display', 'block ');
})
}
});
</Script>
</Body>
</Html>

 

Image Demo:

The above is all the content described in this article. I hope you will like it.

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.