if
(
typeof
(ocellus)
==
"
undefined
"
)
...
{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
_o = ocellus = ...{};
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
if
(
typeof
(_o.autoChange)
==
"
undefined
"
)
...
{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
_o.autoChange = ...{};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
}
else
...
{
alert("AutoChange is already set!");
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
_o.autoChange
=
function
(tbodyID, changeOptions)
...
{
this.tablebody = _o.DOM.gE(tbodyID);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if (!this.tablebody) ...{
return 0;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
this.oP = changeOptions ? changeOptions : ...{};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
var k, def = ...{oddClass:"autoChangeOdd",evenClass:"autoChangeEven", overClass:"autoChangeOver"};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
for (k in def) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if (typeof (this.oP[k]) != typeof (def[k])) ...{
this.oP[k] = def[k];
}
}
var p = this;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
for (var i=0;i<this.tablebody.rows.length ;i++ )...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if (typeof (this.oP.clickListener) == "function") ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
this.tablebody.rows[i].onclick=function()...{
p.oP.clickListener(this.rowIndex,this);
}
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if (this.tablebody.rows[i].rowIndex%2==1)...{
this.tablebody.rows[i].className=this.oP.oddClass;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
this.tablebody.rows[i].onmouseover=function ()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if(this.className && (this.className.indexOf(p.oP.oddClass)>=0))...{
this.className = this.className.replace(p.oP.oddClass, p.oP.overClass);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
}else...{
this.className = p.oP.overClass;
}
};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
this.tablebody.rows[i].onmouseout=function ()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if(this.className && (this.className.indexOf(p.oP.overClass)>=0))...{
this.className = this.className.replace(p.oP.overClass, p.oP.oddClass);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
}else...{
this.className = p.oP.oddClass;
}
};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
}else...{
this.tablebody.rows[i].className=this.oP.evenClass;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
this.tablebody.rows[i].onmouseover=function ()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if(this.className && (this.className.indexOf(p.oP.evenClass)>=0))...{
this.className = this.className.replace(p.oP.evenClass, p.oP.overClass);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
}else...{
this.className = p.oP.overClass;
}
};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
this.tablebody.rows[i].onmouseout=function ()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if(this.className && (this.className.indexOf(p.oP.overClass)>=0))...{
this.className = this.className.replace(p.oP.overClass, p.oP.evenClass);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
}else...{
this.className = p.oP.evenClass;
}
};
}
}
}
;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
_o.autoChange.onMouseOver
=
function
(obj, specialClassName)
...
{
obj.className = specialClassName;
}
;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
_o.autoChange.onMouseOut
=
function
(obj, normalClassName)
...
{
obj.className = normalClassName;
}
;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
if
(
typeof
(_o.DOM)
==
"
undefined
"
)
...
{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
_o.DOM = ...{};
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
_o.DOM.gE
=
function
(e)
...
{
var t = typeof (e);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if (t == "undefined") ...{
return 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
} else ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if (t == "string") ...{
var a = document.getElementById(e);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if (!a) ...{
return 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
} else ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if (typeof (a.appendChild) != "undefined") ...{
return a;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
} else ...{
return 0;
}
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
} else ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if (typeof (e.appendChild) != "undefined") ...{
return e;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
} else ...{
return 0;
}
}
}
}
;
在使用时主要有三步,首先要应用隔行变色的tbody必须有id,其次要定义一个用来设置的数组
var
as_options
=
...
{
oddClass:"autoChangeOdd",
evenClass:"autoChangeEven",
overClass:"autoChangeOver",
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
clickListener: function (rowIndex, theRow) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if(theRow.className && (theRow.className.indexOf(' autoChecked1')>=0))...{
theRow.className = theRow.className.substring(0,theRow.className.length-12);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
}else...{
theRow.className = theRow.className + ' autoChecked1';
}
}
}
其中clickListener只能是一个方法,否则会忽略
最后调用AutoChange
var
as_change
=
new
ocellus.autoChange(
'
goaler1
'
, as_options);
下面是测试用的网页
<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
>
<
html
>
<
head
>
<
title
>
New Document
</
title
>
<
meta
name
="Generator"
content
="EditPlus"
>
<
meta
name
="Author"
content
=""
>
<
meta
name
="Keywords"
content
=""
>
<
meta
name
="Description"
content
=""
>
<
script
language
="JavaScript"
type
="text/javascript"
src
="ocl_autochang.js"
></
script
>
<
link
rel
="stylesheet"
href
="ocl_autochang.css"
type
="text/css"
media
="screen"
charset
="utf-8"
/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</
head
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<
body
>
<
table
width
="800"
border
="0"
cellpadding
="0"
cellspacing
="0"
>
<
tbody
id
="goaler1"
>
<
tr
>
<
td
>
xxxxxxxx
</
td
>
</
tr
>
<
tr
>
<
td
>
xxxxxxxx
</
td
>
</
tr
>
<
tr
>
<
td
>
xxxxxxxx
</
td
>
</
tr
>
<
tr
>
<
td
>
xxxxxxxx
</
td
>
</
tr
>
</
tbody
>
</
table
>
<
br
><
br
><
br
><
br
><
br
>
<
table
width
="800"
border
="0"
cellpadding
="0"
cellspacing
="0"
>
<
tbody
id
="goaler2"
>
<
tr
>
<
td
>
xxxxxxxx
</
td
>
</
tr
>
<
tr
>
<
td
>
xxxxxxxx
</
td
>
</
tr
>
<
tr
>
<
td
>
xxxxxxxx
</
td
>
</
tr
>
<
tr
>
<
td
>
xxxxxxxx
</
td
>
</
tr
>
</
tbody
>
</
table
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
<
script
language
="JavaScript"
>
...
<!--
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
var as_options = ...{
oddClass:"autoChangeOdd",
evenClass:"autoChangeEven",
overClass:"autoChangeOver",
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
clickListener: function (rowIndex, theRow) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if(theRow.className && (theRow.className.indexOf(' autoChecked1')>=0))...{
theRow.className = theRow.className.substring(0,theRow.className.length-12);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
}else...{
theRow.className = theRow.className + ' autoChecked1';
}
}
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var as_change = new ocellus.autoChange('goaler1', as_options);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
var as_options2 = ...{
oddClass:"autoChangeEven",
evenClass:"autoChangeOdd",
overClass:"autoChangeOver",
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
clickListener: function (rowIndex, theRow) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if(theRow.className && (theRow.className.indexOf(' autoChecked2')>=0))...{
theRow.className = theRow.className.substring(0,theRow.className.length-12);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
}else...{
theRow.className = theRow.className + ' autoChecked2';
}
}
}
var as_change = new ocellus.autoChange('goaler2', as_options2);
//-->
</
script
>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</
body
>
</
html
>
.autoChangeOdd
{...}
{
background-color: #F0F0FF;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
.autoChangeEven
{...}
{
background-color: #F9F9FF;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
.autoChangeOver
{...}
{
background-color: #E0E0FF;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
.autoChecked1
{...}
{
color: #FF0000;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
.autoChecked2
{...}
{
color: #00FF00;
}