帮我看看哪里错了

<body>

<input type="button" value="按钮" id="btn" onclick="showMessage()"/>

<input type="button" value="按钮2" id="btn2" />

<input type="button" value="按钮3" id="btn3" />

<script>

function showMessage(){

  alert('hallo world');

}

var btn2=document.getElementById('btn2');

var btn3=document.getElementById('btn3');

var eventUtil={

addHandler:function(element,type,handler)

{

  if(element.addEventListener)

  {elemnet.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)

  {elemnet.removeEventListener(type,handler,false);}

else if(element.detachEvent)

{element.detachEvent('on'+type,handler);}

else{element['on'+type]=null;}

}

}

eventUtil.addHandler(btn3,'click',showMessage);

</script>

</body>


未来的大牛级人物
浏览 1390回答 1
1回答

六道骸

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;}},removeHandler:function(element,type,handler){  if(element.removeEventListener) {element.removeEventListener(type,handler,false);} else if(element.detachEvent) {element.detachEvent('on'+type,handler);} else{element['on'+type]=null;}}};
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript