Home  >  Article  >  Web Front-end  >  JS delayed loading (setTimeout) JS is loaded last_javascript skills

JS delayed loading (setTimeout) JS is loaded last_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:23:051325browse

First JS lazy loading

Copy code The code is as follows:

ee78624f1f3677904a20c1623bdd64442cacc6d41bbb37262a98f745aa00fbf0
3f1c4e4b6b16bbbd69b2ee476dc4f83a
setTimeout("document.getElementById('my').src='include/common.php'; ",3000);//Delay 3 seconds
2cacc6d41bbb37262a98f745aa00fbf0

Under normal circumstances, setTimeout is used to achieve
The second JS is loaded last
Insert the following code where JS needs to be inserted:
Copy code The code is as follows:

4fe8949561ac5b6018d714fc91002a35LOADING...0fe0b7695b8025b8365ca0c050e039db

Of course, that LOADING... you can change it to a small picture you like. It looks very AJAX effective.
Then insert at the bottom of the page:
Copy code The code is as follows:

75716d883ff5d326b7c73a4d4591ce6c82aa3526d91a1e63399c31e3e88e82b62cacc6d41bbb37262a98f745aa00fbf00fe0b7695b8025b8365ca0c050e039db

js code
Copy code The code is as follows:

3f1c4e4b6b16bbbd69b2ee476dc4f83aL4EVER.innerHTML=AD_L4EVER.innerHTML;AD_L4EVER.innerHTML="";2cacc6d41bbb37262a98f745aa00fbf0


The standard syntax of setTimeout is: setTimeout(expression, time (milliseconds)) two parameters.

Here, focus on the call when the first parameter is a function, assuming it is a function.

1. Function without parameters:
function alertV(){ alert("000"); }

When the first parameter is not quoted ("" or ''), there is a one second delay:
setTimeout(alertV,1000);

When the first parameter is quoted, delay for one second:
setTimeout("alertV()",1000);


2. The function has parameters:

function alertV(event){ alert("keyCode=" event.keyCode); }

At this time it should be set to:
setTimeout(function(){alertV(event);},1000); Otherwise, it will prompt that the parameter is undefined.
setTimeout(function () {
    $("#id").html(datastr);
  }, 1000);

jquery is implemented through delay, such as

$("#id").delay(1000).html(datastr);

setTimeout('yourFunction()',5000); Execute yourFunction() after 5 seconds, only once
setInterval('yourFunction()',5000); Execute u
every 5 seconds
If setTimeout('yourFunction()',5000) is called again in yourFunction(), you can complete something similar to

The function of setInterval('yourFunction()',5000)

If anyone has a better and feasible method, thank you for sharing.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn