Return to the original, when the style is switched, control is returned to the page, that is, table.js only controls the switching style and recording operations: Copy code The code is as follows: New Web Project <br>.sidebar { <br>width: 140px; <br>background: #C9E4D6; <br>min-height: 600px; <br>float: left; <br>border-left: solid 1px #C8C8C8; <br>} <br>.sidebar ul { <br>list-style:none; <br>text-align: left; <br>padding: 20px 0px 0px 0px; <br>} <br>.sidebar ul li { <br>border-bottom: 1px dotted #C8C8C8; <br>font-size: 14px; <br>height: 30px; <br>line-height: 30px; <br>padding-left: 15px; <br>margin- left: 15px; <br>cursor: pointer; <br>} <br>.sidebar .active { <br>background: #fff; <br>} <br>.content{ <br>height:600px; <br>width:400px; <br>border-right:1px solid #ccc; <br>margin-left:140px; <br>padding:20px; <br>display:none; <br>} <br></ style> <br></head> <br><body> <br><div class="sidebar" id="sidebar"> <br><ul> <br><li point= "table1"> <br>Option one<br></li> <br><li point="table2"> <br>Option two<br></li> <br><li point="table3"> <br>Option three<br></li> <br><li point="table4"> <br>Option four<br></li> <br>< ;li point="table5"> <br>Option five<br></li> <br></ul> <br></div> <br><div id="table1" class ="content"> <br>This is the content of the first tab<br></div> <br><div id="table2" class="content"> <br>This is the content of the first tab The content of the two tabs<br></div> <br><div id="table3" class="content"> <br>This is the content of the third tab<br></ div> <br><div id="table4" class="content"> <br>This is the content of the fourth tab<br></div> <br><div id="table5 " class="content"> <br>This is the content of the fifth tab<br></div> <br></body> <br><script type="text/javascript" src ="table.js"> </script> <br><script type="text/javascript"> <br>//Available parameters for the callback function: obj.lastIndex (last option index) obj.index (Current option index) obj.arr (tab element array) <br>var back=function(obj) <br>{ <br>var lastPoint=obj.arr[obj.lastIndex].getAttribute("point"); <br>var curentPoint=obj.arr[obj.index].getAttribute("point"); <br>document.getElementById(lastPoint).style.display="none"; <br>document.getElementById(curentPoint). style.display="block"; <br>} <br>//The parameters are: option block ID selected style callback function default selection (starting with 0) <br>table("sidebar", "active",back ,0); <br></script> <br></html> <br> </div> <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="91670" class="copybut" id="copybut91670" onclick="doCopy('code91670')"><u>Copy code</u></a></span> The code is as follows: </div> <div class="codebody" id="code91670"> <br>//Available parameters for the callback function: obj.lastIndex (last option index) obj.index (current option index) obj.arr (tab element array) <br> var back=function(obj) <br>{ <br>var lastPoint=obj.arr[obj.lastIndex].getAttribute("point"); <br>var curentPoint=obj.arr[obj.index].getAttribute( "point"); <br>document.getElementById(lastPoint).style.display="none"; <br>document.getElementById(curentPoint).style.display="block"; <br>} <br>// The parameters are: option block ID selected style callback function default selection (starting with 0) <br>table("sidebar", "active",back,0); <br> </div> <br>table.js code As follows: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="69644" class="copybut" id="copybut69644" onclick="doCopy('code69644')"><u>Copy code</u></a></span> The code is as follows:</div> <div class="codebody" id="code69644"> <br>/**<br>* @author Sky <br>*/ <br>var table=function(id,active,callBack,index) <br>{ <br>table[id]=new Table(id,active,callBack,index); <br>table[id].bind(); <br>} <br>var Table=function(id,active,callBack,index) <br>{ <br>this.index=parseInt(index)||0;//当前索引 <br>this.lastIndex=this.index;//上次索引 <br>this.callBack=callBack||function(){}; <br>this.active=active||"active"; <br>this.id=id; <br>this.arr=document.getElementById(id).getElementsByTagName("li"); <br>} <br>Table.prototype={ <br>bind:function() <br>{ <br>//初始化选项样式 <br>this.setTable(this.index); <br>//绑定事件 <br>var _self=this; <br>for (var i = 0; i < this.arr.length; i ) <br>{ <br>this.arr[i].setAttribute("extatt", i);//钩子 <br>this.arr[i].onclick = function(e) <br>{ <br>var _e = window.event||e; <br>var _target=_e.srcElement || _e.target; <br>_self.setTable(parseInt(_target.getAttribute("extatt"))); <br>} <br>} <br>}, <br>setTable:function(index) <br>{ <br>this.lastIndex=this.index; <br>this.index=index; <br>//清除之前选项的样式 <br>this.arr[this.lastIndex].className=""; <br>//激活当前选项的样式 <br>this.arr[this.index].className=this.active; <br>//执行回调函数 <br>this.callBack(table[this.id]); <br>} <br>} <br> </div>