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