<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <input type="button" id="btn1" value="确定" name="按钮1"> </body> <script type="text/javascript"> function showMes(event){ alert(event.target.nodename) } var btn1=document.getElementById("btn1"); var eventUtil={ //添加句柄 addHandler:function(element,type,handler){ if(element.addEventlistner){ element.addEventlistner(type,handler,false); }else if(element.attachEvent){ element.attachEvent("on"+type,handler); }else{ element["on"+type]=handler; } } } eventUtil.addHandler(btn1,"click",showMes) </script> </html>
谷歌火狐nodename值返回undefined
alert(event.target.nodename) 中的 nodename 改为 name
是大写的N,nodeName
你的listener都写错了