2015-10-08 33 views
-3

以下是我的在線測試考試項目中計時器的代碼。當計時器結束時,我想重定向到finish.php。我怎樣才能做到這一點?倒計時結束後重定向到PHP頁面

 <!doctype html> 
     <html> 
     <head> 

    <link href="http://www.jqueryscript.net/css/jquerysctipttop.css" 

    rel="stylesheet" type="text/css"> 
    <link href='http://fonts.googleapis.com/css?family=Open+Sans' 

     rel='stylesheet' type='text/css'> 
     <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> 
     <script src="src/jquery.missofis-countdown.js"></script> 

     <script type="text/javascript"> 
     $(function() { 
// default setup 
    $('#timer-countdown').countdown({ 
    from: 60, // 3 minutes (3*60) 
    to: 0, // stop at zero 
    movingUnit: 1000, // 1000 for 1 second increment/decrements 
    timerEnd: undefined, 
    outputPattern: '$hour : $minute : $second', 
    autostart: true 
    }); 
// count up 
    $('#timer-countup').countdown({ 
    from: 0, 
    to: 180 
    }); 
// count in-between 
    $('#timer-countinbetween').countdown({ 
    from: 30, 
    to: 20 
    }); 
// counter callback 
$('#timer-countercallback').countdown({ 
    from: 10, 
    to: 0, 
     timerEnd: function() { 
     this.animate({ 'opacity':.5 }, 500).css({ 'text- 
     decoration':'line-through' }); 
    } 
    }); 
    // changed output patterns 
    $('#timer-outputpattern').countdown({ 
    outputPattern: '$day Days $hour Hours $minute Miniuts $second Seconds', 
    from: 60 * 60 * 24 * 3 
    }); 
     }); 
    </script> 
    </head> 
    <body> 


    <p class="timer-holder"><span id="timer-countdown"></span></p> 







    </body> 
    </html> 

以下是我的在線考試考試項目中計時器的代碼。當計時器結束時,我想重定向到finish.php。我怎樣才能做到這一點?

+2

'window.location.assign( 'finish.php')' –

+0

我應該把上面的代碼? – sri

+0

在倒計時結束時爲插件調用的任何屬性提供的匿名函數。 –

回答

2

timerEnd屬性採用一個函數,當定時器結束時調用該函數。你可以把代碼放在那個重定向頁面的函數中。試試這個:

$('#timer-countdown').countdown({ 
    from: 60, // 3 minutes (3*60) 
    to: 0, // stop at zero 
    movingUnit: 1000, // 1000 for 1 second increment/decrements 
    timerEnd: function() { 
     window.location.assign('finish.php'); 
    }, 
    outputPattern: '$hour : $minute : $second', 
    autostart: true 
}); 
+0

不,它不起作用 – sri

+0

請有人告訴我答案請 – sri

+1

@sri羅裏只是解釋了你的答案,如果你只是要忽略它,甚至不想詳細說明什麼是「不工作」,人們不會願意幫助你。 'window.location.assign('SOMEURL')'將進行重定向。如果您用任何頁面替換「SOMEURL」,它將重定向。只需在'

0

我不知道哪個插件你已經在你的code.But從我的角度使用,如果您使用的jQuery插件倒計時,然後整理時間後重定向,您可以通過添加重定向on('finish.countdown',function(){});

剛剛嘗試下面的代碼,如果你想

$("#your_id").countdown({ 
    //do something here 
}) 
.on('finish.countdown',function(){ 

    //redirect from here (document.location.href or whatever you want) 

}); 

感謝