打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
“鼠标移至表格中某一行时,此行高亮显示”通用解决方案
鼠标移至表格中某一行时,此行高亮显示。用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。
 
转载:
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
使用JavaScript完成表格隔行换色
PHP登陆页面完整代码
5-CreateTable
jquery动态创建表格
CSS控制表格隔行变色与鼠标滑过变色
JQuery基本过滤选择器与表单对象过滤器
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服