2012-06-10 58 views
0

這是我的jQuery倒計時代碼,當點擊事件是ID dlbtn觸發jQuery的不斷重定向OM倒計時

var settimmer = 0; 
$(function() { 
    $('#dlbtn').click(function() { 
     $('#dlnotify').toggle('slow'); 
     window.setInterval(function() { 
      var timeCounter = $("b[id=show-time]").html(); 
      var updateTime = eval(timeCounter) - eval(1); 
      $("b[id=show-time]").html(updateTime); 
      if (updateTime <= 0) { 
       window.location = ('/dl.php?fid=12'); 

       $('#dlnotify').hide(); 
      } 
     }, 500); 
     updateTime--; 
     return false; //Kill the Event after request 
    }); 

});​ 

我的劇本繼續打dl.ph頁

+0

重定向因爲錄入<0。能否請您發佈的HTML。 – lucuma

+0

當然繼承人鏈接http://www.game143.com/f/skfh4fcfb24ac018a/365-board-games/我使用== 0,但它顯示負值 –

+0

它倒計時,然後重定向到下載頁面。問題是什麼。 – lucuma

回答

0

我不是100%確定但是什麼這個問題是爲了消除setInterval你需要調用clearInterval

http://www.w3schools.com/jsref/met_win_setinterval.asp

嘗試這種合作德:

var settimmer = 0; 
$(function() { 
    $('#dlbtn').click(function() { 
     $('#dlnotify').toggle('slow'); 
     settimmer =window.setInterval(function() { 
      var timeCounter = $("b[id=show-time]").html(); 
      var updateTime = eval(timeCounter) - eval(1); 
      $("b[id=show-time]").html(updateTime); 
      if (updateTime <= 0) { 

       window.location = ('/dl.php?fid=12'); 
       clearInterval(settimmer); // clear the interval to avoid multiple redirects 
       $('#dlnotify').hide(); 
      } 
     }, 500); 
     updateTime--; 
     return false; //Kill the Event after request 
    }); 

});​