I. Features of Javascript script language
Javascript scripting is a browser-oriented web script. Programming Language . The script language has the following features:
1. Run the command on the client. It runs completely on the user's computer without going through the server.
2. Object-oriented. With built-in objects, you can also directly operate on browser objects.
3. Dynamic Changes. It can respond to user input or directly output to users.
4. Easy to use. Although the Javascript script language is simple, beginners can quickly master it.
5. It can only be used with the HTML language. You need to explain the execution in a browser.
2. How to add JavaScript scripts to HTML
The javascript format is as follows:
<Script language = "JavaScript">
Javascript statements
</SCRIPT>
Place the preceding statement between Example: "Hello!" is displayed on the webpage !".
<HTML>
<Body>
<Script language = "JavaScript">
Alert ("Hello! ")
</SCRIPT>
</Body>
</Html>
3. Execute the Javascript script directly in the browser address bar
You can also enter JavaScript statements in the address bar of the browser, which can be directly executed by the browser.
For example, enter javascript: Alert (200*75)
4. Call JavaScript files
You can save the pure JavaScript statement in another "*. js" file and call it if necessary.
Example: Call the test. js file and a prompt is displayed.
<HTML>
<Body>
Call the test. JS File
<Script language = "JavaScript" src = "test. js">
</SCRIPT>
</Body>
</Html>
The content of the test. js file is as follows:
Alert ("this is the called statement. ")
V. Comment statement
Use <! -...-> Indicates the annotation part, which is used as a description and not displayed by the browser. No.
In addition, the double slash "//" is a javascript comments statement, and the statements following it are not executed.
Vi. Use of Variables
Variable Declaration: var usename
Variable value: usename = "Li Guoqiang"
Example: "Hello, Li Guoqiang!" is displayed on the webpage !".
<HTML>
<Body>
<Script language = "JavaScript">
VaR usename
Usename = "wuyuan"
Alert (usename + "Hello! ")
</SCRIPT>
</Body>
</Html>
VII. Array
Array definition: var name = new array (5) uses new to generate an array.
Array Value assignment: name [1] = "marry"
Array initialization: var name = new array ("marry", "petty", "Mike", "jphn ")
Array reference: name [1]
Note: The first element of the array starts with 1.
8. Operators and expressions
1. Algebraic operators: Plus (+), minus (-), multiplication (*), Division (/), and remainder (% ).
2. Comparison operators: equal to (=) and not equal (! =), Greater than (>), less than (<), greater than or equal to (> =), less than or equal to (<= ).
3. logical operators: logical and (&), logical or (|), and logical non (!).
Expression: A sub-expression consisting of variables and operators. For example, usename + "Hello! "