<!DOCTYPE html>
<html>
<head>
<title>添加与移除事件句柄</title>
</head>
<body>
<button id="btn">按钮</button>
<script>
//DOM EventListener:
//方法: addEventListener();//方法用于向指定元素添加事件句柄
// removeEventListener();//移除方法添加的事件句柄
句柄作用:句柄之间不会覆盖,依次弹出来
var x = document.getElementById('btn');
x.addEventListener(" click",hello);
x.addEventListener(" click",world);
x.removeEventListener( "click",hello);
function hello() {
alert("hello");
}
function world() {
alert("world");
}
</script>
</body>
</html>
<html>
<head>
<title>添加与移除事件句柄</title>
</head>
<body>
<button id="btn">按钮</button>
<script>
//DOM EventListener:
//方法: addEventListener();//方法用于向指定元素添加事件句柄
// removeEventListener();//移除方法添加的事件句柄
句柄作用:句柄之间不会覆盖,依次弹出来
var x = document.getElementById('btn');
x.addEventListener(" click",hello);
x.addEventListener(" click",world);
x.removeEventListener( "click",hello);
function hello() {
alert("hello");
}
function world() {
alert("world");
}
</script>
</body>
</html>