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: