-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzhuangshiqi.html
105 lines (93 loc) · 2.56 KB
/
zhuangshiqi.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>装饰器模式</title>
</head>
<style>
#modal {
height: 200px;
width: 200px;
line-height: 200px;
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
border: 1px solid black;
text-align: center;
}
</style>
<body>
<button id="open">
打开
</button>
<button id="close">
关闭
</button>
<script>
var Modal = (function() {
var modal = null;
return function () {
if (!modal) {
modal = document.createElement('div');
modal.id = 'modal';
modal.innerText = '您还未登录';
modal.style.display = 'none';
document.body.appendChild(modal);
}
return modal;
}
})();
class OpenBut {
onClick() {
var modal = Modal();
modal.style.display = 'block';
}
};
class Decorator{
constructor(open_but) {
this.openBut = open_but;
}
onClick() {
this.openBut.onClick();
this.butDisabel();
}
// 禁用open按钮、更改open按钮文字
butDisabel() {
let openBut = document.getElementById('open');
openBut.innerText = '快去登录';
openBut.setAttribute('disabled', true);
}
}
let openButClass = new OpenBut();
let decorator = new Decorator(openButClass);
document.getElementById('open').addEventListener('click', function() {
decorator.onClick();
// let modal = new Modal();
// modal.style.display = 'block';
// changeButtonStatus('open');
});
// document.getElementById('close').addEventListener('click', function() {
// let modal = document.getElementById('modal');
// if (modal) {
// modal.style.display = 'none';
// changeButtonStatus('close');
// }
// });
// function disableButtonText(butStyle) {
// const openBut = document.getElementById('open');
// openBut.innerHTML = butStyle == 'open' ? '快去登陆' : '登陆';
// };
// function disableButton(butStyle) {
// const openBut = document.getElementById('open');
// butStyle == 'open' ? openBut.setAttribute('disabled', true) : openBut.removeAttribute('disabled');
// };
// function changeButtonStatus(butStyle) {
// disableButtonText(butStyle);
// disableButton(butStyle);
// };
</script>
</body>
</html>