您现在的位置: 万盛学电脑网 >> 程序编程 >> 脚本专题 >> javascript >> 正文

javascript使用onclick事件改变选中行的颜色

作者:佚名    责任编辑:admin    更新时间:2022-06-22

 javascript onclick事件改变选中行的颜色,方法简单,大家参考使用吧

html页面的table 中一行一行的显示当然 div也行 可设置在鼠标放上去时改变其颜色 部分代码如下   代码如下: <script type="text/javascript"> var currentActiveRow; //当前活动行   //改变选中行的颜色 function changeActiveRow(obj) {     if (currentActiveRow) {         currentActiveRow.style.backgroundColor = "";     }     currentActiveRow = obj;     currentActiveRow.style.backgroundColor = "#F2F2F2"; }   </script>       然后在td上设置onmousehover或者onclick事件即可 onmouseover="changeActiveRow(this)"