<body>
    <script language ="javascript" >
    
    function malis()
    {       this .x=0;
            this.y=0;
      
            this.show =function(dds)
            {
            switch (dds)
            {   case('1'):
                var picture=document.getElementById ("picture");
                //window .alert (mali .style.height  );
                var lefts=picture.style.width  ;
                lefts=parseInt (lefts .substr(0,lefts .length-2));
              
              picture .style.left=(lefts +100)+"px";
               
               break :
            }
     }          
     var qq=new malis ();
            
        
      
    function ss(dds)
    {
      switch (dds)
       {
       case ('1'):
       qq.show(dds);
       break 
       }
    }
       
    </script>
     <table class ="table1" border :1px>
    <tr align=center ><td colspan =3>游戏控制中心</td></tr>
    <tr><td>**</td><td><input type="button" value ="向上移动"/></td><td>**</td></tr>
    <tr><td>**</td><td></td><td><input type="button" value ="向右移动" onclick ='ss(1)' /></td></tr>
    </table>
    <div class ="div1">
    <img  class ="img1"src ="image/122.gif" id ="picture" style ="top :50px;left :80px; width :50px;height :40px;position :absolute ;"/>
    </div>
   
 
</body>
</html>
那位高手看看这段代码的结果,我试了试结果是单击一下图片只移动一下,然后再单击就不移动了,不知那处出现问题?

解决方案 »

  1.   

    <body>
      <script language ="javascript" >
        var qq=new malis ();
      function malis()
      { this .x=0;
      this.y=0;
        
      this.show =function(dds)
      {
      switch (dds)
      { case 1:
      var picture=document.getElementById ("picture");
      //window .alert (mali .style.height );
      var lefts=picture.style.left+'';
      lefts=parseInt (lefts.substring(0,lefts.length-2));
        
      picture.style.left=(lefts +100)+"px";
        
      break;
      }
      }   
      
      }
        
        
        
      function ss(dds)
      {
      switch (dds)
      {
      case 1:
      qq.show(dds);
      break; 
      }
      }
        
      </script>
      <table class ="table1" border :1px>
      <tr align=center ><td colspan =3>游戏控制中心</td></tr>
      <tr><td>**</td><td><input type="button" value ="向上移动"/></td><td>**</td></tr>
      <tr><td>**</td><td></td><td><input type="button" value ="向右移动" onclick ='ss(1)' /></td></tr>
      </table>
      <div class ="div1">
      <img class ="img1"src ="image/122.gif" id ="picture" style ="top :50px;left :80px; width :50px;height :40px;position :absolute ;"/>
      </div>
        
     
    </body>
      

  2.   


    var lefts=picture.style.left应该用left值而你之前写的是width,用的是宽了
      

  3.   


    picture.style.left=(lefts +100)+"px";左移:改成-100就行了~·