我正在为我的网站制作倒数计时器,但无法让脚本正常工作。该脚本的创建者 PHP F1 无法提供帮助。
问题是:为什么目标日期 ( $targetDate
) 变量中的年份不能通过 HTML/JavaScript 实现?
我正在使用该mktime()
功能。无论我是将实际日期放入最后一个属性位置(年份)还是放入日期函数(就像我在下面的代码中所做的那样),我都无法让它正确显示前端。
无论如何,我都不是 PHP/JavaScript 专家,所以这似乎是一个非常菜鸟的问题,但如果有人能帮助我解决这个问题,我将不胜感激!
这是以下代码的实时实现:http: //tripdealio.com/countdown/countdown5.php
这是代码:
<?php
/* Define your target date here
$targetYear = 2011;
$targetMonth = 09;
$targetDay = 30;
$targetHour = 23;
$targetMinute= 59;
$targetSecond= 59;
End target date definition */
// Define date format
$dateFormat = "Y-m-d H:i:s";
$targetDate = mktime(23,59,59,09,30,date("Y"));
$actualDate = time();
$secondsDiff = $targetDate - $actualDate;
$remainingDay = floor($secondsDiff/60/60/24);
$remainingHour = floor(($secondsDiff-($remainingDay*60*60*24))/60/60);
$remainingMinutes = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60);
$remainingSeconds = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60));
$targetDateDisplay = date($dateFormat,$targetDate);
$actualDateDisplay = date($dateFormat,$actualDate);
?>
<!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>Max's Countdown System</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var days = <?php echo $remainingDay; ?>
var hours = <?php echo $remainingHour; ?>
var minutes = <?php echo $remainingMinutes; ?>
var seconds = <?php echo $remainingSeconds; ?>
function setCountDown ()
{
seconds--;
if (seconds < 0){
minutes--;
seconds = 59
}
if (minutes < 0){
hours--;
minutes = 59
}
if (hours < 0){
days--;
hours = 23
}
document.getElementById("remain").innerHTML = days+" days, "+hours+" hours, "+minutes+" minutes, "+seconds+" seconds";
setTimeout ( "setCountDown()", 1000 );
}
</script>
</head>
<body onload="setCountDown();">
<div id="container">
<div id="header"><div id="header_left"></div>
<div id="header_main">Max's Countdown System</div><div id="header_right"></div></div>
<div id="content">
<table class="countTable">
<tr><td>Target date:</td><td><?php echo $targetDateDisplay; ?></td></tr>
<tr><th colspan="2" id="remain"><?php echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes, $remainingSeconds seconds";?></th></tr>
<tr><td>Actual date:</td><td><?php echo $actualDateDisplay; ?></td></tr>
</table>
</div>
<div id="footer"><a href="http://www.phpf1.com" target="_blank">Powered by PHP F1</a></div>
</div>
</body>
</html>