2011-05-30 28 views
1

我的JavaScript函數要求定義變量,通過測驗問題來移動用戶,增加或減少數字並達到總量,稍後在HTML中調用形成。所有工作都在進行,但不是以客戶端結果結束的循環,而是在屏幕上閃爍並消失,就好像腳本正在等待用戶再次開始問題一樣。我是否認爲問題出現在JavaScript循環中?感謝:Javascript循環沒有停止..我的結果在一秒鐘之後消失

var max_points = 28; 
var total_points = 0; 
var percentage_addiction = 0; 

var reloadVar = "yes"; 

function makeChanges(currentQuestion, nextQuestion, points){ 
//display only needed question 
document.getElementById(currentQuestion).style.display="none"; 
document.getElementById(nextQuestion).style.display="block"; 

//add total points 
total_points = total_points + points; 

//show image that corresponds to points 
for(var i = 0; i < 15; i++) 
{ 
    if((total_points > i*2) && (total_points <= (i+1)*2)) 
    { 
     //hide image that was shown previously 
     document.getElementById('img' + i).style.display="none"; 

     //display image that corresponds points 
     document.getElementById("img"+(i+1)).style.display="block"; 
    } 
} 

percentage_addiction = Math.floor((total_points/max_points)*100); 

if(nextQuestion == "result") 
{ 
    document.getElementById("code").style.display="block"; 
    //document.form1.percentage.value=escape(document.percentage); 
    location.replace('http://URL?percentage='+percentage_addiction+'&end=yes&oneSubmit=yes'); 
} 

//update percentage in page 
document.getElementById('percentage').innerHTML = percentage_addiction; 
document.getElementById('percentage2').innerHTML = percentage_addiction; 
} 


function submitForm(){ 
document.form1.submit(); 
} 
+0

你是否用FireFox FireBug檢查循環?如果沒有,請檢查它。 – 2011-05-30 08:03:23

+0

我已經檢查了Firebug中的腳本,但承認我沒用時試圖調試..不知道我在找什麼.. – tuwhey 2011-05-30 08:13:19

回答

0

顯示結果後重定向自動運行:

location.replace('http://URL?percentage=' + percentage_addiction + '&end=yes&oneSubmit=yes'); 

這是造成結果的第二條子後消失。將其刪除或將其綁定到文檔中的按鈕或鏈接。

相關問題