javascript没有多线程,只能用timer来模拟

解决方案 »

  1.   

    <body><div id="ice" style="color:#F60">10000</div></body>
    <script language="javascript">
    <!--
    function timer(target){
    this.time   = 10000;
    this.target = target;
    this.run  = function(){
    this.time++;
    this.target.innerHTML = this.time;
    var me = this;
    this.tm = setTimeout( function(){me.run();}, 1 );
    }
    this.stop = function(){if(this.tm)clearTimeout(this.tm)};
    }
    var $=document.getElementById;
    var t = new timer($('ice'));
    //-->
    </script>
    <input type="button" value="run" onclick="t.run()"/>
    <input type="button" value="stop" onclick="t.stop()"/>
      

  2.   

    查看 emu 的贴子,他有专贴研究JS的多线程