js判断当前页是否与链接一致而现实不同css
Code
<script type="text/javascript">
function MemberFunctionMenu(id) {
var menus = [];
this.css = "";
this.activeItemCss = "";
this.addMenu = function(text, url, target) {
var o = new Object();
o.text = text;
o.url = url;
o.target = target;
menus[menus.length] = o;
}
this.render = function() {
var container = document.getElementById(id);
if (!container) {
document.write("<div id='" + id + "'></div>");
container = document.getElementById(id);
}
if (this.css && this.css != "") {
var oCss = container.getAttribute("class");
var css = (oCss && oCss != "") ? oCss + " " + this.css : this.css;
container.setAttribute("className", css);
container.setAttribute("class", css);
}
var ul = document.createElement("UL");
container.appendChild(ul);
for (var i = 0; i < menus.length; i++) {
var li = document.createElement("LI");
if (window.location.pathname.toString().toLowerCase() == menus[i].url.toLowerCase()) {
if (this.activeItemCss && this.activeItemCss != "") {
li.setAttribute("className", this.activeItemCss);
li.setAttribute("class", this.activeItemCss);
}
var span = document.createElement("SPAN");
span.innerHTML = menus[i].text;
li.appendChild(span);
}
else {
var a = document.createElement("A");
a.href = menus[i].url;
a.innerHTML = menus[i].text;
if (menus[i].target && menus[i].target != "")
a.target = menus[i].target;
li.appendChild(a);
}
ul.appendChild(li);
}
}
}
var menu10 = new MemberFunctionMenu("menu10");
menu10.css = "memberLeftMenu";
menu10.activeItemCss = "activeItem";
menu10.addMenu("网站基本设置", "/user/website.aspx");
menu10.render();
</script>
<script type="text/javascript">
function MemberFunctionMenu(id) {
var menus = [];
this.css = "";
this.activeItemCss = "";
this.addMenu = function(text, url, target) {
var o = new Object();
o.text = text;
o.url = url;
o.target = target;
menus[menus.length] = o;
}
this.render = function() {
var container = document.getElementById(id);
if (!container) {
document.write("<div id='" + id + "'></div>");
container = document.getElementById(id);
}
if (this.css && this.css != "") {
var oCss = container.getAttribute("class");
var css = (oCss && oCss != "") ? oCss + " " + this.css : this.css;
container.setAttribute("className", css);
container.setAttribute("class", css);
}
var ul = document.createElement("UL");
container.appendChild(ul);
for (var i = 0; i < menus.length; i++) {
var li = document.createElement("LI");
if (window.location.pathname.toString().toLowerCase() == menus[i].url.toLowerCase()) {
if (this.activeItemCss && this.activeItemCss != "") {
li.setAttribute("className", this.activeItemCss);
li.setAttribute("class", this.activeItemCss);
}
var span = document.createElement("SPAN");
span.innerHTML = menus[i].text;
li.appendChild(span);
}
else {
var a = document.createElement("A");
a.href = menus[i].url;
a.innerHTML = menus[i].text;
if (menus[i].target && menus[i].target != "")
a.target = menus[i].target;
li.appendChild(a);
}
ul.appendChild(li);
}
}
}
var menu10 = new MemberFunctionMenu("menu10");
menu10.css = "memberLeftMenu";
menu10.activeItemCss = "activeItem";
menu10.addMenu("网站基本设置", "/user/website.aspx");
menu10.render();
</script>