如何在mouseout jquery上设置setInterval?

时间:2011-03-30 01:32:16

标签: jquery setinterval onmouseout

鼠标输出上的setInterval不工作可以帮助我 这是我的代码

<script type="text/javascript">
$(document).ready(function() {
$("#time").load("ajaxTime.php");

var refreshId = setInterval(function() {
$("#time").load('ajaxTime.php?randval='+ Math.random());
}, 1000);
 $('#stop').mouseover(function(){
    clearInterval(refreshId);
 });
  $('#stop').mouseout(function(){
    setInterval(refrashID, 1000);
 });
});

   </script>
        <center>
            <div id="stop" style="width:100px; height: 100px; border: 1px solid #000;">
                <div id="time"></div>
            </div>
        </center>

1 个答案:

答案 0 :(得分:0)

首先,您写了refrashID而不是refreshId。但是您需要将您想要的功能分配为变量,以便重复使用它:

var $interval_function = function() { $("#time").load('ajaxTime.php?randval='+ Math.random()); };

// then when you set the interval:
refreshId = setInterval($interval_function, 1000);

// clear the interval:
clearInterval(refreshId)

// and you have to store the new result from setInterval if you run it again:
refreshId = setInterval($interval_function, 1000);