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');
}
}
}
螢火顯示:JavaScript中的錯誤代碼?
TypeError: link[i] is undefined
link[i].setAttribute('class', 'selected');
您需要關閉。 – adeneo 2013-05-03 17:31:15