用command模拟多线程
来源:互联网 发布:神雕群芳谱txt下载知轩 编辑:程序博客网 时间:2024/06/16 05:00
<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>