你可以用完全不同的方式来解决这个问题。
例如,您有一个包含 5000 条记录的表
<table id="recordtable">
<tr>
<td>Record 1</td>
<td><a href="#link1">click here</a></td>
</tr>
......//snip
<tr>
<td>Record 100</td>
<td><a href="#link100">click here</a></td>
</tr>
.......//snip
</table>
现在在桌子上放一个观察者来观察链接的点击
$('recordtable').on('click','a:not([href="#"])',function(e){
//FYI 'this' points to the table element
//e is the event object passed in-------------------^^^
//use e.findElement() to get the element that the click originated on
var el = e.findElement();
if(el.readAttribute('href') != "something")
{
window.location.href = 'some other link';
}
//most importantly stop the event so that the link doesn't fire
e.stop();
});