Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 多个Jquery倒计时显示NaN_Javascript_Php_Jquery_Mysql - Fatal编程技术网

Javascript 多个Jquery倒计时显示NaN

Javascript 多个Jquery倒计时显示NaN,javascript,php,jquery,mysql,Javascript,Php,Jquery,Mysql,我一直在为我自己的costum Javascript倒计时工作,在网站上进行了多次倒计时,但日期没有正确计算 我有一个用于显示时间计数器的javascript: $(function(){ $('.countdown').each(function() { var $this = $(this), ts = new Date($this.data('ts')), newYear = true; if((new Date(

我一直在为我自己的costum Javascript倒计时工作,在网站上进行了多次倒计时,但日期没有正确计算

我有一个用于显示时间计数器的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);
            }
        });
    });

});
我用foreach乘以倒计时,但它总是显示'NaN'而不是数字:

<?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>



好吧,我将我的javascript更改为:

$(function(){

    $('.countdown').each(function() {
        var $this = $(this),
            ts = new Date($('.note').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);
            }
        });
    });

});
$(函数(){
$('.countdown')。每个(函数(){
变量$this=$(this),
ts=新日期($('.note')。数据('ts')),
新年=真;
如果((新日期())>ts){
新年=假;
}
这个,倒计时({
时间戳:ts,
回调:函数(天、小时、分钟、秒){
var message=“”;
消息+=days+“hari”+(days==1?'':'')+“,”;
消息+=hours+“jam”+(hours==1?'':'')+“,”;
消息+=minutes+“menit”+(minutes==1?'':'')+“,”;
消息+=seconds+“detik”+(seconds==1?“”:“”)+“
”; $this.next().html(消息); } }); }); });

它将日期传递到javascript中,但传递到javascript中的
$tglclose
只是第一行,因此我有三个计数器和同一个时间计数器。

您是否尝试过
parseFloat()
parseInt()
?(您的问题很可能是将其连接为字符串,而不是将它们添加在一起)如果我弄错了,我很抱歉,但我想传递一个日期,
parseInt()
parseFloat()
会出错吗?
$(function(){

    $('.countdown').each(function() {
        var $this = $(this),
            ts = new Date($('.note').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);
            }
        });
    });

});