версия 0.2
Код:
<table id="zebra">
<tr OnMouseOver="OnMouseOverHandler(this)" onMouseOut="OnMouseOutHandler(this)"><td>123</td><td>456</td></tr>
<tr ><td>123</td><td>456</td></tr>
<tr OnMouseOver="OnMouseOverHandler(this)" onMouseOut="OnMouseOutHandler(this)"><td>123</td><td>456</td></tr>
<tr ><td>123</td><td>456</td></tr>
<tr OnMouseOver="OnMouseOverHandler(this)" onMouseOut="OnMouseOutHandler(this)"><td>123</td><td>456</td></tr>
</table>
<script>
function dozebra (id)
{
var table = document.getElementById(id);
if (table){
trs = table.getElementsByTagName('tr');
for (var i=0;i<trs.length;i++)
{
trs[i].style.backgroundColor = (i%2==0)?'eaeaea':'bbbbbb';
}
}
}
function Swap(obj)
{
if (obj != null && obj.tagName == "TR")
{
//alert(obj.style.backgroundColor);
if (obj.style.backgroundColor == '#eaeaea')
{
obj.style.backgroundColor = '#bbbbbb';
for(j=0;j<obj.children.length;j++)
{
if (obj.children[j].tagName == "TD")
{
obj.children[j].style.backgroundColor = '#bbbbbb';
}
}
}
else
{
obj.style.backgroundColor = '#eaeaea';
for(j=0;j<obj.children.length;j++)
{
if (obj.children[j].tagName == "TD")
{
obj.children[j].style.backgroundColor = '#eaeaea';
}
}
}
}
}
function OnMouseOverHandler(obj)
{
Swap(obj);
}
function OnMouseOutHandler(obj)
{
Swap(obj);
}
dozebra('zebra');
</script>