Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 语句交错_Javascript_For Loop - Fatal编程技术网

Javascript 语句交错

Javascript 语句交错,javascript,for-loop,Javascript,For Loop,我有CodeJSHiddle,当你在单元格上方悬停时,该列会改变颜色,但是,当你将鼠标移动到另一个单元格时,你会看到颜色似乎以交错的模式恢复,有人知道为什么会发生这种情况吗,我不想让人讲我的代码有多可怕 处理取消高亮显示的代码: tables[i].onmouseout = function(e){ var target; if(e.target.tagName.toLowerCase() == 'span') target = e.target.parentNode;

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

处理取消高亮显示的代码:

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/,'');
    }
}
表[i].onmouseout=function(e){
var目标;
如果(e.target.tagName.toLowerCase()=“span”)目标=e.target.parentNode;
如果(e.target.tagName.toLowerCase()='td')target=e.target;
如果(!target | | target.innerHTML=='')返回;
target=document.getElementsByClassName('hcell');
对于(变量i=0;i
如果onmouseover逻辑出现错误,您将添加十几次hcell类,然后仅删除其中一个,在您的fiddle中进行一次简短测试,结果如下:

<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>
2D
考虑使用jQuery使您的生活更加轻松