2016-03-10 39 views
0

嗨我正在使用這個插件:http://hilios.github.io/jQuery.countdown/它計算從一個日期的時間。一切工作正常,除了我console.log .on('finish.countdown', function(event)我什麼也沒有得到。所以它似乎沒有用。有人能告訴我爲什麼嗎?也許可以修復?jQuery功能沒有傳遞完成倒計時

$(document).ready(function() { 
    $('table tr').each(function() { 
    var inputDate = new Date($(this).find('.count').text()); 
    var timeProduct = $(this).find('.timeProduct'); 
    timeProduct.html('Aktyvus'); 
    inputDate.setDate(inputDate.getDate() + 7); 

    $(this).find('.clock').countdown(inputDate, function(event) { 
     $(this).text(event.strftime('%D dienos %Hh %Mmin %Ssek')); 
    }).on('finish.countdown', function(event) { 
     var timeProduct = $(".timeProduct"); 
     timeProduct.removeClass("label label-success"); 
     timeProduct.addClass('label label-danger'); 
     timeProduct.html("Pasibaigė"); 
     console.log('labas'); 
    }); 

    }); 
}); 

編輯

這是的jsfiddle

https://jsfiddle.net/mo6fhum5/

你可以看到,當計時器命中0它仍然說aktyvus

+0

控制檯中的任何錯誤? – mplungjan

+0

不能@mplungjan – hulkatron

+0

你可以添加html代碼或jsfiddle版本來幫助你嗎? –

回答

0

試試這個

Fiddle

$('table tr').each(function(index) { 
    var inputDate = new Date($(this).find('.count').text()); 
    var timeProduct = $(this).find('.timeProduct'); 
    inputDate.setDate(inputDate.getDate() + 7); 
    timeProduct.html(inputDate.getTime()>new Date().getTime()?'Aktyvus':"Pasibaigė"); 

    console.log(inputDate) 
    $(this).find('.clock').countdown(inputDate, function(event) { 
    $parent=$(this).closest("tr"); 
    $(this).text(event.strftime('%D dienos %Hh %Mmin %Ssek')); 
    }).on('finish.countdown', function(event) { 
    console.log("done"); 
    var timeProduct = $parent.find(".timeProduct"); 
    timeProduct.removeClass("label label-success"); 
    timeProduct.addClass('label label-danger'); 
    timeProduct.html("Pasibaigė"); 
    }); 
}); 

活動:

enter image description here

完成 enter image description here

+0

仍然不能正常工作 – hulkatron

+0

適合我。我必須將最後的日期和時間更改爲較短的時間間隔。看圖片 – mplungjan

+0

看我的:http://imgur.com/obVUsZ0 – hulkatron