Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.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
Php javascript中刷新倒计时的问题_Php_Javascript - Fatal编程技术网

Php javascript中刷新倒计时的问题

Php javascript中刷新倒计时的问题,php,javascript,Php,Javascript,我的电脑倒计时了,但却无法刷新 代码: window.onload=function(){ idElement=“时间”; document.getElementById(ideElement).innerHTML= ""; setInterval(“document.getElementById(ideElement.innerHTML= ''", 1000); }; // ... 为什么不起作用?因为倒计时不是用javascript实现的,而是用php实现的。如果需要倒计时才能在客户机上工

我的电脑倒计时了,但却无法刷新

代码:

window.onload=function(){
idElement=“时间”;
document.getElementById(ideElement).innerHTML=
"";
setInterval(“document.getElementById(ideElement.innerHTML=
''", 1000);
};
// ...


为什么不起作用?

因为倒计时不是用javascript实现的,而是用php实现的。如果需要倒计时才能在客户机上工作,则需要在javascript中实现它或轮询服务器(不推荐


web是无状态的,这有什么意义吗?

尝试使用JavaScript编写的倒计时库,并从PHP将其参数化:

。如果外部站点宕机,这里关于StackOverflow的问题就没有那么有价值了。
window.onload = function() {
    idElement = "time";
    document.getElementById(idElement).innerHTML = 
        "<?php countdown(21,00,00,9,15,2012) ?>";

    setInterval("document.getElementById(idElement).innerHTML = 
        '<?php countdown(21,00,00,9,15,2012) ?>'", 1000);
};

// ...

<?php
    function countdown($godzina, $minuta, $sekunda, $miesiac, $dzien, $rok) {
        $target = mktime($godzina, $minuta, $sekunda, $miesiac, $dzien, $rok);
        $now = time();
        $sekundy = ($target - $now);
        // $sekundy =(int) ($sekundy) ;

        $check = 0;
        if ($sekundy > 0) {
            if ($check == 0) {
                if ($sekundy <= 10000) {
                    // zmien klase
                    $check = 1;
                }
            }
            $hours = floor($sekundy / 3600);
            $minutes = floor(($sekundy / 60) - ($hours * 60));
            $seconds = floor(($sekundy) - ($hours * 3600) - ($minutes * 60));


            if ($hours < 10) $hours = '0'.$hours;

            if ($minutes < 10) $minutes = '0'.$minutes;

            if ($seconds < 10) $seconds = '0'.$seconds;

            $all = $hours." : ".$minutes." : ".$seconds;
            echo $all;
        }
        else {
            echo "Aukcja zakończona!";
        }
    }
?>