<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>handler</title>
<script type="text/javascript">
function showWord(){
alert("hello world!")
}
var mybtn=document.getElementsByClassName('btn')[0];
var eventUtil={
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;
}
}
}
eventUtil.addHandler(mybtn,'click',showWord())
</script>
</head>
<body>
<input type="button" value="try" />
</body>
</html>