console
function showMessage1(){
document.write("You have clicked the button!");
}
var btn1 = document.getElementById('btn1');
btn1.onclick = function(){
document.write('BTN1');
}
var btn2 = document.getElementById('btn2');
btn2.addEventListener('click',function(){
document.write('BTN2')
},false)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>事件处理程序</title>
</head>
<body>
<h4>HTML事件处理程序</h4>
<input type="button" onclick="try{showMessage1();}catch(ex){}" />
<h4>DOM0级事件处理程序</h4>
<input type="button" id='btn1' />
<h4>DOM2级事件处理程序</h4>
<input type="button" id='btn2' />
</body>
</html>