-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
176 lines (152 loc) · 4.41 KB
/
test.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id='a' onclick='openA("a")'>
<div class="pp">
<h1>111</h1>
</div>
</div>
<div id='b' onclick='openA("b")'>
<div class="pp">
<h1>222</h1>
</div>
</div>
<script>
let openModal = (function openModal() {
let modalContainer = document.createElement('div')
let body = document.querySelector('body')
let single = null
return function (children) {
if (!single) {
// children
// console.log(8, children)
single = modalContainer.appendChild(children)
body.appendChild(modalContainer)
} else {
single = null
// console.log(modalContainer.childNodes)
modalContainer.childNodes[0].remove()
//
}
}
})()
function openA(target) {
// var e = window.event || arguments.callee.caller.arguments[0];
let a = document.querySelector(`#${target}`)
// let body = document.querySelector('body')
// body.append(e)
openModal(a.cloneNode(true))
}
</script>
<!-- <script>
console.log('script start');
setTimeout(function () {
console.log('setTimeout');
}, 0);
Promise.resolve().then(function () {
console.log('promise1');
}).then(function () {
console.log('promise2');
});
console.log('script end');
</script> -->
<!-- <script>
class Singleton {
constructor(name) {
this.name = name
}
print() {
return this.name
}
}
var A = (function () {
let single = null
return function (name) {
if (!single) {
single = new Singleton(name)
}
return single
}
})()
console.log(A('a'))
console.log(A('b'))
console.log(A('b'))
</script> -->
<!-- <script>
function Obj(name) {
this.name = name
}
Obj.prototype.print = function () {
console.log(this.name)
}
let createObj = (function () {
let single = null
return function (name) {
if (!single) {
single = new Obj(name)
}
return single
}
})()
createObj('a').print()
createObj('b').print()
</script> -->
<!-- <script>
function Obj(name) {
this.name = name
this.single = null
}
Obj.prototype.print = function () {
console.log(this.name)
}
Obj.create = function (name) {
if (!this.single) {
this.single = new Obj(name)
}
return this.single
}
let a = Obj.create('a').print()
let b = Obj.create('b').print()
</script> -->
<!-- <script>
let a = (money) => {
return 1 * money
}
function strategy(cb, money) {
return cb(money)
}
console.log(strategy(1, 1000))
console.log(strategy(2, 1000))
console.log(strategy(3, 1000))
</script> -->
<!-- <script>
const myImage = (function () {
const imgNode = document.createElement('img')
document.body.appendChild(imgNode)
return {
setSrc: function (src) {
imgNode.src = src
}
}
})()
const proxyImage = (function () {
const img = new Image()
img.onload = function () { // http 图片加载完毕后才会执行
myImage.setSrc(this.src)
}
return {
setSrc: function (src) {
myImage.setSrc('./src/imgs/loading.png') // 本地 loading 图片
img.src = src
}
}
})()
proxyImage.setSrc('./src/imgs/loaded.png')
</script> -->
</body>
</html>