Javascript 语句交错
我有CodeJSHiddle,当你在单元格上方悬停时,该列会改变颜色,但是,当你将鼠标移动到另一个单元格时,你会看到颜色似乎以交错的模式恢复,有人知道为什么会发生这种情况吗,我不想让人讲我的代码有多可怕 处理取消高亮显示的代码: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;
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使您的生活更加轻松