2016-01-13 30 views
2

在引導程序中,我使用了一個jquery倒計時插件,當時間等於00周00天時,我需要將我的類從label-default更改爲lable-danger。00: 00:00如何在jquery中更改倒數計時器的類,當它爲零時

<!--this element class i want to change--> 

<span id="sp-dt-<?php echo $row['id']; ?>" class="label label-default"></span> 

<!--This is my countdown plugin--> 
<script type="text/javascript"> 
    $('#sp-dt-<?php echo $row["id"]; ?>').countdown('<?php echo $expDate; ?>', function(event) {$(this).html(event.strftime('%w weeks %d days %H:%M:%S')); 
}); 

Screenshot

爲u可以在圖片中看到,當時間來到00周00天00:00:00我想從標籤dafault改變類標籤的危險

說明:

  • 我用getElementByIdjquery文件倒計時和 jquery CDN相互矛盾,因此給予「未捕獲的錯誤」。
  • 我也嘗試使用$('#sp-dt-<?php echo $row["id"]; ?>').val() = 00 weeks 00 days 00:00:00,但它不工作
+0

試試'$('#sp-dt - <?php echo $ row [「id」]; ')。')。text()==「00 weeks 00 days 00:00:00」' –

+0

[Jquery Countdown on finish callback]可能的重複(http://stackoverflow.com/questions/31182732/jquery-countdown- on-finish-callback) –

+0

你使用了什麼倒計時插件? – crashwap

回答

1

你可以試試下面的代碼

$('#sp-dt-<?php echo $row["id"]; ?>').countdown('<?php echo $expDate; ?>', function(event) 
    { 
     $(this).html(event.strftime('%w weeks %d days %H:%M:%S')); 
     //if remaining days are less then 4 weeks = 7*4 = 28 days 
     if (event.strftime('%D') <= 28 && event.strftime('%m') == 0 && event.strftime('%Y') == 0) { 
        $(this).addClass("four-weeks-remaining"); 
      } 
    }).on('finish.countdown', function() { 
      $(this).addClass("new-class"); 
    }); 
+0

感謝您的幫助。 – themesndesigns

+0

如果我想改變時間少於4周剩下的時間??? – themesndesigns

+0

我編輯了我的答案... pl。檢查 –

0

可以將此JavaScript添加到您的網頁:

<script type="text/javascript"> 
    $(function(){ 

     $('.label-default').each(function(){ 
      if ($(this).text() == '00 weeks 00 days 00:00:00'){ 
       $(this).addClass('label-danger').removeClass('label-default'); 
      } 
     }); 

    }); //END document.ready 
</script> 

jsFiddle Demo

+0

謝謝兄弟...非常感謝 – themesndesigns

+0

如果我想改變類不到4周,然後? – themesndesigns

+1

你應該接受這個問題的答案 - 已經回答了,並且解決方案做了你所問的。然後,發佈一個新問題,尋求額外的幫助。而不是一兩個人(我和Mayur)試圖幫助解決這個新問題,你會有數十個新人閱讀這個問題並試圖提供幫助 - 就在上半個小時內!如果新讀者從你的問題中學到了一些東西,你也會被高舉。 – gibberish