1

I am trying to fire a function every 60 seconds.

Here is my current code:

<script>
$(document).ready(function() {
    setInterval(alertme, 600000);
});  

function alertme() {
    alert('1 minute has passed');
} 
</script>

For some reason the function alertme is not being called.

Any ideas why?

4

5 回答 5

3

Interval parameter in the setInterval function is in milliseconds.

So 1 minute = 60 sec = 60 * 1000 millisec = 60000 millisec

于 2012-10-30T13:30:47.263 回答
1

There are 1,000ms in a second, not 10,000. This will fire after 10 minutes, not 1.

于 2012-10-30T13:31:01.800 回答
1

60 seconds = 60000 ms not 600000

于 2012-10-30T13:31:32.987 回答
0

600000 isn't one minute...

setInterval is in milliseconds.

于 2012-10-30T13:31:08.110 回答
0

Here is correct code:

<script>
$(document).ready(function() {
    setInterval(alertme, 60000);
});  

function alertme() {
    alert('1 minute has passed');
} 
</script>
于 2012-10-30T13:35:08.693 回答