鼠标移至表格中某一行时,此行高亮显示。用Javascript实现的。ASP.NET和JAVA平台都能使用,比较方便。试验了半天。如下代码:
<html>
<head>
<title>鼠标移至表格中某一行时,此行高亮显示</title>
</head>
<body>
<table id="tb1">
<tr>
<td>a</td><td>b</td><td>c</td>
</tr>
<tr>
<td>a</td><td>b</td><td>c</td>
</tr>
<tr>
<td>a</td><td>b</td><td>c</td>
</tr>
<tr>
<td>a</td><td>b</td><td>c</td>
</tr>
<tr >
<td>a</td><td>b</td><td>c</td>
</tr>
</table>
<script>
var c;
var table1 = document.getElementById("tb1");
var rows =table1.getElementsByTagName('tr');
alert(rows.length);
for(var i=0;i<rows.length;i++)
{
var row = rows[i];
row. = function() {c=this.style.backgroundColor;this.style.backgroundColor='red';}
row. = function(){this.style.backgroundColor=c;}
}
</script>
</body>
</html>
可能有些朋友要用这种写法:
row.setAttribute("onMouseOver","c=this.style.backgroundColor;this.style.backgroundColor='red'");
但是微软的IE对DOM的setAttribute方法支持不好,用这种写法写了以后没效果,可能在FireFox和谷歌浏览器中会成功。我刚刚试验了半天。那个郁闷哦...还好最后查到用这种写法成功了。大家可以参考一下:
row. = function() {c=this.style.backgroundColor;this.style.backgroundColor='red';}
其中c这个变量时用来存放原始的backgroundColor,最后onmouseout的时候,要用c这个变量里面的值还原初始的backgroundColor。
转载:
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。