<html>
<title></title>
<script language=javascript>
    var x=0;
    var y=0;
    var xs=10;
    var ys=10;
    var one=document.getElementById("one");
   function move(){
      x+=xs;
      y+=ys;
      one.style.left=x;
      one.style.top=y;
  }
  function timer()
  {
    setinterval("move()",100);
  }
</script>
<body onload="timer()">
<div id="one" style="background:red;width:100px;height:100px;"></div>
</body>
</html>

解决方案 »

  1.   

    <html>
    <head>
    <title></title> <script type="text/javascript">
    function BodyOnLoad() {
    var x = 0;
    var y = 0;
    var xs = 10;
    var ys = 10;
    var one = document.getElementById("one");
    function move() {
    x += xs;
    y += ys;
    one.style.left = x + "px";
    one.style.top = y + "px";
    }
    (function timer() {
    setInterval(function() { move(); }, 100);
    //if()
    })();

    </script></head>
    <body onload="BodyOnLoad();">
    <div id="one"  style="background: red; width: 100px; height: 100px; position: absolute;left: 0px; top: 0px;">
    </div>
    </body>
    </html>