promise间隔时间添加dom
生活随笔
收集整理的這篇文章主要介紹了
promise间隔时间添加dom
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<!DOCTYPE html>
<html>
<head><title></title>
</head>
<body><input type="button" value="添加">
<ul></ul>
<script>var oUl = document.querySelector("ul");var oBtn = document.querySelector("input");var count = 0;var timer = null;function createDom() {var oLi = document.createElement("li");oLi.innerHTML = count++;oUl.appendChild(oLi);}var addDom = (function () {return new Promise(function (resolve, reject) {resolve(createDom);});})();oBtn.onclick = function () {timer = setInterval(function () {if (count == 10) {clearInterval(timer);} else {addDom.then(function (fn) {fn();});}}, 1000);}
</script>
</body>
</html>
promise 的基本用法
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的promise间隔时间添加dom的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL · 源码分析 · 一条ins
- 下一篇: Day12 CSS简单用法