javascript里面一个永恒的循环PHP代码不起作用

时间:2014-10-21 14:01:39

标签: javascript php

<html>
    <head>
    </head>
    <body>
        <div>
            <object width="100%" 
                    height="100%" 
                    id="liveTV_api" 
                    name="liveTV_api" 
                    data="http://www.extratv.gr/media/imgs/flowplayer-3.2.15.swf"    type="application/x-shockwave-flash">
               <param name="allowfullscreen" 
                      value="true">
               <param name="allowscriptaccess" 
                      value="always">
               <param name="quality" 
                      value="high">
               <param name="bgcolor" 
                      value="#000000">
               <param name="flashvars" 
                      value="config={&quot;clip&quot;:{&quot;url&quot;:&quot;mpegts_256.stream&quot;,&quot;provider&quot;:&quot;rtmp&quot;,&quot;live&quot;:true,&quot;scaling&quot;:&quot;fit&quot;},&quot;plugins&quot;:{&quot;rtmp&quot;:{&quot;url&quot;:&quot;http://www.extratv.gr/media/imgs/flowplayer.rtmp-3.2.11.swf&quot;,&quot;netConnectionUrl&quot;:&quot;rtmp://213.16.167.186:1935/live&quot;,&quot;subscribe&quot;:true}},&quot;playerId&quot;:&quot;liveTV&quot;,&quot;playlist&quot;:[{&quot;url&quot;:&quot;mpegts_256.stream&quot;,&quot;provider&quot;:&quot;rtmp&quot;,&quot;live&quot;:true,&quot;scaling&quot;:&quot;fit&quot;}]}">
            </object>
            <img id="adtv" src="img.png">
      </div>
<?php
set_time_limit(0);
$x=1;
while(x==1) {
   $now = date('G',time());
   $start = 12;
   $end = 13;

  if($now >= $start && $now <= $end):
     echo '<script type="text/javascript">document.getElementById("adtv").style.display="none"; </script>';
     echo '<script type="text/javascript">document.getElementById("liveTV_api").style.display="block"; document.getElementById("adtv").style.display="none";</script>';

   else:
     echo '<script type="text/javascript">document.getElementById("adtv").style.display="block"; document.getElementById("liveTV_api").style.display="none";</script>';
   endif;

   sleep(3600);
}

?>

    </body>
</html>

好的我需要一个程序,在一天内1小时将显示1小时长度的视频,然后在接下来的23小时内显示图像。 视频工作正常,但在视频div处于活动状态时,图像也会显示而不是隐藏。似乎js根本不起作用,我不知道为什么。

1 个答案:

答案 0 :(得分:0)

仅使用Javascript,我还没有测试过:

<html>
<head>
</head>
<body>
<div>
<object width="100%" height="100%" id="liveTV_api" name="liveTV_api" 
data="http://www.extratv.gr/media/imgs/flowplayer-3.2.15.swf" type="application/x-shockwave-flash"><param 
name="allowfullscreen" value="true"><param name="allowscriptaccess" value="always"><param name="quality" 
value="high"><param name="bgcolor" value="#000000"><param name="flashvars" value="config={&quot;clip&quot;:{&quot;url&quot;:&quot;mpegts_256.stream&quot;,&quot;provider&quot;:&quot;rtmp&quot;,&quot;live&quot;:true,&quot;scaling&quot;:&quot;fit&quot;},&quot;plugins&quot;:{&quot;rtmp&quot;:{&quot;url&quot;:&quot;http://www.extratv.gr/media/imgs/flowplayer.rtmp-3.2.11.swf&quot;,&quot;netConnectionUrl&quot;:&quot;rtmp://213.16.167.186:1935/live&quot;,&quot;subscribe&quot;:true}},&quot;playerId&quot;:&quot;liveTV&quot;,&quot;playlist&quot;:[{&quot;url&quot;:&quot;mpegts_256.stream&quot;,&quot;provider&quot;:&quot;rtmp&quot;,&quot;live&quot;:true,&quot;scaling&quot;:&quot;fit&quot;}]}"></object>
<img id="adtv" src="img.png">
</div>

<script type="text/javascript">

function update() {
    var now = (new Date()).getHours(),
      start = 12,
      end = 13;

    if(now >= start && now <= end) {
        document.getElementById("adtv").style.display="none";
        document.getElementById("liveTV_api").style.display="block";
    }
     else {
        document.getElementById("adtv").style.display="block";
        document.getElementById("liveTV_api").style.display="none";
    }
}

// repeat interval in milliseconds
window.setInterval(update, 3600000);

update();

</script>

</body>
</html>