First, JS lazy loading
The code is as follows:
Copy the code code as follows:
<script language="JavaScript" src="" id="my"></script>
<script language="JavaScript">
setTimeout("document.getElementById('my').src='include/...file...php'; ",3000);//Delay 3 seconds
</script>
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:
Copy the code code as follows:
<SPAN class=spanclass id=AD_L4EVER>
Your JS code is here!</SPAN>
<script>L4EVER.innerHTML=AD_L4EVER.innerHTML;AD_L4EVER.innerHTML="";</script>
Third, JS is loaded last
Where you want your ad to appear
<div id="guangg1"></div>
The ad content you want to display
Copy the code code as follows:
<div id="ggad1" style="display:none">
<script language="javascript" src="/include/.....js"></script>
</div>
Determine whether the ad position to be displayed exists
Copy the code code as follows:
<script language="javascript">
function chkdiv(divid){
var chkid=document.getElementById(divid);
if(chkid != null)
{return true; }
else
{return false; }
} Finally, display ads
if (chkdiv('guangg1')) {
document.getElementById('guangg1').innerHTML= document.getElementById('ggad1').innerHTML;
document.getElementById('ggad1').innerHTML="";
}
</script>
setTimeout usage
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. The function has no parameters:
function alertV(){ alert("000"); }
When the first argument is unquoted ("" or ''), there is a one second delay:
setTimeout(alertV,1000);
When the first argument is quoted, there is a one second delay:
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.