跑马灯效果
<!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"> var flag; function f1(obj) { flag = obj; } setInterval(function () { var title = document.title;//获取标题 if (flag == "R") { //向右走 var first = title.substr(title.length - 1); var last = title.substr(0, title.length - 1); document.title = first + last; } else { //向左走 var first = title.substr(0, 1); var last = title.substr(1); document.title = last + first; }; }, 800) </script> </head> <body> <input type="button" value="向左" id="btnLeft" onclick="f1('L')"/> <input type="button" value="向右" id="btnRight" onclick="f1('R')"/> </body> </html>