window.onload = function () {
var trs = document.getElementById('tb').getElementsByTagName('tr');
for (var i = 0; i < trs.length; i++) {
trs[i].onmouseover = function () {
this.style.backgroundColor = 'red';
};
trs[i].onmouseout = function () {
this.style.backgroundColor = '';
}
}
}
<table id="tb" border="1" cellpadding="0" cellspacing="0" style=" cursor:pointer;">
<tr>
<td>
写两遍 写两遍 写两遍
</td>
<td>
写两遍 写两遍 写两遍
</td>
<td>
写两遍 写两遍 写两遍
</td>
</tr>
<tr>
<td>
写两遍 写两遍 写两遍
</td>
<td>
写两遍 写两遍 写两遍
</td>
<td>
写两遍 写两遍 写两遍
</td>
</tr>
</table>
var trs = document.getElementById('tb').getElementsByTagName('tr');
for (var i = 0; i < trs.length; i++) {
trs[i].onmouseover = function () {
this.style.backgroundColor = 'red';
};
trs[i].onmouseout = function () {
this.style.backgroundColor = '';
}
}
}
<table id="tb" border="1" cellpadding="0" cellspacing="0" style=" cursor:pointer;">
<tr>
<td>
写两遍 写两遍 写两遍
</td>
<td>
写两遍 写两遍 写两遍
</td>
<td>
写两遍 写两遍 写两遍
</td>
</tr>
<tr>
<td>
写两遍 写两遍 写两遍
</td>
<td>
写两遍 写两遍 写两遍
</td>
<td>
写两遍 写两遍 写两遍
</td>
</tr>
</table>