好久不更新了
[JS]文字逐字打出
代码如下
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div id="content"></div> </body> <script> window.onload = function() { let word = '我是一个个的文字,慢慢的被打出 '; let n = 0; let t = setInterval(function() { n++; console.log('n:' + n + ",word.length:" + word.length); if(n > word.length) clearInterval(t); document.getElementById('content').innerText = word.substring(0, n); }, 100); } </script> </html>