-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.html
88 lines (84 loc) · 2.61 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>delegate-events Demo</title>
<style type="text/css">
.container {
max-width: 900px;
margin: 0 auto;
}
.btn-wrap,
.input-wrap,
.radio-wrap {
margin-top: 20px;
}
#messages {
max-height: 300px;
margin-top: 20px;
overflow: auto;
}
</style>
</head>
<body>
<div class="container">
<h1>delegate-events Demo</h1>
<div class="btn-wrap">
<button class="btn-test">.btn-test</button>
<button class="btn-with-event-bubbling">.btn-with-event-bubbling</button>
<button class="btn-clear">.btn-clear</button>
</div>
<div class="input-wrap">
<input type="text" class="input-test" placeholder=".input-test"/>
</div>
<div class="radio-wrap">
<label><input type="radio" name="radio-test" value="1"/>radio 1</label>
<label><input type="radio" name="radio-test" value="2"/>radio 2</label>
<label><input type="radio" name="radio-test" value="3"/>radio 3</label>
<label><input type="radio" name="radio-test" value="4"/>radio 4</label>
</div>
<div id="messages"></div>
</div>
<script type="text/javascript" src="delegate-events.js"></script>
<script type="text/javascript">
delegate(document.body, {
'click .btn-wrap .btn-test': function () {
Message.add('click .btn-test');
},
'click .btn-wrap .btn-without-event-bubbling': function () {
Message.add('click .btn-without-event-bubbling');
return false;
},
'click .btn-wrap': function (e) {
Message.add('click .btn-wrap');
},
'click .btn-wrap .btn-clear': function () {
Message.clear();
return false;
},
'focus .input-test': function () {
Message.add('focus .input-test');
},
'blur .input-test': function () {
Message.add('blur .input-test');
},
'input .input-test': function (e) {
Message.add('input .input-test value:' + e.currentTarget.value);
},
'change input[type=radio]': function (e) {
Message.add('change input[type=radio] value:' + e.currentTarget.value);
}
});
var Message = {
el: document.getElementById('messages'),
add: function (msg) {
this.el.innerText += msg + '\n';
this.el.scrollTop = 99999;
},
clear: function () {
this.el.innerText = '';
}
};
</script>
</body>
</html>