我正在开发一个关于出价的网站,我正在使用倒数计时器,如果我的格式日期倒计时正常工作
$this.html(event.strftime('%D días %H:%M:%S'));
我在数据库中有一个数字,例如:120秒
如何更改格式以获取秒数?如果我只放了%S,他倒计时就不起作用了。
<script src="{{ URL::asset('js/jquery.countdown.js') }}" type="text/javascript"></script>
<script src="{{ URL::asset('js/jquery.countdown.min') }}" type="text/javascript"></script>
<script type="text/javascript">
$('[data-countdown]').each(function() {
var $this = $(this), finalDate = $(this).data('countdown');
$this.countdown(finalDate, function(event) {
$this.html(event.strftime('%D días %H:%M:%S'));
});
});
</script>
UPDATED2
代码工作正常,但我只能显示一个计时器,因为它是一个ID,我需要与.class一起使用。
我将document.getElementByID更改为document.getElementByClassName并且无法正常工作。
<script type="text/javascript">
function dateToHHMMSS(date) {
var hours = date.getHours() - 1;
var minutes = date.getMinutes();
var seconds = date.getSeconds();
if (hours < 10) {hours = "0"+hours;}
if (minutes < 10) {minutes = "0"+minutes;}
if (seconds < 10) {seconds = "0"+seconds;}
return hours+':'+minutes+':'+seconds;
}
function countdown(count) {
var start = new Date();
var end = new Date(start.getTime() + (count * 1e3)); // * 1e3 to get milliseconds
var intervalHandle = setInterval(function() {
var current = new Date();
var delta = new Date(end.getTime() - current.getTime());
$(".countdown").text(dateToHHMMSS(delta));
if(delta.getTime() <= 0) {
clearInterval(intervalHandle);
$(".countdown").text(dateToHHMMSS(delta));
}
}, 1e3);
}
$('[data-countdown]').each(function() {
var id = $(this).attr('data-countdown');
countdown(id);
});
</script>
UPDATED3
你好,另一次,当我显示console.log(id)时,我可以看到我收到的所有数字,但是当我使用倒计时(id)时,我只发送最后一个id。
$('[data-countdown]').each(function() {
var id = $(this).attr('data-countdown');
var export_data = [];
export_data.push(id);
$.each(export_data, function( index, value ) {
countdown(value);
});
});