JavaScript - jQuery interval

后端 未结 5 1106
执笔经年
执笔经年 2020-12-10 04:20

I am using JavaScript with jQuery. I have the following script to alert hi every 30 seconds.

$(document).ready( function() {
    alert(\"hi\");
         


        
5条回答
  •  星月不相逢
    2020-12-10 04:52

    Well, there probably is a way of doing it in just one call..

    setInterval(
        (function x() {
            alert('hi');
            return x;
        })(), 30000);
    

    Another solution would be to use arguments.callee, but as it is now deprecated, it is generally not recommended to use it.

    setInterval(
        (function() {
            alert('hi');
            return arguments.callee;
        })(), 30000);
    

提交回复
热议问题