<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script type="text/javascript">
function btnMessage(){
alert("hello world1");
}
function btnMessage2(event){
alert(event.type);
}
function btnMessage3(event){
event.stopPropagation();
event.pretDefavenult();
}
window.onload = function(){
var btn2 = document.getElementById("btn2");
var btn3 = document.getElementById("btn3");
var box = document.getElementById("box");
var btn4 = document.getElementById("btn4");
btn2.onclick = function(){
alert("hello world0");
}
box.onclick = function(){
alert("hello world00");
}
//btn2.onclick = null;
//btn3.addEventListener('click',function(){alert(this.value);},false);
//btn3.removeEventListener('click',btnMessage,false);
//btn3.attachEvent('onclick',btnMessage);
var UntilHandler={
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;
}
}
}
UntilHandler.addHandler(btn3,'click',btnMessage2);
UntilHandler.addHandler(bnt4,'click',btnMessage3);
//UntilHandler.removeHandler(btn3,'click',btnMessage2);
}
</script>
</head>
<body>
<div id = "box">
<input type="button" name="btn" value="按钮" onclick="btnMessage()">
<input type="button" name="btn2" value="按钮2" id="btn2">
<input type="button" name="btn3" value ="按钮3" id= "btn3">
<a href= "http://www.imooc.com/course/programdetail/pid/32" id = "btn4">跳转</a>
</div>
<script>
</script>
</body>
</html>
代码打错了,以后小心点
UntilHandler.addHandler(bnt4,'click',btnMessage3);
这句的括号里的btn4,你的是bnt4……
以后写代码,保存后,用浏览器打开你的文件,右击检查(审查元素),可以很快的发现自己代码的错误。