日期:2014-05-16  浏览次数:20398 次

求高手看看这段代码!为什么在不同浏览器运行出错

为什么这段代码,在ie下运行出错,在其他浏览器运行没有问题,请高手指点下!

ie下错误提示如下:


行: 60
错误: 缺少函数


JScript code


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> 小球游戏 </title>
    <script type="text/javascript">
    
    var seconds=20;
    var tep_x=1;
    var tep_y=1;
         function move(){
              tep_x++;
              tep_y+=1;
              var img=document.getElementById("myimg");
              var left=img.style.marginLeft;
              var top=img.style.marginTop;
              if(left=="135px"){
                    if(top=="0px"){
                         //小球到达顶部
                         alert("小球到达顶部");
                    }else if(top<="185px" && top>"0px"){
                       //小球撞到右边的墙
                        // alert("小球撞到右边的墙");
                         window.clearInterval(intval);                           
                    }
              }
              
               left=parseInt(left.substr(0,left.length-2));
               top=parseInt(top.substr(0,top.length-2));
               img.style.marginLeft=(left+tep_x)+"px";
               img.style.marginTop=(top-tep_y)+"px";
              tep_x=0;
              tep_y=0;
         }

         var intval= window.setInterval("move()",seconds);
         function start(){
           intval= window.setInterval("move()",seconds);
        }
        
          function stop(){
          window.clearInterval(intval);    
        }
    </script>

 </head>

 <body>
  <div id="divid" style="width:150px; height:200px; border:1px #FFCC66 solid">
   <img src="1.gif" id="myimg" style=" witdth:15px; height:15px;margin-left:50px; margin-top:185px;"> 
  </div>
   <input type="button" value="开始" onclick="start()">

  <input type="button" value="结束" onclick="stop()">

 </body>
</html>





------解决方案--------------------
JScript code


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

 <head>
  <title> 小球游戏 </title>
    <script type="text/javascript">
    
    var seconds=20;
    var tep_x=1;
    var tep_y=1;
         function move(){
              tep_x++;
              tep_y+=1;
              var img=document.getElementById("myimg");
              var left=img.style.marginLeft;
              var top=img.style.marginTop;
              if(left=="135px"){
                    if(top=="0px"){
                         //小球到达顶部
                         alert("小球到达顶部");
                    }else if(top<="185px" && top>"0px"){
                       //小球撞到右边的墙
                        // alert("小球撞到右边的墙");
                         window.clearInterval(intval);                           
                    }
              }
              
               left=parseInt(left.substr(0,left.length-2));
               top=parseInt(top.substr(0,top.length-2));
               img.style.marginLeft=(left+tep_x)+"px";
               img.style.marginTop=(top-tep_y)+"px";
              tep_x=0;
              tep_y=0;
         }

         var intval= window.setInterval("move()",seconds);
         function startMove(){
           intval= window.setInterval("move()&