function switchmodTag(){ } switchmodTag.prototype = { st : function(menus,divs,openClass,closeClass){ var _this = this; if(menus.length != divs.length) { alert("菜单层和内容层数目不一样!"); return false; } for(var i = 0 ; i < menus.length ; i++) { _this.$(menus[i]).value = i; _this.$(menus[i]).onmouseover = function(){//此行onmouseover 可以改成onclick。 for(var j = 0 ; j < menus.length ; j++) { _this.$(menus[j]).className = closeClass; _this.$(divs[j]).style.display = "none"; } _this.$(menus[this.value]).className = openClass; _this.$(divs[this.value]).style.display = "block"; } } }, $ : function(oid){ if(typeof(oid) == "string") return document.getElementById(oid); return oid; } } window.onload = function(){ var STmodel = new switchmodTag(); STmodel.st(["a_1","a_2"],["c1_1","c1_2"],"st01","st02");//第一组动滑轮 STmodel.st(["d_1","d_2"],["c4_1","c4_2"],"st01","st02");//第四组动滑轮 //如需增加个数,请复制代码,ID命名规则如上即可。 }