问答详情
源自:2-4 IE事件处理程序及跨浏览器解决

(已解决)代码如下 为何按钮1无反应

<!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>


提问者:慕粉3346016 2016-11-12 00:06

个回答

  • snowflow0
    2016-11-12 04:38:05
    已采纳

    line 75:    eventSelect.addhandler(btn1,"click",get);,你把'click'写成了"clcik"