JavaScript Drop Location Differences

Source: Internet
Author: User

JavaScript Drop Location Differences

The script in the page executes immediately after the page is loaded into the browser. We don't always want that. Sometimes we want to execute the script when the page is loaded, and in the other case we want the script to execute when the user triggers the event.script in the head section: The script is executed when the script is called, or when the event is triggered. When you put the script in the Head section, you can ensure that it is loaded before you need to use the script. ........
script in the body section: The script is executed when the page is loaded. When you place the script in the body section, it generates the contents of the page. ....
in the body and head section of the script: you can place any number of scripts in the document, so you can either place the script in the body or place it in the head section. ........
using external JavaScript Sometimes, you might want to run JavaScript on several pages without writing the same script on each page. for this purpose, you can write JavaScript into an external file. Then save the file with a. js suffix. Note:external files cannot contain In short:
    • If you put it in the head, it will be loaded first when the page is initialized.
    • If placed inside the body, and so on the page initialization completes, only then to load.

Reference: http://blog.sina.com.cn/s/blog_54c367d4010179ks.html

JavaScript Drop Location Differences

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.