Chair's blog
2011年8月19日 星期五
JavaScript 模擬批次檔的執行
<html> <head> <title>模擬 Command Line 的執行方式 (將準備要執行的 function 放入陣列)</title> </head> <body> <SCRIPT LANGUAGE="JavaScript"> <!-- var tempII = 0; var commandList = []; function executeCommands() { document.getElementById('waitRunS').innerHTML = commandList.length; if(commandList.length>0) { //執行commandList中的 function 並且從陣列中移除這個Function, 以便執行下一個function... commandList.shift()(); } } function startNewTask() { //Create一個span var resultTemp = document.createElement("span"); //將span加在body內 document.body.insertBefore(resultTemp, document.body.lastChild); //再加上一個br document.body.insertBefore(document.createElement("br"),document.body.lastChild); resultTemp.innerHTML = 0; //tempII++; for(tempII = 0; tempII < 50; tempII++) //產生10個 command... { //在陣列中放入function (一共放50個) commandList.push( function() { simThread(resultTemp, 1); //把執行的事件加入commandList中, 讓executeCommands可以去執行... } ); } } function simThread(temp,n) { temp.innerHTML = temp.innerHTML-(-n); //temp.innerHTMLt = temp.innerHTML + n; //使用這行會變成是字串合併... } window.onload = function() { setInterval("executeCommands()",100); //每0.1秒就執行一次指令... } //--> </SCRIPT> <h2>模擬Command Line執行</h2><button onclick="startNewTask()">每按一次產生50個累加指令</button><br> 目前待執行的指令數量<span id="waitRunS">0</span> <hr> <hr> </body> </html>
參考來源: http://itgroup.blueshop.com.tw/cwvdavid/pg?n=convew&i=246528
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言