javascript使用onclick事件改变选中行的颜色
发布时间:2016-12-30 来源:查字典编辑
摘要:html页面的table中一行一行的显示当然div也行可设置在鼠标放上去时改变其颜色部分代码如下复制代码代码如下:varcurrentAct...
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)"