2011-03-30 16 views
-2

的setInterval鼠標移開時不工作,可以在任何幫助我,請 這裏是我的代碼如何在mouseout上設置setInterval jquery?

<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> 
+0

爲什麼用1個rep聲明對某人進行投票?投票關閉... – 2011-03-30 01:47:52

回答

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); 
+0

非常感謝 – bosko 2011-03-30 15:09:09