0
嗨 我已經創建了在線測驗。我添加了倒數計時器,問題的標籤& radiobuttonlist的答案和下一個問題的下一個按鈕。我有定時器的代碼,但是當我點擊下一個按鈕時,這個定時器會重新開始,因爲我想倒計時器的整個問題(測驗)。 倒計時代碼(JavaScript)的如下:關於(倒計時)在asp.net中應用的計時器c#
var hour=0; //specify hours for counter
var min= '<%= Session["timer"] %>'; // specify minutes
var second = '<%= Session["second"] %>'; // specify the seconds
var lab = 'cd'; // id of the entry on the page where the counter(for question) is to be inserted & cd is span id in aspx page where i am displaying countdown timer
function start()
{
displayCountdown(setCountdown(hour,min,second),lab);
}
loaded(lab,start);
var pageLoaded = 0;
window.onload = function() {pageLoaded = 1;}
function loaded(i,f)
{
if (document.getElementById && document.getElementById(i) != null)
f();
else if (!pageLoaded)
setTimeout('loaded(\''+i+'\','+f+')',100);
}
function setCountdown(hour,min,second)
{
if(hour>0)
min=min*hour*60;
c = setC(min,second);
return c;
}
function setC(min,second)
{
if(min>0)
second=min*60*second;
return Math.floor(second);
}
function displayCountdown(countdn,cd)
{
if (countdn < 0)
{
document.getElementById(cd).innerHTML = "Sorry, you are too late.";
__doPostBack('__Page');
}
else
{
var secs = countdn % 60;
if (secs < 10)
secs = '0'+secs;
var countdn1 = (countdn - secs)/60;
var mins = countdn1 % 60;
if (mins < 10)
mins = '0'+mins;
countdn1 = (countdn1 - mins)/60;
var hours = countdn1 % 24;
document.getElementById(cd).innerHTML = hours+' : '+mins+' : '+secs;
setTimeout('displayCountdown('+(countdn-1)+',\''+cd+'\');',999);
}
}
希望你知道,JavaScript可以輕易無法...確保在服務器端進行驗證。 – 2011-04-12 13:09:43