以下是我的在线考试项目中的计时器代码。我想在计时器结束时重定向到finish.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
。我怎么能这样做?
答案 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
});
答案 1 :(得分:0)
我不知道你在代码中使用了哪个插件。但是从我的角度来看,如果你使用jquery倒计时插件,然后在完成时间后重定向,你可以通过添加on(&#重定向) 39; finish.countdown&#39;,函数(){});
如果需要,请尝试以下代码
$("#your_id").countdown({
//do something here
})
.on('finish.countdown',function(){
//redirect from here (document.location.href or whatever you want)
});
由于