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