Features of JavaScript scripting language
The JavaScript scripting language is a browser-oriented web script programming language. Scripting languages have the following features:
1, in the client implementation. Run completely on the user's computer without having to go through the server.
2, object-oriented. has built-in objects, or you can manipulate the browser object directly.
3, dynamic change. You can respond to user input, or you can output directly to the user.
4. Simple and easy to use. JavaScript scripting language is simple, but beginners can quickly grasp it.
5, can only be used with the HTML language. To interpret execution through a browser.
Second, how to add JavaScript script in HTML
JavaScript takes the following format:
<script language= "JavaScript" >
JavaScript statements
</Script>
Put the above statements between the Example: Show "Hello!" on the Web page. ”。
<body>
<script language= "JavaScript" >
Alert ("Hello!") ")
</script>
</body>
C. Execute JavaScript script directly in the browser address bar
You can also enter JavaScript statements in the browser's address bar, which are executed directly by the browser.
such as input: Javascript:alert (200*75)
Four, call JavaScript file
You can save pure JavaScript statements in a separate "*.js" file, which is called again.
Example: Invoke the Test.js file to display a hint.
<body>
Call Test.js File
<script language= "JavaScript" src= "Test.js" >
</script>
</body>
The contents of the Test.js document are as follows:
Alert ("This is the statement being invoked.) ")
V. Comment statements
Use the <!-...-> to represent the annotation section as an explanation, and the browser is not displayed. No, you can.
In addition, the double slash "//" is a JavaScript annotation statement that follows the statement that is not executed.
Vi. Use of variables
Variable's declaration: Var Usename
Assignment of variables: usename= "Li Guoqiang"
Example: Display on the Web page "Li Guoqiang Hello!" ”。
<body>
<script language= "JavaScript" >
Var Usename
Usename= "The Garden of the turnip"
Alert (usename + "Hello!") ")
</script>
</body>
Seven, array
Array definition: var name=new array (5) uses new to generate an array.
Assignment of an array: name[1]= "Marry"
Initialization of arrays: Var name=new array ("Marry", "petty", "Mike", "JPHN")
Array references: name[1]
Note: The first element of the array starts with 1.
Viii. Operators and expressions
1, algebraic operators: plus (+), minus (-), multiply (*), in addition to (/), take the remainder (%).
2. Comparison operators: equals (= =), not equal to (!=), greater than (>), less than (<), greater than or equal (>=), less than or equal (<=).
3. Logical operators: Logic and (&&), logic, or (| | ), logical non (!).
Expression: A formula that consists of a variable and an operator. such as: Usename + "Hello!" "
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.