dopod0901 2017-06-19 18:09
浏览 30

Javascript适用于HTML,但不适用于PHP

Code runs perfectly in HTML file, but when used in PHP file the javascript seems to be the only thing that fails. Does anyone know a reason why?

This code is supposed to make a appear after a certain amount of time with out mouse movement. if the user moves their mouse, the will .fadeOut();. However if the user doesn't move the mouse, then they are redirected to another url after a few more seconds.

 <html>
 <head>

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
 <script type="text/javascript">
 $('#showdiv').fadeOut();

 var timedelay = 1;
 function delayCheck()
 {
 if(timedelay > 5)
 {
 $('#showdiv').fadeIn();
     if(timedelay == 12)
         {
                window.location = "https://www.google.com";
         }  
 timedelay = timedelay+1;
 }

 $(document).mousemove(function() {
 $('#showdiv').fadeOut();
 timedelay = 1;
clearInterval(_delay);
 _delay = setInterval(delayCheck, 900);
 });
  // page loads starts delay timer
 _delay = setInterval(delayCheck, 900)

  </script>

  <style type="text/css">
 #showdiv{
 width: 450px;
 border-radius: 10px;
 padding: 50px;
 border: 2px double gray;
 position: absolute;
    top: 40%;
    left: 40%;
 }

 </style>

 </head>
 <body>
      <div id="showdiv">
          <h2>
             You will be redirected in a few second unless you move your mouse.
          </h2>
       </div>
 </body>

</html>
  • 写回答

2条回答 默认 最新

  • douci1196 2017-06-19 18:13
    关注

    You gotta understand that JavaScript is usually executed at the user's browser while php is usually executed in the server.

    However, if you want to embed JavaScript on a php file, you can still do so after the last ?> php tag.

    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集