简单的, 控制CSS来做。 呵!

解决方案 »

  1.   

    异步的还可以这样做,网上有很多loading的图片,直接用一个以行了,控制显示与隐藏display: block|none
    visibility: visible|hidden
      

  2.   


    <html>
    <head>
    <script type="text/javascript">
    function $(selector){
        return document.getElementById(selector);
    }
    (function(){
        var index = 0;
        var timer = null;    $.show = function (){
            var d1 = $("d1"), d2 = $("d2");
            timer = setInterval(loading,100);
            function loading(){
                if(index>=100){ clearInterval(timer); return;}
                d1.style.width = ++index + "%";
                d2.innerHTML = "已加载" + index + "/100";
            }
        }
        $.end = function (){
            if(timer){
                clearInterval(timer);
            }
        }
    })();
    </script>
    </head>
    <body>
      <div style="border:1px blue solid;width:800px;height:25px">
      <div style="width:0px;height:23px;background-color:#FF99CC" id="d1"></div>
      </div>
      <div id="d2" style="font-size:9pt"> </div>  <input type="button" value="开始" onclick="$.show();">
      <input type="button" value="结束" onclick="$.end();">
    </body>
    </html>