1 function updateUI(){ 2 var imgs = document.getElementByTagName("img"); 3 for (var i=0, len = imgs.length; i < len; i++){ 4 imgs[i].title = document.title + " image " + i; 5 } 6 7 var msg = document.getElementById("msg"); 8 msg.innerHTML = "Update complete"; 9 } 10 11 12 //性能优化 : 将一个函数中会用到的多次的全局对象存储为局部变量总是没错的 13 function updateUI(){ 14 var doc = document; 15 var imgs = doc.getElementsByTagName("img"); 16 ...... 17 }