Chapter I JavaScript basics

Source: Internet
Author: User

Chapter I JavaScript basics one. Introduction to JavaScript 1. Why learn JavaScript?

JavaScript plays a very important role in Web page making, which can realize

A) Customer form verification

B) page Dynamic effect

C) JavaScript is the basis of jquery

2. What is JavaScript

JavaScript is a descriptive language and is a scripting language that is object-based and event-driven (driven) and has security performance.

Together with HTML (Hypertext Markup Language), it links multiple objects in a single Web page, interacting with Web object implementations. JavaScript programs are downloaded to the browser's client, both on the client and server side, to reduce the burden on the server.

3. Features of JavaScript

1) JavaScript is primarily used to add interactive behavior to HTML pages

2) JavaScript is a scripting language, and syntax is similar to Java

3) JavaScript is typically used to write client-side scripts

4) JavaScript is an explanatory language that changes execution side interpretation

4. The composition of JavaScript

A complete JavaScript consists of three different parts, each of which is:

(1) ECMAScript

ECMAScript is an open, internationally accepted, standard scripting language specification. It is not bound to any specific browser. The ECMAScript standard mainly describes the following:

1). Syntax

2). Variables and data types

3). operator

4). Logical Control Statements

5). keywords, reserved words

6). Object

(2) Browser object model BOM (browers)

Provides an object independent of the content and browser window interaction, using the browser model can be used to interact with HTML, such as the common web pop-ups, forward and backward functions.

(3) Document Object Model DOM

The Document Object model, the DOM, is a standard set of methods defined by the HTML Document Object Model (HTML DOM) that is used to access and manipulate HTML documents, such as those common in online shopping malls that display large pictures with mouse movements, pop-up tips, etc.

Two. Basic structure of JavaScript basic structure 1.javaScript

The basic structure of JavaScript is as follows:

<script type= "Text/javascript" >

JavaScript statement;

</script>

2.javaScript Principle of execution

1) The browser client sends a request to the server, and a user enters the page to be accessed in the address bar of the browser (the page contains a JavaScript program).

2) Data processing: The server side processes a page that contains JavaScript.

3) Send response: The server sends the HTML file processing page containing JavaScript to the browser client, and then the browser client parses the HTML tag and JavaScript from top to bottom, and renders the page to the user.

3. Benefits of using client-side scripting:

1) pages containing JavaScript can only be downloaded once, which may reduce unnecessary network traffic.

2) The JavaScript program is executed by the browser client, not by the server side, thus alleviating the stress on the server side.

4. Precautions:

A ) If you do not use <script> tag, the browser will add JavaScript The statement is treated as plain text, which means that the command itself is written on the page.

B ) <script>...</script> location is not fixed and can be contained anywhere in the document, as long as the code is guaranteed to be read and loaded into memory before it is used.

Three. Three ways to reference JavaScript in the page 1. Internal JavaScript files

is to add JavaScript code directly to the HTML document using the <script> tag, which is the most common way.

However, this approach is usually only applicable to fewer JavaScript code, and each page in the site uses a different JavaScript code.

2. Using an external JavaScript file

Using an external JavaScript file, you can reuse it on multiple pages. Reduced code redundancy with the use of the same JavaScript page.

The external JavaScript file is written to an external file by writing the JavaScript code to: file name. JS is saved for the extension, and the file path is assigned to the "src" attribute in the <script> tag, which references the external JS file.

3. Directly in the HTML tag

Sometimes it is necessary to add short JavaScript code to the page to achieve a simple page effect, such as a single button popup dialog box.

Cases:

<input name= "btn" type= "button" value= "Pop-up message box" onclick= "JavaScript":

Alert= "(' Welcome you ')"/>

Then when you click the pop-Up message box button, the prompt dialog box "welcome You" pops up.

Summary: Through the above three ways to know the application of the situation:

>>: internal JavaScript file for JavaScript The effect code is small, only for a single page.

>>: External JS The file applies to the Code More , and repeatedly applied to multiple pages.

>>: write JavaScript directly in the label is suitable for very little code, only for the current label, but this way adds HTML code, so this approach is rarely used in real-world development.

Chapter I JavaScript basics

Related Article

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.