duanre4421 2018-11-14 01:30
浏览 50
已采纳

PHP / Javascript倒计时计时器脚本

I have IRC channel's stats web page which updates every 15 minutes.
I want to display live countdown on web page that links in with my server unix time and goes from 15:00 minutes down to 00:00 and then starts again at 15:00 minutes.
If the web page is refreshed, the timer must not refresh back to 15:00.

I have searched on internet & tried so many scripts but only found countdown's that count to a particular date in the future .
then found the followin solution but I am getting error "Uncaught SyntaxError: Unexpected token < "

How do I fix this error or is there any other script/way?
I would really appreciate it if someone help me out, thank you.
P.S: I am sorry if I made any mistake as this is my first post on stackoverflow.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
#time {
 }
</style>

<? 
$currenttime = time(); 
$mins = date('i', (15 * 60) - ($currenttime % (15 * 60))); 
$secs = date('s', (15 * 60) - ($currenttime % (15 * 60)));
$usercount = date('i:s', (15 * 60) - ($currenttime % (15 * 60)));
?>
<script type="text/javascript">
var m = <? echo "$mins"; ?> ;
var s = <? echo "$secs"; ?> ;
window.onload=function() {
   fifteenMinutes();
 }
function fifteenMinutes(){
   s--;
if(s<0) {
   s=59;
   m--;
 }
if(m==-1) {
   m=14; #
 }
if(m<10) {
   mins='0'+m;
 }
else {
   mins=m;
 }
if(s<10) {
   secs='0'+s;
 }
else {
   secs=s;
 }
   document.getElementById('time').firstChild.nodeValue=mins+':'+secs;
   cd=setTimeout('fifteenMinutes()',1000);
}
</script>
</head>
<body>
<div id="time"> <? echo "$usercount"; ?>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • drox90250557 2018-11-14 01:44
    关注

    This is not valid javascript, which is why you are getting a syntax error:

    var m = <? echo "$mins"; ?> ;
    var s = <? echo "$secs"; ?> ;
    

    Neither is this (remove the #):

    m=14; #
    

    Instead, use <?php, like so:

    var m = <?php echo "$mins"; ?> ;
    var s = <?php echo "$secs"; ?> ;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站