0

我有这个代码JSFiddle,当您将鼠标悬停在单元格上时,该列会改变颜色,但是,当您将鼠标移动到另一个单元格时,您会看到颜色似乎以交错的模式恢复,有没有人知道为什么会这样正在发生,我不想讲我的代码有多可怕。

处理取消突出显示的代码:

tables[i].onmouseout = function(e){
    var target;
    if(e.target.tagName.toLowerCase() == 'span') target = e.target.parentNode;
    else if(e.target.tagName.toLowerCase() == 'td') target = e.target;
    if(!target || target.innerHTML == ' ') return;
    target = document.getElementsByClassName('hcell');
    for(var i = 0; i < target.length; i++){
        target[i].className = target[i].className.replace(/\bhcell\b/,'');
    }
}
4

1 回答 1

1

您的 onmouseover 逻辑中有一个错误,您添加了 hcell 类十几次,然后您只删除了其中一个,在您的小提琴中进行了一个简短的测试,结果如下:

<td class="letter hcell hcell hcell hcell hcell hcell hcell hcell hcell hcell hcell hcell hcell hcell hcell hcell hcell hcell hcell hcell hcell hcell hcell hcell"><span class="tblsup">2</span>D</td>

考虑使用 jQuery 让你的生活更轻松。

于 2013-11-15T08:01:02.027 回答