JS delay loading (settimeout) JS final load _javascript tips

Source: Internet
Author: User
Tags setinterval

First JS delay loading

Copy Code code as follows:

<script language= "JavaScript" src= "id=" my "></script>
<script>
SetTimeout ("document.getElementById (' my '). src= ' include/common.php ';", 3000);/delay 3 seconds
</script>

In general, the use of settimeout to achieve
Second JS finally loaded
Insert the following code where you want to insert JS:
Copy Code code as follows:

<span id=l4ever>loading...</span>

Of course, that loading ... You can change your favorite small picture. It looks like an Ajax effect.
Then insert at the bottom of the page:
Copy Code code as follows:

<span class=spanclass id=ad_l4ever><script src= "1.js" ></script></SPAN>

JS Code
Copy Code code as follows:

<script>L4EVER.innerHTML=AD_L4EVER.innerHTML; Ad_l4ever.innerhtml= "";</script>


The standard syntax for settimeout is: settimeout (expression, time (milliseconds)) two parameters.

Here you'll note that the first parameter is called when a function is invoked, assuming that it is a functional.

1. Function No parameters:
function Alertv () {alert ("000");}

Delay one second when the first argument is not quoted ("" or "):
SetTimeout (alertv,1000);

Delay one second when the first argument is quoted again:
SetTimeout ("Alertv ()", 1000);


2. The function has the parameter:

function Alertv (event) {alert ("keycode=" +event.keycode);}

This should be set to:
settimeout (function () {ALERTV (event);},1000); Otherwise, you will be prompted for undefined parameters.

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); Perform a u every 5 seconds

If you call SetTimeout (' yourfunction () ', 5000) again in YourFunction (), you can complete a similar

The function of SetInterval (' yourfunction () ', 5000)

If there is a good way to do it, thank you for sharing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.