<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h2>DOM 2级事件绑定</h2>
<button>解绑</button>
<script type="text/javascript">
var h2 = document.getElementsByTagName('h2')[0];
function f1(){
console.log('甲程序员的小功能');
}
//甲程序员
h2.addEventListener('click',f1);
//解绑
var btn = document.getElementsByTagName('button')[0];
btn.onclick = function(){
h2.removeEventListener('click',f1);
}
//乙程序员
h2.addEventListener('click',function(){
console.log('乙程序员的小功能');
});
//丙程序员
h2.addEventListener('click',function(){
console.log('丙程序员的小功能');
});
</script>
</body>
</html>
f1
is the function object itself. The function is equivalent to assigning the function object to the variable of the function name, so you can access the function just like accessing the variable.f1()
is the calling function.f1() gets the return value of the function call, and f1 represents the pointer to a function