window.onload = function() {
var links = document.getElementById('subMenu').getElementsByTagName('a');
for(var i = 0; i < links.length; i++) {
links[i].onclick = function() {
links[i].setAttribute('class', 'selected');
}
}
}
萤火虫显示:
TypeError: link[i] is undefined
link[i].setAttribute('class', 'selected');