JavaScript Common simple Table tab to implement _javascript techniques

Source: Internet
Author: User
The first step: quoting Table.js
Copy Code code as follows:
<script type= "Text/javascript" src= "Table.js" > </script>

Step Two: Define the selected style, such as "active", the ID of the block to which the tab is applied, such as "sidebar", the serial number that is selected by default, such as the first "0";
Step Three: Call the function:
Copy Code code as follows:
<script type= "Text/javascript" >
The parameters are: Default selection Application Block ID selected style
Table (0, "sidebar", "active")
</script>

All OK, the tab response click event, concurrently IE and FF, and so have time to optimize, the effect is as follows:

The HTML source code is as follows:
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>new Web project</title>
<script type= "Text/javascript" src= "Table.js" > </script>
<style type= "Text/css" >
. sidebar {
width:140px;
Background: #C9E4D6;
min-height:600px;
Float:left;
Border-left:solid 1px #C8C8C8;
}
. Sidebar ul {
List-style:none;
Text-align:left;
padding:20px 0px 0px 0px;
}
. Sidebar ul li {
border-bottom:1px dotted #C8C8C8;
font-size:14px;
height:30px;
line-height:30px;
padding-left:15px;
margin-left:15px;
Cursor:pointer;
}
. Sidebar. Active {
Background: #fff;
}
</style>
<body>
<div class= "sidebar" id= "sidebar" >
<ul>
<li>
Option One
</li>
<li>
Option two
</li>
<li>
Option three
</li>
<li>
Option Four
</li>
<li>
Option Five
</li>
</ul>
</div>
</body>
<script type= "Text/javascript" >
The parameters are: Default selection Application Block ID selected style
Table (0, "sidebar", "active")
</script>

Table.js
Copy Code code as follows:

/**
* @author Sky
*/
var table=function (index,id,active)
{
Table=new Table (index,id,active);
Table.bind ();
}
var table=function (index,id,active)
{
This.index=parseint (index);
This.arr=document.getelementbyid (ID). getElementsByTagName ("Li");
this.active=active;
}
table.prototype={
Bind:function ()
{
this.arr[this.index].classname=this.active;//initialization
var _self=this;
for (var i = 0; i < this.arr.length; i++)
{
This.arr[i].setattribute ("ext", i);
This.arr[i].onclick = function (e)
{
var _e = window.event| | E
var _target=_e.srcelement | | _e.target;
_self.setclass (parseint (_target.getattribute ("ext"));
}
}
},
Setclass:function (Index)
{
This.arr[this.index].classname= "";
this.arr[index].classname=this.active;
This.index=index;
}
}

Demo download
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.