本帖最后由 u014790351 于 2014-05-03 21:36:14 编辑

解决方案 »

  1.   

    用clearTimeout()模仿这个例子写吧
    http://www.w3school.com.cn/tiy/t.asp?f=hdom_timing_stop
      

  2.   

    给你
    var dom, x, y, finalx = 300,t;
    function initText() {
        debugger;
        dom = document.getElementById('theText').style;
    var x  = dom.left.replace('px','');
    moveText(x);
    }function moveText(x) {
    x++;
        if (x < finalx){
    dom.left = x + "px";
    t = setTimeout("moveText(" + x + ")", 1);
        }
        if (x == finalx){
    moveTextR(x); 
        }else {
    return false;
    }
    }function moveTextR(x) {
    if(x>=0){
        x--;
    dom.left = x + "px";
    if (x == 0) {       
    moveText(x);      
    }       
        t = setTimeout("moveTextR(" + x + ")", 1);    
    }   
    }function stopMove(){
        clearTimeout(t) 
    }
    <!DOCTYPE html>
    <html lang = "en">
      <head>
        <title> Moving text </title>
        <meta charset = "utf-8" />
        <style type = "text/css">
          #theText {position: absolute; left:0px; top:0px;
                    font: bold 1.7em 'Times Roman';
                    color: blue;}
        </style>
        <script type = "text/javascript"  src = "moveText.js">
        </script>
      </head>
      <body>
    <!-- The text to be moved -->
        <p>
          <span id = 'theText'> Jump in the lake!
          </span>
        </p>    <br /><br /><br /><br /><br /><br /><br /><br /><br />
        <br /><br /><br /><br /><br /><br /><br /><br /><br />
    <!-- Control Moving -->
        <input type="button" value="START MOVING" onclick="initText()">
        <input type="button" value="STOP MOVING" onclick="stopMove();"> 这里,求一个写一个停止移动文字的函数
      </body>
    </html>