倒数计时器PHP [英] Count down timer PHP
本文介绍了倒数计时器PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是PHP的新手,我在第一段代码中遇到问题,请协助我.我的页面上有一个倒计时计时器,它在Chrome和firefox上正确显示,但在IE和Safari上,它显示"NaNd NaNh NaNm NaNs" pleae help
以下是我的代码,谢谢.
我尝试过的事情:
i am new in PHP and i am having problem on my first block of code please assist me. I have a count down timer on my page, it displays correctly on Chrome and firefox but on IE and Safari it displays "NaNd NaNh NaNm NaNs " pleae help
below is my code, thank you in advance.
What I have tried:
Counter is below <!-- Counter will be inside this div form1 -->
<div id="form<?php echo $row[''id''];?>" style="color:green" class="form-
group">
</div>
<Script>
function createCountDown(elementId, date)
{
// Set the date we''re counting down to
var countDownDate = new Date(date).getTime();
// Update the count down every 1 second
var x = setInterval(function()
{
// Get todays date and time
var now = new Date().getTime();
// Find the distance between now an the count down date
var distance = (countDownDate) - (now);
//Hint on converting from object to the string.
//var distance = Date.parse(countDownDate) - Date.parse(now);
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the result in the element with id="demo"
document.getElementById(elementId).innerHTML = days + "d " + hours + "h "
+ minutes + "m " + seconds + "s ";
// If the count down is finished, write some text
if (distance < 0)
{
clearInterval(x);
document.getElementById(elementId).innerHTML = "ORDER EXPIRED";
}
}, 1000);
}
createCountDown(''form<?php echo $row[''id''];?>'', "<?php echo $row[''time_to_expire''] ;?>")
</Script>
推荐答案
row [''id''];?>"style =" color:green"class =" form- 组" </div> <脚本> 函数createCountDown(elementId,date) { //设置倒计时的日期 var countDownDate = new Date(date).getTime(); //每1秒钟更新一次计数 var x = setInterval(function() { //获取今天的日期和时间 var now = new Date().getTime(); //找到现在和倒计时日期之间的距离 var distance =(countDownDate)-(now); //从对象转换为字符串的提示. //var distance = Date.parse(countDownDate)-Date.parse(now); //时间计算的天,小时,分钟和秒 var days = Math.floor(距离/(1000 * 60 * 60 * 24)); var hours = Math.floor((距离%(1000 * 60 * 60 * 24))/(1000 * 60 * 60)); var minutes = Math.floor((距离%(1000 * 60 * 60))/(1000 * 60)); var seconds = Math.floor((距离%(1000 * 60))/1000); //将结果显示在id ="demo"的元素中 document.getElementById(elementId).innerHTML =天+"d" +小时+"h" +分钟+"m" +秒+"s"; //如果倒计时完成,请写一些文字 如果(距离< 0) { clearInterval(x); document.getElementById(elementId).innerHTML =订单已过期"; } },1000); } createCountDown(''form<?php echo
row[''id''];?>" style="color:green" class="form- group"> </div> <Script> function createCountDown(elementId, date) { // Set the date we''re counting down to var countDownDate = new Date(date).getTime(); // Update the count down every 1 second var x = setInterval(function() { // Get todays date and time var now = new Date().getTime(); // Find the distance between now an the count down date var distance = (countDownDate) - (now); //Hint on converting from object to the string. //var distance = Date.parse(countDownDate) - Date.parse(now); // Time calculations for days, hours, minutes and seconds var days = Math.floor(distance / (1000 * 60 * 60 * 24)); var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000); // Display the result in the element with id="demo" document.getElementById(elementId).innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s "; // If the count down is finished, write some text if (distance < 0) { clearInterval(x); document.getElementById(elementId).innerHTML = "ORDER EXPIRED"; } }, 1000); } createCountDown(''form<?php echo
row [''id''];?>'',,<?php echo
row[''id''];?>'', "<?php echo
row [''time_to_expire''];?>) </Script>
row[''time_to_expire''] ;?>") </Script>
这篇关于倒数计时器PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文