-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathok.html
79 lines (55 loc) · 1.31 KB
/
ok.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Test de page</title>
</head>
<body>
<div>
Ceci est un boutton, essayez donc de cliquer dessus :
<button id="button">Cliquez je vous dis</button>
</div>
<div>
Vous avez cliqué <span id="nmbClick">0</span> fois sur le bouton !
</div>
<div id="init">Et hop, un boutton pour <button>réinitialiser.</button></div>
</body>
</html>
<script type="text/javascript">
(function(){
var myClass = function() {
this.publicVar = 0;
}
var numberClicked = 0;
myClass.prototype = {
decrement:function() {
console.log( --this.publicVar );
-- numberClicked;
this.apply();
},
increment : function() {
console.log( ++this.publicVar );
++ numberClicked;
this.apply();
},
init : function() {
numberClicked = 0;
this.apply();
},
apply : function() {
clickCounter.innerHTML = numberClicked;
}
};
myObject = new myClass();
console.log(myObject);
var clickCounter = document.getElementById("nmbClick");
var button = document.getElementById("button");
button.onclick = function() {
myObject.increment();
};
var init = document.getElementById("init");
init.onclick = function() {
myObject.init();
}
})();
</script>