How JavaScript code is applied to Web pages

Source: Internet
Author: User

In today's Web pages, JavaScript is used quite extensively, which makes the Web page more interactive. JavaScript simplifies regular, repetitive HTML paragraphs and reduces download time. JavaScript can respond to the user's action in time, even if the submission of the form of the inspection, no waste of time to CGL verification. The features of JavaScript are endless, as long as you are creative. So what is the use of JavaScript in a Web page, and let me be specific about that.

There are two ways to add JavaScript to a Web page:

  1, directly add HTML documents

This is the most common approach, and most Web pages that contain JavaScript use this approach, such as:

!--

Document.writeln ("This is javascript! Use the direct insertion Method! ");

-javascript End-->

In this example, we can see a new tag: , and

HTML annotation Tags!--and-->: Used to remove JavaScript source code that the browser does not recognize, which is useful for browsers that do not support JavaScript language.

-javascript end: The double slash represents the annotation portion of JavaScript, where characters from//start to end of line are ignored. The document.write () function used in the program means that the text in parentheses is exported to the window. Another point to note is that is not fixed and can be included in ... or ... Anywhere in the .

  2. Reference mode

If you already have a JavaScript source file (with JS extensions), you can use this reference to increase the utilization of your program's code. The basic format is as follows:

The URL of which is the address of the program file. Similarly, such statements can be placed in the head of an HTML document or in any part of the body. If you want to achieve the effect of the example shown in direct Insert, you can first create a JavaScript source code file, "Script.js," which reads as follows:

Document.writeln ("This is javascript! Use the direct insertion Method! ");

In a Web page, you can call a program like this:

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.