<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>练习</title> <script type="text/javascript"> onload = function () { var txt = document.getElementById("txt"); var txt2 = txt.innerHTML.trim(); // alert(txt.innerHTML.trim().charAt(0)); //alert(txt.innerHTML.trim().substr(0,2)); var paoMaDeng = function () { //两个获取字符的方法,charAt(0)和substr(0,1) var first = txt2.charAt(0); var rest = txt2.substr(1); txt2 = rest + first; txt.innerHTML = txt2; } aaa = setInterval(paoMaDeng, 100); } </script> </head> <body> <p id="txt"> 北京欢迎你!</p> <input type = "button" value = "停止" id = "btn" onclick="clearInterval(aaa);"/> </body> </html>
时间: 2024-10-12 13:45:55