2011-11-02 106 views
0

我在IE8和下面有一個奇怪的問題,那就是我的倒計時只會觸發一次,而現在的瀏覽器中卻不會發生。有沒有什麼辦法解決這一問題?謝謝!目標是在選擇輸入後開始倒數計時。IE中的jQuery倒計時功能

代碼:

$("input").focus (function counter() { 
    $("input").unbind('focus', counter); 
    var count = 60; 
    countdown = setInterval(function(){ 
    $(".clock p").html(count); 
    if (count == 0) { 
     $(".while-ticking").fadeOut(1000); 
     $(".countdown-finished").fadeIn(1000); 
    } 
    else { 
     count--; 
    } 
    }, 1000); 
}); 

回答

0

試試這樣說:

$("input").focus(function() { counter(60) }); 

function counter(count) { 
    $("input").unbind('focus'); 
    setTimeout(function(){ 
     $(".clock p").html(count); 
     if (count == 0) { 
      $(".while-ticking").fadeOut(1000); 
      $(".countdown-finished").fadeIn(1000); 
     } 
     else { 
      counter(count--); 
     } 
    }, 1000); 
} 

編輯: 您需要創建倒計時一環。所以我basicly就開始與60等一下,並與59 ..等等,等等再後來回憶功能時,它的0它不調用函數了,所以它stopt

編輯: 我有測試它下面,它的工作:)倒計時非常好

<script type="text/javascript" src=".............../jquery-1.4.4.min.js"></script> 
<script type="text/javascript"> 

    $(document).ready(function() { 

     $("input").focus(function() { counter(60) }); 

    }); 

    function counter(count) { 
     $("input").unbind('focus'); 
     $(".clock p").html(count); 
     setTimeout(function(){ 
      if (count == 0) { 
       $(".while-ticking").fadeOut(1000); 
       $(".countdown-finished").fadeIn(1000); 
      } 
      else { 
       console.log(count--); 
       counter(count--); 
      } 
     }, 1000); 
    } 

</script> 


<input type="text" /> 

<div class="clock"> 
    <p></p> 
</div> 
+0

仍然無法正常工作,但無論如何感謝。有什麼建議麼? – user1023552

+0

嘗試我最後一次編輯...關於取消綁定重點 –

+0

我已測試過,請參閱上次編輯 –