为了不重复_nav

//企业站的一级目录,二级目录的焦点,

页面的命名:aboutus.php ; aboutus_tissue.php ; aboutus_partners.php ; aboutus_culture.php

var navaddNow = Class.create();
navaddNow.prototype = {
    initialize: function(id,a){
    if(document.getElementById(id)){
        this.nowA = document.getElementById(id).getElementsByTagName("a");
        this.choseOne(a);
        }
    },
    getmenuNow: function(){
        var url = location.href.split("/");
        var rex = /[a-z]+/;
        var res = url[url.length-1].match(rex).toString();
        for(var i=0; i<this.nowA.length; i++){
            var a = this.nowA[i].href.split("/");
            var c = a[url.length-1].match(rex).toString();
            if(c == res){
                this.nowA[i].className = "now";
                return;
                }
            }
    },
    getnavNow: function(){
        var url = location.href.split("/");
        var urlx = url[url.length-1].split(".")[0];
        var num;
        for(var i in this.setnum){
            if(urlx==i) num = this.setnum[i];
            }
        this.nowA[num].className = "now";
    },
    setnum: {
        "aboutus"                  :0,
        "aboutus_tissue"       :1,
        "aboutus_partners"      :2,
        "aboutus_culture"      :3
        },
    choseOne: function(x){
        switch(x){
            case "1" : this.getmenuNow(); break;
            case "2" : this.getnavNow(); break;
            }
        }
}
new navaddNow("nav","2");

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