獲取元素的第二種方法
阿新 • • 發佈:2017-05-26
title onclick alert set scrip tle 方法 onload 文檔
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標題文檔</title>
<script>
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); };
// 重復執行某些代碼
// 每次執行的時候,有個數字在變化
};
</script>
</head>
<body>
</body>
</html>
獲取元素的第二種方法