<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>event lisnter の中断</title>
<style type="text/css">
</style>
</head>
<body>
Attached event listeners on the
<button id="button">button</button> are:
<ul id="attached_events"></ul>
<script>
function function_name(f){
return 'name' in f
? f.name
: (''+f).replace(/^\s*function\s*([^\(]*)[\S\s]+$/im, '$1');
};
function handler1(){ alert('handler1 is called!'); }
function handler2(){ alert('handler2 is called!'); }
function handler3(){ alert('handler3 is called!'); }
function handler4(){ alert('handler4 is called!'); }
function stop_propagation(ev){
ev.stopImmediatePropagation()
alert('stop_propagation is called!');
}
var b = document.getElementById('button');
var ul = document.getElementById('attached_events');
[handler1,handler2,stop_propagation,handler3,handler4].forEach(function(f){
b.addEventListener('click', f);
var li = document.createElement('li');
li.appendChild(document.createTextNode(function_name(f)));
ul.appendChild(li);
});
</script>
</body>
</html>