Javascript 如何在js中显示表中的倒计时 倒数计时器

Javascript 如何在js中显示表中的倒计时 倒数计时器,javascript,php,Javascript,Php,剩余时间: 功能计算(秒、num1、num2){ s=((数学层(秒/num1))%num2.toString(); if(引线零和s.长度

剩余时间: 功能计算(秒、num1、num2){ s=((数学层(秒/num1))%num2.toString(); if(引线零和s.长度<2) s=“0”+s; 返回“+s+”; } 函数倒计时(秒){ 如果(秒<0){ document.getElementById(“cntdwn”).innerHTML=FinishMessage; 返回; } DisplayStr=DisplayFormat.replace(/%%D%%/g,calage(secs,86400100000)); DisplayStr=DisplayStr.replace(/%%H%%/g,calage(secs,3600,24)); DisplayStr=DisplayStr.replace(/%%M%%/g,calage(secs,60,60)); DisplayStr=DisplayStr.replace(/%%S%%/g,calage(secs,1,60)); document.getElementById(“cntdwn”).innerHTML=DisplayStr; if(CountActive) setTimeout(“倒计时”(+(秒+计数步进器)+)”,SetTimeOutPeriod; } 功能putspan(背景色、前景色){ 文件。填写(“”); } if(typeof(BackColor)=“未定义”) BackColor=“绿色”; if(类型(前景色)=“未定义”) 前景色=“白色”; if(typeof(TargetDate)=“未定义”) TargetDate=“”; if(typeof(DisplayFormat)=“未定义”) DisplayFormat=“%%D%%天、%%H%%小时、%%M%%分钟、%%S%%秒。”; if(typeof(CountActive)=“未定义”) CountActive=true; if(typeof(FinishMessage)=“未定义”) FinishMessage=“竞标结束!”; if(类型(计数步进器)!=“数字”) CountStepper=-1; if(类型(引线零)=“未定义”) 前导零=真; CountStepper=Math.ceil(CountStepper); if(CountStepper==0) CountActive=false; var SetTimeOutPeriod=(Math.abs(CountStepper)-1)*1000+990; putspan(背景色、前景色); var dthen=新日期(TargetDate); var dnow=新日期(); 如果(计数步进器>0) ddiff=新日期(dnow dthen); 其他的 ddiff=新日期(dthen dnow); gsecs=数学地板(ddiff.valueOf()/1000); 倒计时(gsecs);


这实际上工作正常,但我希望我的倒计时显示在表中;第一行应该有
天小时分钟秒
,第二行应该有ovel.plz中的值帮助我克服这个问题

您是否正确地从您使用的网站复制了所有代码作为示例

返回此站点查看示例HTML和JS

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
        <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Countdown Timer</title>

</head>

<body>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("bidding", $con);

$result = mysql_query("SELECT * FROM bids WHERE id = 1");

$numrow = mysql_num_rows($result);

if ($numrow == 0)
{
die('No record found.');
}

$row = mysql_fetch_row($result);
echo "Description: " . $row[1] . "<br />";
$closedate = date_format(date_create($row[2]), 'm/d/Y H:i:s');
echo "Closing Date: " . $closedate;
?>
<p>Time Left:
<script>
function calcage(secs, num1, num2) {
 s = ((Math.floor(secs/num1))%num2).toString();
 if (LeadingZero && s.length < 2)
 s = "0" + s;
 return "<b>" + s + "</b>";
  }

  function CountBack(secs) {
   if (secs < 0) {
  document.getElementById("cntdwn").innerHTML = FinishMessage;

  return;
   }
DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));
DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));
DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));
DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));

document.getElementById("cntdwn").innerHTML = DisplayStr;
 if (CountActive)
setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);
}

function putspan(backcolor, forecolor) {
document.write("<span id='cntdwn' style='background-color:" + backcolor + 
            "; color:" + forecolor + "'></span>");
}

if (typeof(BackColor)=="undefined")
BackColor = "green";
if (typeof(ForeColor)=="undefined")
ForeColor= "white";
if (typeof(TargetDate)=="undefined")
TargetDate = "<?php echo $closedate ?>";
if (typeof(DisplayFormat)=="undefined")
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
if (typeof(CountActive)=="undefined")
CountActive = true;
if (typeof(FinishMessage)=="undefined")
FinishMessage = "Bidding closed!";
if (typeof(CountStepper)!="number")
CountStepper = -1;
if (typeof(LeadingZero)=="undefined")
 LeadingZero = true;


CountStepper = Math.ceil(CountStepper);
if (CountStepper == 0)
CountActive = false;
var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
 putspan(BackColor, ForeColor);
 var dthen = new Date(TargetDate);
 var dnow = new Date();
 if(CountStepper>0)
 ddiff = new Date(dnow-dthen);
else
ddiff = new Date(dthen-dnow);
gsecs = Math.floor(ddiff.valueOf()/1000);
 CountBack(gsecs);

</script>
</p>

</body>
</html>