-
Notifications
You must be signed in to change notification settings - Fork 2
/
一次插入10万条数据.html
46 lines (40 loc) · 1.03 KB
/
一次插入10万条数据.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<ul></ul>
</body>
<script>
setTimeout(() => {
const total = 100 //插入一万条数据
const once = 20 // 一次插入的数据
const loopCount = Math.ceil(total / once) //插入数据需要的次数
let renderCount = 0
const ul = document.querySelector("ul")
//创建、添加li节点
function add() {
const fragment = document.createDocumentFragment()
for (let i = 0; i < once; i++) {
const li = document.createElement("li")
li.innerText = Math.floor(Math.random() * total)
fragment.appendChild(li)
}
ul.appendChild(fragment)
renderCount++
loop()
}
function loop() {
if (renderCount < loopCount) {
window.requestAnimationFrame(add)
}
loop()
}
loop()
}, 0)
</script>
</html>