<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <font id="show" color="blue" size="6"></font> </body> <script> var show = document.getElementById('show'); var str = '今天也是3月1号也就是说一九年已经过去两个月了'; //将字符串添加标签的函数 function pick(i,str){ tmp = str.substr(0,i); tmp +='<font color="red" size="7">'+str[i]+'</font>'; tmp += str.substr(i+1); //alert(tmp); return tmp; } var num = 0; setInterval(function(){ if(num >=str.length){ num = 0; } show.innerHTML =pick(num,str); num++; },300) </script> </html>
点击 "运行实例" 按钮查看在线实例