日期:2014-05-16 浏览次数:20292 次
<html> <body> <div id="a"></div> <div id="b"></div> <script> var point = function(id,msg,init){ if (typeof(init)=='undefined'){ init=3; } this.id=id; this.len= init; var show = function(p){ document.getElementById(id).innerHTML = msg + p; }; var initp = function(n){ var p = []; for(var i=0;i<n;i++){ p.push("."); } return p.join(""); } this.start=function(){ var len = this.len; this.timer = setInterval(function(){ if (init!=len){ show(initp(++init)); }else{ init=1; show(initp(init)); } },300); }; this.stop = function(){ clearInterval(this.timer); } } var p = new point("a","loading"); p.start(); //setTimeout(function(){p.stop()},1000); var q = new point("b","加载中",6); q.start(); //setTimeout(function(){q.stop()},1000); </script> </body> </html>