var oUl = document.getElementsByTagName('ul')[0]; var aLi = oUl.getElementsByTagName('li'); window.onload = function (){ // document.title = 123; // document.body.innerHTML = 'abc'; var aBtn = document.getElementsByTagName('input'); // alert(aBtn.length); document.body.innerHTML = '<input type="button" value="按钮" /><input type="button" value="按钮" /><input type="button" value="按钮" />'; // alert(aBtn.length); aBtn[0].onclick = function (){ alert(1); }; aBtn[1].onclick = function (){ alert(1); }; aBtn[2].onclick = function (){ alert(1); }; // 重复执行某些代码 // 每次执行的时候,有个数字在变化 } aLi[j].style.border = '1px solid red'; oDiv.style.cssText = ' 200px; height:200px; '; alert(this); window fn1(this); function fn1(obj){ obj => window } oDiv.onclick = function (){ fn2(this); }; function fn2(obj){ obj => oDiv }