Current location - Trademark Inquiry Complete Network - Futures platform - How to delay js script in html for 5 seconds?
How to delay js script in html for 5 seconds?
Called through the setTimeout function. As follows:

setTimeout( function(){

//Add your code

}, 5 * 1000 ); //Delay 5000 mm

The first parameter of setTimeout () is a string containing JavaScript statements. The statement may be similar to "alert('5 seconds! ).) ",or call a function, such as alertMsg ()".

The second parameter indicates how many milliseconds from now before the first parameter is executed.

The extended data is delayed, and the specific example of using the setTimeout function is:

& lt scripting language = "javascript">

functional test

{

alert(obj);

setTimeout("test()", 1000);

}

& lt/script & gt;

& ltinput id = " test button " type = " button " onclick = " test(this)" & gt;

Test () in setTimeout has no parameters. The first time [object] is displayed, the display is undefined after 1000 milliseconds. The variable has not been assigned, which means that the method loop with parameters can be realized in this way, but the parameters are destroyed.

In fact, this is very simple and can be achieved without writing such a long code.

Refer to Baidu Encyclopedia -setTimeout