第1个回答 推荐于2016-05-17
解压并对部分函数做了解释
/* ========== 舌签构造函数 begin ========== */
var isIE = navigator.appVersion.indexOf("MSIE") != -1 ? true: false;
function SubShowClass(h, j, k, l, m) {//主函数 h-舌簧的id名程;j-设置响应类型:有五种状态响应onmouseover、onmouseout、click、mouseup、mousedown;k、l、m-默认选中容器(div)的索引序号、默认选中、关闭容器id名称;注意k、l、m都是相对于舌簧tab(h)的子容器
this.version = "1.0";
this.author = "mengjia";
this.parentObj = SubShowClass.$(h);//取得舌簧id
if (this.parentObj == null) {
throw new Error("SubShowClass(ID)参数错误:ID 对像存在!")
};
if (!SubShowClass.childs) {
SubShowClass.childs = new Array()//以下将需开关显示的容器名(div)取得并压入js数组
};
this.ID = SubShowClass.childs.length;
SubShowClass.childs.push(this);
this.lock = false;//以下设置状态参数值
this.label = [];
this.defaultID = k == null ? 0: k;
this.selectedIndex = this.defaultID;
this.openClassName = l == null ? "selected": l;
this.closeClassName = m == null ? "": m;
this.mouseIn = false;
var n = Function("SubShowClass.childs[" + this.ID + "].mouseIn = true");
var o = Function("SubShowClass.childs[" + this.ID + "].mouseIn = false");
if (isIE) {
this.parentObj.attachEvent("onmouseover", n)
} else {
this.parentObj.addEventListener("mouseover", n, false)
};
if (isIE) {
this.parentObj.attachEvent("onmouseout", o)
} else {
this.parentObj.addEventListener("mouseout", o, false)
};
if (typeof(j) != "string") {//以下设置舌簧鼠标响应类型
j = "onmousedown"
};
j = j.toLowerCase();
switch (j) {
case "onmouseover":
this.eventType = "mouseover";
break;
case "onmouseout":
this.eventType = "mouseout";
break;
case "onclick":
this.eventType = "click";
break;
case "onmouseup":
this.eventType = "mouseup";
break;
default:
this.eventType = "mousedown"
};
this.addLabel = function(a, b, c, d, e) {//该函数根据取得的状态显示或关闭子容器并设置tab背景样式(c参数)
if (SubShowClass.$(a) == null) {
throw new Error("addLabel(labelID)参数错误:labelID 对像存在!")
};
var f = this.label.length;
if (c == "") {
c = null
};
this.label.push([a, b, c, d, e]);
var g = Function('SubShowClass.childs[' + this.ID + '].select(' + f + ')');
if (isIE) {
SubShowClass.$(a).attachEvent("on" + this.eventType, g)
} else {
SubShowClass.$(a).addEventListener(this.eventType, g, false)
};
if (f == this.defaultID) {
SubShowClass.$(a).className = this.openClassName;
if (SubShowClass.$(b)) {
SubShowClass.$(b).style.display = ""
};
if (c != null) {
this.parentObj.style.background = c
};
if (d != null) {
eval(d)
}
} else {
SubShowClass.$(a).className = this.closeClassName;
if (SubShowClass.$(b)) {
SubShowClass.$(b).style.display = "none"
}
};
if (SubShowClass.$(b)) {
if (isIE) {
SubShowClass.$(b).attachEvent("onmouseover", n)
} else {
SubShowClass.$(b).addEventListener("mouseover", n, false)
};
if (isIE) {
SubShowClass.$(b).attachEvent("onmouseout", o)
} else {
SubShowClass.$(b).addEventListener("mouseout", o, false)
}
}
};
this.select = function(a) {//调用函数具体设置选中tab状态或样式
if (typeof(a) != "number") {
throw new Error("select(num)参数错误:num 不是 number 类型!")
};
var i;
for (i = 0; i < this.label.length; i++) {
if (i == a) {
SubShowClass.$(this.label[i][0]).className = this.openClassName;
if (SubShowClass.$(this.label[i][1])) {
SubShowClass.$(this.label[i][1]).style.display = ""
};
if (this.label[i][2] != null) {
this.parentObj.style.background = this.label[i][2]
};
if (this.label[i][3] != null) {
eval(this.label[i][3])
}
} else if (this.selectedIndex == i) {
SubShowClass.$(this.label[i][0]).className = this.closeClassName;
if (SubShowClass.$(this.label[i][1])) {
SubShowClass.$(this.label[i][1]).style.display = "none"
};
if (this.label[i][4] != null) {
eval(this.label[i][4])
}
}
};
this.selectedIndex = a
};
this.random = function() {
if (arguments.length != this.label.length) {
throw new Error("random()参数错误:参数数量与标签数量不符!")
};
var a = 0,
i;
for (i = 0; i < arguments.length; i++) {
a += arguments[i]
};
var b = Math.random(),
percent = 0;
for (i = 0; i < arguments.length; i++) {
percent += arguments[i] / a;
if (b < percent) {
this.select(i);
break
}
}
};
this.autoPlay = false;
var p = null;
this.spaceTime = 5000;
this.play = function(a) {
if (typeof(a) == "number") {
this.spaceTime = a
};
clearInterval(p);
p = setInterval("SubShowClass.childs[" + this.ID + "].nextLabel()", this.spaceTime);
this.autoPlay = true
};
this.nextLabel = function() {
if (this.autoPlay == false || this.mouseIn == true) {
return
};
var a = this.selectedIndex;
a++;
if (a >= this.label.length) {
a = 0
};
this.select(a)
};
this.stop = function() {
clearInterval(p);
this.autoPlay = false
}
};
SubShowClass.$ = function(a) {//取得tab h的超链接
if (document.getElementById) {
return eval('document.getElementById("' + a + '")')
} else {
return eval('document.all.' + a)
}
}
/* ========== 舌签构造函数 end ========== */本回答被提问者采纳
第2个回答 2011-02-28
function SubShowClass(h,j,k,l,m){
this.version="1.21";
this.author="mengjia";
this.parentObj=SubShowClass.$(h);
if(this.parentObj==null&&h!="none"){
throw new Error("SubShowClass(ID)\u53c2\u6570\u9519\u8bef:ID \u5bf9\u50cf\u5b58\u5728!(value:"+h+")");
}
if(!SubShowClass.childs){
SubShowClass.childs=[];
}
this.ID=SubShowClass.childs.length;
SubShowClass.childs.push(this);
this.lock=false;
this.label=[];
this.defaultID=k==null?0:k;
this.selectedIndex=this.defaultID;
this.openClassName=l==null?"selected":l;
this.closeClassName=m==null?"":m;
this.mouseIn=false;
var n=Function("SubShowClass.childs["+this.ID+"].mouseIn = true"),mouseOutFunc=Function("SubShowClass.childs["+this.ID+"].mouseIn = false");
if(h!="none"){
if(this.parentObj.attachEvent){
this.parentObj.attachEvent("onmouseover",n);
}else {
this.parentObj.addEventListener("mouseover",n,false);
}
}
if(h!="none"){
if(this.parentObj.attachEvent){
this.parentObj.attachEvent("onmouseout",mouseOutFunc);
}else {
this.parentObj.addEventListener("mouseout",mouseOutFunc,false);
}
}
if(typeof (j)!="string"){
j="onmousedown";
}
j=j.toLowerCase();
switch(j){
case "onmouseover":
this.eventType="mouseover";
break ;
case "onmouseout":
this.eventType="mouseout";
break ;
case "onclick":
this.eventType="click";
break ;
case "onmouseup":
this.eventType="mouseup";
break ;
default:
this.eventType="mousedown";
}
this.addLabel=function(a,b,c,d,e){
if(SubShowClass.$(a)==null&&a!="none"){
throw new Error("addLabel(labelID)\u53c2\u6570\u9519\u8bef:labelID \u5bf9\u50cf\u5b58\u5728!(value:"+a+")");
}
var f=this.label.length;
if(c==""){
c=null;
}
this.label.push([a,b,c,d,e]);
var g=Function("SubShowClass.childs["+this.ID+"].select("+f+")");
if(a!="none"){
if(SubShowClass.$(a).attachEvent){
SubShowClass.$(a).attachEvent("on"+this.eventType,g);
}else {
SubShowClass.$(a).addEventListener(this.eventType,g,false);
}
}
if(f==this.defaultID){
if(a!="none"){
SubShowClass.$(a).className=this.openClassName;
}
if(SubShowClass.$(b)){
SubShowClass.$(b).style.display="";
}
if(h!="none"){
if(c!=null){
this.parentObj.style.background=c;
}
}
if(d!=null){
eval(d);
}
}else {
if(a!="none"){
SubShowClass.$(a).className=this.closeClassName;
}
if(SubShowClass.$(b)){
SubShowClass.$(b).style.display="none";
}
}
if(SubShowClass.$(b)){
if(SubShowClass.$(b).attachEvent){
SubShowClass.$(b).attachEvent("onmouseover",n);
}else {
SubShowClass.$(b).addEventListener("mouseover",n,false);
}
if(SubShowClass.$(b).attachEvent){
SubShowClass.$(b).attachEvent("onmouseout",mouseOutFunc);
}else {
SubShowClass.$(b).addEventListener("mouseout",mouseOutFunc,false);
}
}
};
this.select=function(a,b){
if(typeof (a)!="number"){
throw new Error("select(num)\u53c2\u6570\u9519\u8bef:num \u4e0d\u662f number \u7c7b\u578b!(value:"+a+")");
}
if(b!=true&&this.selectedIndex==a){
return ;
}
var i;
for(i=0;i<this.label.length;i++){
if(i==a){
if(this.label[i][0]!="none"){
SubShowClass.$(this.label[i][0]).className=this.openClassName;
}
if(SubShowClass.$(this.label[i][1])){
SubShowClass.$(this.label[i][1]).style.display="";
}
if(h!="none"){
if(this.label[i][2]!=null){
this.parentObj.style.background=this.label[i][2];
}
}
if(this.label[i][3]!=null){
eval(this.label[i][3]);
}
}else {
if(this.selectedIndex==i||b==true){
if(this.label[i][0]!="none"){
SubShowClass.$(this.label[i][0]).className=this.closeClassName;
}
if(SubShowClass.$(this.label[i][1])){
SubShowClass.$(this.label[i][1]).style.display="none";
}
if(this.label[i][4]!=null){
eval(this.label[i][4]);
}
}
}
}
this.selectedIndex=a;
};
this.random=function(){
if(arguments.length!=this.label.length){
throw new Error("random()\u53c2\u6570\u9519\u8bef:\u53c2\u6570\u6570\u91cf\u4e0e\u6807\u7b7e\u6570\u91cf\u4e0d\u7b26!(length:"+arguments.length+")");
}
var a=0,i;
for(i=0;i<arguments.length;i++){
a+=arguments[i];
}
var b=Math.random(),percent=0;
for(i=0;i<arguments.length;i++){
percent+=arguments[i]/a;
if(b<percent){
this.select(i);
break ;
}
}
};
this.autoPlay=false;
var o=null;
this.spaceTime=5000;
this.play=function(a){
if(typeof (a)=="number"){
this.spaceTime=a;
}
clearInterval(o);
o=setInterval("SubShowClass.childs["+this.ID+"].autoPlayFunc()",this.spaceTime);
this.autoPlay=true;
};
this.autoPlayFunc=function(){
if(this.autoPlay==false||this.mouseIn==true){
return ;
}
this.nextLabel();
};
this.nextLabel=function(){
var a=this.selectedIndex;
a++;
if(a>=this.label.length){
a=0;
}
this.select(a);
if(this.autoPlay==true){
clearInterval(o);
o=setInterval("SubShowClass.childs["+this.ID+"].autoPlayFunc()",this.spaceTime);
}
};
this.previousLabel=function(){
var a=this.selectedIndex;
a--;
if(a<0){
a=this.label.length-1;
}
this.select(a);
if(this.autoPlay==true){
clearInterval(o);
o=setInterval("SubShowClass.childs["+this.ID+"].autoPlayFunc()",this.spaceTime);
}
};
this.stop=function(){
clearInterval(o);
this.autoPlay=false;
};
}
SubShowClass.$=function(a){
if(document.getElementById){
return eval("document.getElementById(\""+a+"\")");
}else {
return eval("document.all."+a);
}
};
第3个回答 2011-02-28
/* ========== 舌签构造函数 begin ========== */
var isIE = navigator.appVersion.indexOf("MSIE") != -1 ? true: false;
function SubShowClass(h, j, k, l, m) {
this.version = "1.0";
this.author = "mengjia";
this.parentObj = SubShowClass.$(h);
if (this.parentObj == null) {
throw new Error("SubShowClass(ID)参数错误:ID 对像存在!")
};
if (!SubShowClass.childs) {
SubShowClass.childs = new Array()
};
this.ID = SubShowClass.childs.length;
SubShowClass.childs.push(this);
this.lock = false;
this.label = [];
this.defaultID = k == null ? 0 : k;
this.selectedIndex = this.defaultID;
this.openClassName = l == null ? "selected": l;
this.closeClassName = m == null ? "": m;
this.mouseIn = false;
var n = Function("SubShowClass.childs[" + this.ID + "].mouseIn = true");
var o = Function("SubShowClass.childs[" + this.ID + "].mouseIn = false");
if (isIE) {
this.parentObj.attachEvent("onmouseover", n)
} else {
this.parentObj.addEventListener("mouseover", n, false)
};
if (isIE) {
this.parentObj.attachEvent("onmouseout", o)
} else {
this.parentObj.addEventListener("mouseout", o, false)
};
if (typeof(j) != "string") {
j = "onmousedown"
};
j = j.toLowerCase();
switch (j) {
case "onmouseover":
this.eventType = "mouseover";
break;
case "onmouseout":
this.eventType = "mouseout";
break;
case "onclick":
this.eventType = "click";
break;
case "onmouseup":
this.eventType = "mouseup";
break;
default:
this.eventType = "mousedown"
};
this.addLabel = function(a, b, c, d, e) {
if (SubShowClass.$(a) == null) {
throw new Error("addLabel(labelID)参数错误:labelID 对像存在!")
};
var f = this.label.length;
if (c == "") {
c = null
};
this.label.push([a, b, c, d, e]);
var g = Function('SubShowClass.childs[' + this.ID + '].select(' + f + ')');
if (isIE) {
SubShowClass.$(a).attachEvent("on" + this.eventType, g)
} else {
SubShowClass.$(a).addEventListener(this.eventType, g, false)
};
if (f == this.defaultID) {
SubShowClass.$(a).className = this.openClassName;
if (SubShowClass.$(b)) {
SubShowClass.$(b).style.display = ""
};
if (c != null) {
this.parentObj.style.background = c
};
if (d != null) {
eval(d)
}
} else {
SubShowClass.$(a).className = this.closeClassName;
if (SubShowClass.$(b)) {
SubShowClass.$(b).style.display = "none"
}
};
if (SubShowClass.$(b)) {
if (isIE) {
SubShowClass.$(b).attachEvent("onmouseover", n)
} else {
SubShowClass.$(b).addEventListener("mouseover", n, false)
};
if (isIE) {
SubShowClass.$(b).attachEvent("onmouseout", o)
} else {
SubShowClass.$(b).addEventListener("mouseout", o, false)
}
}
};
this.select = function(a) {
if (typeof(a) != "number") {
throw new Error("select(num)参数错误:num 不是 number 类型!")
};
var i;
for (i = 0; i < this.label.length; i++) {
if (i == a) {
SubShowClass.$(this.label[i][0]).className = this.openClassName;
if (SubShowClass.$(this.label[i][1])) {
SubShowClass.$(this.label[i][1]).style.display = ""
};
if (this.label[i][2] != null) {
this.parentObj.style.background = this.label[i][2]
};
if (this.label[i][3] != null) {
eval(this.label[i][3])
}
} else if (this.selectedIndex == i) {
SubShowClass.$(this.label[i][0]).className = this.closeClassName;
if (SubShowClass.$(this.label[i][1])) {
SubShowClass.$(this.label[i][1]).style.display = "none"
};
if (this.label[i][4] != null) {
eval(this.label[i][4])
}
}
};
this.selectedIndex = a
};
this.random = function() {
if (arguments.length != this.label.length) {
throw new Error("random()参数错误:参数数量与标签数量不符!")
};
var a = 0,
i;
for (i = 0; i < arguments.length; i++) {
a += arguments[i]
};
var b = Math.random(),
percent = 0;
for (i = 0; i < arguments.length; i++) {
percent += arguments[i] / a;
if (b < percent) {
this.select(i);
break
}
}
};
this.autoPlay = false;
var p = null;
this.spaceTime = 5000;
this.play = function(a) {
if (typeof(a) == "number") {
this.spaceTime = a
};
clearInterval(p);
p = setInterval("SubShowClass.childs[" + this.ID + "].nextLabel()", this.spaceTime);
this.autoPlay = true
};
this.nextLabel = function() {
if (this.autoPlay == false || this.mouseIn == true) {
return
};
var a = this.selectedIndex;
a++;
if (a >= this.label.length) {
a = 0
};
this.select(a)
};
this.stop = function() {
clearInterval(p);
this.autoPlay = false
}
};
SubShowClass.$ = function(a) {
if (document.getElementById) {
return eval('document.getElementById("' + a + '")')
} else {
return eval('document.all.' + a)
}
}
/* ========== 舌签构造函数 end ========== */