GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Sunday, December 19, 2010

Handle Javascript setTimeout

Here's a simple code to show setTimeout() without parameter:

<script>

var data = ["luna maya","lady gaga","aura kasih",
            "bill gates","steve jobs"];
var i = 0;

function show(){
    alert(data[i]);
    setTimeout("show()",2000);

    i++;
    if(i>=data.length){
        i = 0;
    }
}

show();
</script>

If there are some parameters, use this:

<script>

function show(code,desc){
    alert(code+': '+desc);
    setTimeout(function(){show(code,desc);}, 2000);
}

show(12,'holla world');

</script>

Share/Bookmark

No comments:

Post a Comment