<!DOCTYPE html>
<html>
<head>
<title>DOM 0|2</title>
<meta charset="utf-8">
</head>
<body>
<input type="button" value="按钮1" id="btn1">
<script type="text/javascript">
var btn1=document.getElementById("btn1");
function get(){
alert("hello");
}
var eventSelect={
addHandler:function(element,type,handler){
if (element.addEventListener) {
element.addEventListener(type,handler,false);
}
else if (element.attachEvent) {
element.attachEvent('on'+type,handler);
}
else{
element['on'+type]=handler;
}
},
removeHandler:function(element,type,handler){
if (element.removeEventListener) {
element.removeEventListener(type,handler,false);
}
else if (element.attachEvent) {
element.detachEvent('on'+type,handler);
}
else{
element['on'+type]=null;
}
}
}
eventSelect.addHandler(btn1,'clcik',get);
</script>
</body>
</html>