注册 登录
编程论坛 WEB前端(UI)

用command模拟多线程,这个程序怎么不能运行?

vfdff 发布于 2011-02-09 23:39, 710 次点击
<html>
    <head>
        <title> emus -- 用command模拟多线程       </title>
    </head>
   
    <body>
        <SCRIPT LANGUAGE = "JavaScript">
        <!--
          var commandList = [];
          function executeCommands(){
              if (commandList.length > 0) {
                commandList.shift()();
              }
          }
         
          function StartNewTask(){
              var resultTemp = document.creatElement("span");
              document.body.insertBefore(resultTemp, document.body.LastChild);
              document.body.insertBefore(document.creatElement("br"), document.body.LastChild);
              resultTemp.innerText = 0;
              commandList.push(function(){simThread(resultTemp, 0);});
          }
         
          function simThread(temp, n){
              temp.innerText = temp.innerText-(-n);
              if(n<1000)
                  commandList.push(function(){simThread(temp, ++n);});
              else {
                  document.body.removechild(temp.nextsibling);
                  document.body.removechild(temp);
              }
          }
         
          window.onload = function(){setInterval("executeCommands()", 1);}
         
          //-->
        </SCRIPT>
        <button onclick="StartNewTask()">start</button>
        <BR> <BR>
    </body>
</html>
只有本站会员才能查看附件,请 登录



[ 本帖最后由 vfdff 于 2011-2-10 00:01 编辑 ]
1 回复
#2
vfdff2011-02-10 10:56
注意大小写:
17:    var resultTemp = document.createElement("span");
18:    document.body.insertBefore(resultTemp,document.body.lastChild);
19:    document.body.insertBefore(document.createElement("br"),document.body.lastChild);
29:    document.body.removeChild(temp.nextSibling);
30:    document.body.removeChild(temp);

1