<style>
table tr
{
background-color:expression(this.rowIndex%2==0 ? "#ffffff" : "#c0c0c0");
}
</style>
<script>
var oldTd,oldTdText;
window.onload=function(){
var table1 = document.getElementById("table1");
var rows = table1.rows;
for(i=0; i<rows.length; i++)
{
rows[i].cells[0].onmouseover=function(){
if(oldTd)
{
oldTd.innerHTML=oldTdText;
}
oldTd=this;
oldTdText=this.innerHTML;
this.innerHTML="<font style='background-color:red'>"+this.innerHTML+"</font>";
};
}
}
</script>
</head>
<table id="table1" width="300" border="1" cellpadding="0" cellspacing="0" align="center" >
<tr>
<td>Line1Line1Line1Line1</td>
</tr>
<tr>
<td>Line2Line2Line2Line2</td>
</tr>
<tr>
<td>Line3Line3Line3Line3</td>
</tr>
<tr>
<td>Line4Line4Line4Line4</td>
</tr>
<tr>
<td>Line5Line5Line5Line5</td>
</tr>
</table>
table tr
{
background-color:expression(this.rowIndex%2==0 ? "#ffffff" : "#c0c0c0");
}
</style>
<script>
var oldTd,oldTdText;
window.onload=function(){
var table1 = document.getElementById("table1");
var rows = table1.rows;
for(i=0; i<rows.length; i++)
{
rows[i].cells[0].onmouseover=function(){
if(oldTd)
{
oldTd.innerHTML=oldTdText;
}
oldTd=this;
oldTdText=this.innerHTML;
this.innerHTML="<font style='background-color:red'>"+this.innerHTML+"</font>";
};
}
}
</script>
</head>
<table id="table1" width="300" border="1" cellpadding="0" cellspacing="0" align="center" >
<tr>
<td>Line1Line1Line1Line1</td>
</tr>
<tr>
<td>Line2Line2Line2Line2</td>
</tr>
<tr>
<td>Line3Line3Line3Line3</td>
</tr>
<tr>
<td>Line4Line4Line4Line4</td>
</tr>
<tr>
<td>Line5Line5Line5Line5</td>
</tr>
</table>
expression的性能比较差的吗!看来传说的也不对啊!测了下感觉比JS好点!汗一个
$(document).ready(function(){
$(".stripe tr").mouseover(function(){
$(this).addClass("样式表名");}).mouseout(function(){
$(this).removeClass("样式表名");})
$(".table class tr:even").addClass("偶数行样式表名");
});
</script>
<title>隔行换色_选中高亮</title>
<style>
td{width:200px;padding-left:20px;}
a{color:#00f}
.tdover{background:#ff0}
.tdover a{color:#fff;background:#f00}
</style>
<script>
window.onload=function(){
var table1 = document.getElementById("table1");
var rows = table1.rows;
for(i=0; i<rows.length; i++){
rows[i].style.backgroundColor=(i%2==0)?"#fff" : "#eee"
rows[i].cells[0].onmouseover=function(){
this.name=this.style.backgroundColor;
this.className="tdover";
}
rows[i].cells[0].onmouseout=function(){
this.style.backgroundColor=this.name;
this.name="";
this.className="";
}
}}
</script>
</head>
<table id="table1" width="300" border="1" cellpadding="0" cellspacing="0">
<tr>
<td><a href="###">选中高亮</a></td><td>隔行换色</td></tr>
<tr>
<td><a href="###">选中高亮</a></td><td>隔行换色</td></tr>
<tr>
<td><a href="###">选中高亮</a></td><td>隔行换色</td></tr>
<tr>
<td><a href="###">选中高亮</a></td><td>隔行换色</td></tr>
</table>