I have following javascript code. Its a timer code. Timer stops if quiz is 3 for 3 seconds and starts after 3 seconds for 20 seconds. But this code is not working for if quiz is anything else than 3. Can anyone help me with this?
<script type="text/javascript">
var days = 0
开发者_StackOverflow中文版var hours = 0
var minutes = 0
var seconds = 20
var delay_countdown = <?php echo ($quiz == 3) || 0 ; ?>;
function setCount ()
{
document.getElementById("remain").innerHTML = seconds+" seconds";
SD=window.setTimeout( "setCount()", 1000 );
if (delay_countdown) {
return
}
seconds--;
if (seconds < 0){
minutes--;
seconds = 59
}
if (minutes < 0){
hours--;
minutes = 59
}
if (hours < 0){
days--;
hours = 23
}
}
</script>
Your script works for me if $quiz is anything else than 3(if it's 3 delay_countdown will be true and you return the function on the 4th line).
Supply a different delay-time when delay_countdown is true:
SD=window.setTimeout( setCount, (delay_countdown)?3000:1000 );
and set delay_countdown
to false
before leaving the function:
if (delay_countdown) {
delay_countdown=false;
return;
}
精彩评论