前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >一种实用的表格行鼠标点击高亮效果

一种实用的表格行鼠标点击高亮效果

作者头像
菩提树下的杨过
发布2018-01-22 20:13:14
1.1K0
发布2018-01-22 20:13:14
举报

偶尔在看天天基金网净值公告时,从源代码里剥下的一段js代码,感觉比较实用,分享一下(仅IE有效)

代码语言:javascript
复制
<script??type="text/javascript">

var?highlightcolor='#E0F2FE';

var?clickcolor='#ffedd2';



function??MouseOver(){

????var?source=event.srcElement;????????

????if??(source.tagName=="TD"){????????

????????source=source.parentElement;

????????var?cells??=??source.children;????

????????if??(cells[0].style.backgroundColor!=highlightcolor&&cells[0].style.backgroundColor!=clickcolor)

????????????for(i=0;i<cells.length;i++){

????????????????cells[i].style.backgroundColor=highlightcolor;

????????????}????????

????}

}



function??MouseOut(){????

????var?source=event.srcElement;

????if??(source.tagName=="TD"){????

????????source=source.parentElement;

????????var?cells??=??source.children;????

????????if??(cells[0].style.backgroundColor!=clickcolor)????

????????????for(i=0;i<cells.length;i++){

????????????????cells[i].style.backgroundColor="";

????????????}????????

????}

}



function??MouseClick(){

????var?source=event.srcElement;

????if??(source.tagName=="TD"){????

????????source=source.parentElement;

????????var?cells??=??source.children;

????????if??(cells[0].style.backgroundColor!=clickcolor)

????????????for(i=0;i<cells.length;i++)

????????????????cells[i].style.backgroundColor=clickcolor;????????????

????????else

????????????for(i=0;i<cells.length;i++)

????????????????cells[i].style.backgroundColor="";????

????}

}

</script>



<table?onmouseover="MouseOver()"?onclick="MouseClick()"??onmouseout="MouseOut()"?cellspacing="0"?bordercolordark="#ffffff"??bordercolorlight="#cccccc"??border="1"?width="80%"?align="center"?style="cursor:pointer">??

????<tr>

??????<td>1</td>

??????<td>a</td>

??????<td>b</td>?????

????</tr>

????<tr>

??????<td>2</td>

??????<td>c</td>

??????<td>d</td>?????

????</tr>

????<tr>

??????<td>3</td>

??????<td>e</td>

??????<td>f?</td>?????

????</tr>??

????<tr>

??????<td>4</td>

??????<td>g</td>

??????<td>h?</td>?????

????</tr>??

</table>
本文参与?腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2008-01-05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体分享计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com