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.