<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> #container{ height: 200px; width: 200px; border: 1px solid #ccc; } </style> <script src="D:/jobn/前端笔记/jquery笔记/jquery-1.11.2.js"></script> </head> <body> <div id="container"> </div> <script type="text/javascript"> var con = $("#container"); var s = "这是一个用jquery实现的打字效果"; var len = s.length; var index = 0; var tid = null; function start(){ con.text(''); tid = setInterval(function(){ con.append(s.charAt(index)); if(index ++ === len){ clearInterval(tid); index = 0; start(); } },100); } start(); </script> </body> </html>
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/8646.html