如何用JavaScript+CSS+DIV实现表格变色
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了如何用JavaScript+CSS+DIV实现表格变色,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1464字,纯文字阅读大概需要3分钟。
内容图文
![如何用JavaScript+CSS+DIV实现表格变色](/upload/InfoBanner/zyjiaocheng/299/739861c163b548278e48cc8e1c903853.jpg)
1.鼠标覆盖:onMouseOver
2.鼠标离开:onMouseOut
同时这两个事件需要调用事件函数:
1.实现对行的颜色设置:
resetColor(row)
2.实现对行颜色的改变:
changeColor(row)
实现代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> <html> <head> <title>变色表格示例</title> <script type="text/javascript"> function changeColor(row){ document.getElementById(row).style.backgroundColor='#9999FF'; } function resetColor(row){ document.getElementById(row).style.backgroundColor=''; } </script> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head> <body> <table width="200" border="1" cellspacing="1" cellpadding="1" align="center"> <tr><th>学校</th><th>专业</th><th>人数</th></tr> <tr align="center" id="row1" onMouseOver="changeColor('row1')" onMouseOut="resetColor('row1')"> <th>北大</th><th>法律</th><th>2000</th> </tr> <tr align="center" id="row2" onMouseOver="changeColor('row2')" onMouseOut="resetColor('row2')"> <th>清华</th><th>计算机</th><th>5000</th> </tr> <tr align="center" id="row3" onMouseOver="changeColor('row3')" onMouseOut="resetColor('row3')"> <th>人大</th><th>经济</th><th>6000</th> </tr> </table> </body> </html>
以上就是如何用JavaScript+CSS+DIV实现表格变色的详细内容,更多请关注Gxl网其它相关文章!
内容总结
以上是互联网集市为您收集整理的如何用JavaScript+CSS+DIV实现表格变色全部内容,希望文章能够帮你解决如何用JavaScript+CSS+DIV实现表格变色所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。