运行没有效果,提问代码哪里出了问题?
<!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>事件处理程序</title>
</head>
<body>
<input type="button" value="按钮" id="btn" onclick="showMes()"/>
<script>
var bt = document.getElementById("btn");
function showMes(){
alert("我是黑牛")
}
var eventUitl = {
//添加句柄
addHandler:function(element,type,handler){
if(element.addEventListener){
bt.addEventListener(type,handler,false);
}else if(element.attachEvent){
bt.attachEvent('on'+type,handler);
}else{
element['on'+type] = handler ;
}
//删除句柄
removeHandler:function(element,type,handler){
if(element.addEventListener){
bt.removeEventListener(type,handler,false);
}else if(element.attachEvent){
bt.detachEvent('on'+type,handler);
}else{
element['on'+type] = null ;
}
}
eventUitl.addHandler(bt,'click',shouMes);
</script>
</body>
</html>