为了不重复_table

var Class = {   
      create: function() {   
        return function() {   
          this.initialize.apply(this, arguments);   
        }   
      }   
    }
var table = Class.create();
table.prototype = {
    initialize: function(a,b,c,d,e){
        if(document.getElementById(a) && document.getElementById(c)){
            this.b = document.getElementById(a).getElementsByTagName(b);
            this.d = document.getElementById(c).getElementsByTagName(d);
            this.e = e
            this.show();
            }
        },
    index: function(a,b){
        for(var i in b){
            if(a == b[i]){
            return i;
            }
        }
        },
    show: function(){
        var tli = this.b;
        var mli = this.d;
        var index = this.index;
        var cname = this.e;
        tli[0].className = cname;
        for(var z=0; z<mli.length; z++){
            mli[z].style.display = "none";
            }
        mli[0].style.display = "block";
        for(var i=0; i<tli.length; i++){
            tli[i].onclick = function(){
                for(var y=0; y<tli.length; y++){
                    tli[y].className = "";
                    mli[y].style.display = "none";
                    }
                this.className = cname;
                var x = index(this,tli);
                mli[x].style.display = "block";
                }
            }
        }
    }
new table("title","li","main","li","on");

原文地址:https://www.cnblogs.com/somesayss/p/2486865.html