2013-02-03 43 views
0

我是JavaScript的新手,我負責一個在線測驗(html5代碼),它需要很長時間來執行「startgame」功能(構建100個問題的html)我。所以添加一個進度條,使用JQuery的簡單進度條不起作用

function startgame() 
    {  
    var progress=0; 
    for (index = 0; index < numberofquestions; index++) { 
    progress=index+"%"; 
    $("#progress-bar").css("width",progress); 
    ... 
    } 
    ...} 

和進度條是在HTML代碼中

<div id="progress-bar" style="width:0%; background:blue;opacity:1;height:25px;"/>` 

按預期其中工程一個div的id(所述條的寬度增大時)時我跨越了for循環,但是,如果我刪除了中斷點並運行(進度將保持在0%或者我停止調試點) 我也試過

document.getElementById("progress-bar").outerHTML='<div id="progress-bar"   style="width:'+progress+';background:blue;opacity:1; display:block; height:25px;"'+'/>'; 

更換 $( 「#進度條」),CSS( 「寬度」,進度)。 但結果與之前一樣

+0

''這需要很長時間才能執行「startgame」函數(爲100個問題構建html「你的優先級應該是優化這些附加內容100 questios,因爲它沒有那麼多的數據,它不應該需要很長時間,你需要一個進度條 – mikakun

回答

0

numberofquestions.length應該給你數組的整個長度numberofquestions。你錯過了所有的代碼,所以除了不能說...

+0

我的困難是讓進度條移動,for循環的迭代,謝謝 – Shawn1989