<分区>
我一直在尝试编写一个函数,使所有链接在点击时执行一个函数,但我不知道为什么这不起作用:
function interceptLinks() {
var ls = document.links, numLinks = ls.length
for (i=0; i<numLinks; i++) {
if ls[i].onclick {
//Don't do anything, cause there's already code there!
}
else {
ls[i].onclick = "reloadInfo();";
}
}
}
当我运行该函数时,它只是抛出一个“interceptLinks is not defined”错误。