getElementsByTagName returns an array, not a single element. You need to loop through your results and attach a function to each one individually, something like this:
var buttons = document.getElementsByTagName('button');
for( var x=0; x < buttons.length; x++ ) {
buttons[x].onclick = function(){
alert('entered');
document.getElementById("demo").innerHTML="test";
};
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…