A practical reference to JavaScript oop editing ideas

Source: Internet
Author: User

. 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

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.