-
Notifications
You must be signed in to change notification settings - Fork 32
/
Demo.html
43 lines (38 loc) · 1.6 KB
/
Demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><!---<![endif]-->
<meta name="description" content="Polyfills the EventListener interface in IE.">
<meta name="viewport" content="width=device-width">
<title>EventListener</title>
<!--[if IE 8]><script src="EventListener.js"></script><!--<![endif]-->
<!--[if lt IE 8]><script src="EventListener.oldie.js"></script><!--<![endif]-->
</head>
<body>
<h1>EventListener</h1>
<p>
<span id="a">Three events are registered these two sentences.</span>
<span id="b">On dispatch, they will remove themselves.</span>
</p>
<p id="c">A fourth event is registered on the document.</p>
<script>
var
span1 = document.getElementById("a"),
span2 = document.getElementById("b"),
p2 = document.getElementById("c"),
onevent = function (event) {
var message = "Succesfully fired " + event.type + " on " + (event.currentTarget && event.currentTarget.nodeName || "window") + " at " + new Date + ".";
if (event.currentTarget.innerHTML) event.currentTarget.innerHTML = message; else p2.innerHTML = message;
event.currentTarget.removeEventListener(event.type, onevent);
};
document.addEventListener("DOMContentLoaded", function (event) {
p2.innerHTML = p2.innerHTML.slice(0, -1) + ", and a fifth on the window that actually registers the other four.";
span1.addEventListener("mouseover", onevent);
span2.addEventListener("mousedown", onevent);
span2.addEventListener("mouseup", onevent);
document.addEventListener("click", onevent);
});
</script>
</body>
</html>