Jquery 倒计时结束时重定向到PHP页面

Jquery 倒计时结束时重定向到PHP页面,jquery,Jquery,下面是我在线测试项目中计时器的代码。我想在计时器结束时重定向到finish.php。我该怎么做 <!doctype html> <html> <head> <link href="http://www.jqueryscript.net/css/jquerysctipttop.css" rel="stylesheet" type="text/css"> <link

下面是我在线测试项目中计时器的代码。我想在计时器结束时重定向到
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>

$(函数(){
//默认设置
$(“#计时器倒计时”)。倒计时({
起始时间:60,//3分钟(3*60)
到:0,//在0处停止
movingUnit:1000,//1000表示1秒递增/递减
timerEnd:未定义,
outputPattern:“$hour:$minute:$second”,
自动启动:正确
} );
//计算
$(“#计时器倒计时”)。倒计时({
起:0,,
收件人:180
} );
//介于两者之间
$(“#计时器计数中间”)。倒计时({
起:30,,
收件人:20
} );
//计数器回调
$(“#计时器计数器回调”)。倒计时({
起:10,,
至:0,,
timerEnd:function(){
这个.animate({'opacity':.5},500).css({'text-
装饰“:”线穿过“});
} 
} );
//改变输出模式
$(“#计时器输出模式”)。倒计时({
outputPattern:“$day Days$hour Hours$minutes$Seconds”,
起始:60*60*24*3
} );
} );


下面是我在线测试项目中计时器的代码。我想在计时器结束时重定向到
finish.php
。如何执行此操作?

计时器结束时,
timerEnd
属性会调用一个函数。您可以将代码放入重定向页面的函数中。试试这个:

       <!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>
$('#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
});

我不知道您在代码中使用了哪个插件。但从我的角度来看,如果您使用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)

});

感谢

window.location.assign('finish.php')
在倒计时结束时,我应该将上述代码放在插件调用的任何属性的匿名函数中。请用代码回答我无法理解你所说的,但你的问题中没有给出足够的细节。告诉我们你正在使用什么插件会很有帮助。请任何人告诉我答案please@sriRory刚刚向你解释了答案,如果你只是想忽略它,甚至不想详细说明什么“不起作用”,人们将不会愿意帮助你
window.location.assign('SOMEURL')
将进行重定向。如果用任何页面替换
SOMEURL
,它将重定向。只要把那一行放在
后面,你就会看到它是如何重定向的。如果您的倒计时未达到
timerEnd
,则是另一个问题。