0
我一直在我自己的costum的Javascript倒计时在站点中的多个倒计时,但日期不正确计算。多jQuery的倒计时显示的NaN
我有这个JavaScript用于显示时间计数器:
$(function(){
$('.countdown').each(function() {
var $this = $(this),
ts = new Date($this.data('ts')),
newYear = true;
if((new Date()) > ts){
newYear = false;
}
$this.countdown({
timestamp : ts,
callback : function(days, hours, minutes, seconds){
var message = "";
message += days + " hari" + (days==1 ? '':'') + ", ";
message += hours + " jam" + (hours==1 ? '':'') + ", ";
message += minutes + " menit" + (minutes==1 ? '':'') + ", ";
message += seconds + " detik" + (seconds==1 ? '':'') + " <br />";
$this.next().html(message);
}
});
});
});
这是我的表是什么样子:
id | tgl_close1 | idrek
1 | 2014-11-25 08:00:00 | 1
2 | 2014-11-26 10:00:00 | 1
3 | 2014-11-26 12:10:00 | 1
我用的foreach乘以倒计时,但它始终显示“男”,而不是数量:
<?php
$fetch = mysql_query("select tgl_close1
from tba
where idrek = 1");
/* Retrieve and store in array the results of the query.*/
while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)) {
$tgl_close1[] = date("Y, n-1, j, G, i, s", strtotime($row['tgl_close1']));
}
foreach ($tgl_close1 as $tglclose){
?>
<br>
<table border="0"><tr><td>
<div class="countdown" data-ts="<?php echo $tglclose"></div>
<p class="note"></p>
</td></tr></table>
<?php
}
}
mysql_close($conn);
?>
<script type="text/javascript">
$(function(){
$('.countdown').each(function() {
var $this = $(this),
ts = new Date($this.data('ts')),
newYear = true;
if((new Date()) > ts){
newYear = false;
}
$this.countdown({
timestamp : ts,
callback : function(days, hours, minutes, seconds){
var message = "";
message += days + " hari" + (days==1 ? '':'') + ", ";
message += hours + " jam" + (hours==1 ? '':'') + ", ";
message += minutes + " menit" + (minutes==1 ? '':'') + ", ";
message += seconds + " detik" + (seconds==1 ? '':'') + " <br />";
$this.next().html(message);
}
});
});
});
</script>
有人能告诉我我的代码有什么问题吗?
你试过用'parseFloat()'或'parseInt函数()'? (*您的问题是最有可能被串联它作为一个字符串,而不是将它们放在一起*) – Darren 2014-11-21 02:42:33
对不起,如果我做错了,但我想传递一个日期,是不是'parseInt函数()'或'parseFloat()'会采取错误的方式? – ryuusoultaker 2014-11-21 03:03:50