一万条数据

79 阅读1分钟

一万条数据 body结构

<button id="button">button</button>
<ul id="container"></ul>


 <script>
  document.getElementById('button').addEventListener('click', function () {
    // 记录任务开始时间
    let now = Date.now()
    // 插入一万条数据
    const total = 10000
    // 获取容器 ul
    let ul = document.getElementById('container')
    // 获取数据
    for (let i = 0; i < total; i++) {
        let li = document.createElement('li')
        li.innerHTML = (Math.random() * total)
        ul.appendChild(li)
    }
    console.log('js运行时间', Date.now() - now);
    setTimeout(() => {
        console.log('总运行时间:Date.now()-now');
    }, 0)
})
</script>