我想知道如何将毫秒添加到我的 JS 测验计数器。此时,测验本身只计算并查找秒数(在 mysql 中是秒数,例如:120(2 分钟),显示为 02:00)。现在我想添加毫秒。提前致谢
这是脚本:
<script type="text/javascript">
var quiz_timer = 0;
$(window).load(function(){
setInterval('run_timer()',1000 )
})
function run_timer()
{
quiz_timer++;
if(quiz_timer > 60)
{
sec = quiz_timer%60;
min = Math.floor(quiz_timer/60);
}
else
{
sec = quiz_timer;
min = 0;
}
var timer='';
if(min < 10)
timer = '0';
timer += min;
timer += ':';
if(sec < 10)
timer += '0';
timer += sec;
var timer_h = 'Time: '+timer;//+rand();
$('#quiz_timer').html(timer_h);
$('#quiz_time').val(quiz_timer);
}
function update_quiz()
{
var cnt_questions = parseInt($('#cnt_questions').val());
var cq = parseInt($('#current_question').val());
var op = $('#question_'+cq).find('input[type=radio]:checked').length;
if(op == 0)
{
alert('You must answer on the question.');
return false;
}
if(cq < cnt_questions)
{
$('#question_'+cq).hide();
$('#question_'+(cq+1)).fadeIn(1000);
$('#current_question').val(cq+1);
return false;
}
$(window).unbind('beforeunload');
document.frm_quiz.submit();
}
</script>
这是在mysql中输入数据的函数:
function timer($quiz_timer)
{
if($quiz_timer > 60)
{
$sec = $quiz_timer%60;
$min = floor($quiz_timer/60);
}
else
{
$sec = $quiz_timer;
$min = 0;
}
$timer='';
if($min < 10)
$timer = '0';
$timer .= $min;
$timer .= ':';
if($sec < 10)
$timer .= '0';
$timer .= $sec;
return $timer;
}