1. Characteristics of JavaScript script language
JavaScript script language is a web script programming language for browsers. The script language has the following characteristics:
1. Executed on the client. Runs completely on the user's computer without going through the server.
2. Object-oriented. Has built-in objects and can also directly manipulate browser objects.
3. Dynamic changes. It can respond to user input or output directly to the user.
4. Simple and easy to use. Although the JavaScript scripting language is simple, beginners can quickly master it.
5. Can only be used with HTML language. To be interpreted and executed by the browser.
2. How to add JavaScript script to HTML
The format used by JavaScript is as follows:
Put the above statements in HTML's and between, or between and
.
Example: Display "Hello!" on the web page.
3. Execute JavaScript script directly in the browser address bar
You can also enter JavaScript statements in the browser's address bar and the browser will execute them directly.
For example, enter: javascript:alert(200*75)
4. Call JavaScript files
You can save pure JavaScript statements in a "*.js" file and call them when needed. call.
Example: Call the test.js file and display the prompt.
Calling the test.js file
The content of the test.js file is as follows:
alert("This is the called statement.")
5. Comment statement
Use
to represent the comment part, which is used for explanation and will not be displayed by the browser. It’s okay not to.
In addition, the double slash "//" is a JavaScript comment statement, and the statements following it will not be executed.
6. Use of variables
Declaration of variables: Var usename Assignment of variables: usename="Li Guoqiang"
Example: Display "Hello Li Guoqiang!" on the web page! .
7. Array
Definition of array: var name=new Array(5) Use new to generate an array.
Assignment of array: name[1]="Marry"
Initialization of array: var name=new Array("Marry","Petty","Mike","Jphn")
Reference of array :name[1]
Note: The first element of the array starts with 1.
8. Operators and expressions
1. Algebraic operators: addition ( ), subtraction (-), multiplication (*), division (/), remainder (%). <script> <BR>JavaScript 语句 <BR></script>2. Comparison operators: equal to (==), not equal to (!=), greater than (>), less than (<script> <BR>alert("你好!") <BR></script>=), less than or equal to (
3. Logical operators: logical AND (&&), logical OR (||), logical NOT (!). <script> <BR>Var usename <BR>usename="芜园" <BR>alert(usename + "您好!") <BR></script>Expression: a formula composed of variables and operators. Such as: usename "Hello!"