<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>dom 0级事件</title>
</head>
<body>
<input type="button" id="btn2" value="按钮"/>
<script>
var btn2 = document.getElementById("btn2");
btn2.onclick = function(){
alert("hello world");
}
</script>
</body>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>dom 0级事件</title>
</head>
<body>
<input type="button" id="btn2" value="按钮"/>
<script>
var btn2 = document.getElementById("btn2");
btn2.onclick = function(){
alert("hello world");
}
</script>
</body>
</html>
这种方式是目前开发人员使用最多的方式。因为它简单而且浏览器的兼容性比较好。与html处理事件相比。耦合度相对较低。