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

Octavia ·
更新时间:2024-09-21
· 732 次阅读

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)"



中行 onclick JavaScript

需要 登录 后方可回复, 如果你还没有账号请 注册新账号