-2

マウスアウトの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>
4

1 に答える 1

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);
于 2011-03-30T01:33:50.133 に答える