尝试这样:
<html>
<head>
<script>
function hl(cell, enable)
{
var rIndex = cell.cellIndex;
var cIndex = cell.parentNode.rowIndex;
var cell2 = cell.parentNode.parentNode.rows[rIndex].cells[cIndex];
if (enable) {
cell.style.backgroundColor = '#000';
cell2.style.backgroundColor = '#000';
} else {
cell.style.backgroundColor = '#fff';
cell2.style.backgroundColor = '#fff';
}
}
</script>
</head>
<body>
<table border="1">
<tr>
<td></td>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
<tr>
<td>A</td>
<td></td>
<td onmouseover="hl(this, true)" onmouseout="hl(this, false)">A:B</td>
<td onmouseover="hl(this, true)" onmouseout="hl(this, false)">A:C</td>
</tr>
<tr>
<td>B</td>
<td onmouseover="hl(this, true)" onmouseout="hl(this, false)">B:A</td>
<td></td>
<td onmouseover="hl(this, true)" onmouseout="hl(this, false)">B:C</td>
</tr>
<tr>
<td>C</td>
<td onmouseover="hl(this, true)" onmouseout="hl(this, false)">C:A</td>
<td onmouseover="hl(this, true)" onmouseout="hl(this, false)">C:B</td>
<td></td>
</tr>
<table>
</body>
</html>