js 如何在多个按钮中获取点击按钮的id值
window.onload = function(){ var arr = document.getElementsByTagName('button'); for(var i = 0;i<arr.length;i++){ arr[i].onclick = function(){ alert(this.id); } } } <button id="b1">b1</button> <button id="b2">b2</button> <button id="b3">b3</button> <button id="b4">b4</button>