. Current {background-color:red;}. DV {background-color:green; width:200px; height:200px;}</style>/********* Whether the query node contains a style *******/varHasclass =function(tag, clsname) {vararr = Tag.className.split (/\s+/); for(vari = 0; i < arr.length; i++) { if(Arr[i] = =clsname) { return true; } }; return false;}/********* extended getelementsbyclassname function (compatible with IE low version) *********/if(!document.getelementsbyclassname) {document.getelementsbyclassname=function(CLS) {varNodearr = []; varnodes = document.getElementsByTagName (' * ')); if(Nodes && nodes.length > 0) { for(vari = 0; i < nodes.length; i++) { if(Hasclass (Nodes[i], CLS)) {Nodearr.push (nodes[i]); } }; } returnNodearr; }}varChangetab =function(option) {//body ... This. Init.apply ( This, arguments);} Changetab.prototype= { /*initialization of the ******* parameter ********/Init:function() { vararr =Array.prototype.slice.call (arguments); This. option = Arr[0] | |{inittab:0,//Set the selected tab indextab: ",//Tab's classnameTabclass: ",//Style after tab-clickContainer: "//Div's classname }; }, /************* function Execution **************/Render:function() { ///Get tab and div to manipulate This. Tabs = Document.getelementsbyclassname ( This. Option.tab); This. Contents = Document.getelementsbyclassname ( This. Option.container); if( This. Tabs.length = = 0 | | This. Contents.length = = 0) { return; } if( This. tabs.length! = This. Contents.length) { return; } varthat = This;///Because the closure needs to use the parameters of this function, the scope is inconsistent, so point to the current function ////Set tab and DIV content for initial display This. contents[ This. Option.inittab].style.display = ' block '; This. tabs[ This. Option.inittab].classname = That.option.tab + "+That.option.tabclass; for(vari = 0; I < This. tabs.length; i++) { //// Closed bag(function(num) {That.tabs[num].onclick=function() { for(vark = 0; K < That.contents.length; k++) { ///Hide All div and remove all tab stylesThat.contents[k].style.display = ' None '; That.tabs[k].classname=That.option.tab; }; ///Display and set tab and DIV content for the current click This. ClassName = That.option.tab + "+That.option.tabclass; That.contents[num].style.display= ' Block '; }}) (i); } }, /************* function extension function **************/Extend:function(obj) {if(obj && Object.prototype.toString.call (obj) = = "[Object Object]") { for(Propinchobj) { This[Prop] =Obj[prop]; }}}}window.onload=function() {//body ... vartb=NewChangetab ({inittab:0, tab: ' SP ', Tabclass: ' Current ', container: ' DV ') }); Tb.render (); }</script>A practical reference to JavaScript oop editing ideas