JS delayed loading (setTimeout) JS is loaded last_javascript skills
May 16, 2016 pm 06:23 PMFirst JS lazy loading
<script language="JavaScript" src="" id="my"></script>
<script>
setTimeout("document.getElementById('my').src='include/common.php'; ",3000);//Delay 3 seconds
</script>
Under normal circumstances, setTimeout is used to achieve
The second JS is loaded last
Insert the following code where JS needs to be inserted:
<SPAN id=L4EVER>LOADING...</SPAN>
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:
<SPAN class=spanclass id=AD_L4EVER><script src="1.js"></script></SPAN>
js code
<script>L4EVER.innerHTML=AD_L4EVER.innerHTML;AD_L4EVER.innerHTML="";</script>
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.

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Replace String Characters in JavaScript

Custom Google Search API Setup Tutorial

8 Stunning jQuery Page Layout Plugins

Improve Your jQuery Knowledge with the Source Viewer

10 Mobile Cheat Sheets for Mobile Development
