1. Add JavaScript to the Web page
The first approach: write JavaScript code directly into an HTML document
<script></script>
The second approach: writing JavaScript code to a separate file
<script src= "File path" ></script>
For example:
<script src= ". /mycode.js "></script>
<script src= "Http://www.xxx.com/.../mycode.js" ></script>
2. JavaScript statements
JavaScript internal statements end with each statement ";"
To improve the readability of the code, in general, write only one statement per line
JavaScript comment statements are commonly used in two ways:
Single-line Comment
/* is commented
Lost content */
3. Variables
There are no strict rules for the naming of variables but we generally use only letters, numbers, dollar sign $ and underscores, and the style is usually camel (capitalized)
Definition: We use the keyword var to declare a variable
var Netprice;
Netprice = 8.99;
can be written
var netprice = 8.99;
If you want to assign a string to a variable, you need to quote the string in double or single quotes.
var stringname = "Xiangcunjiaoshihujin";
4. Operator
(1) Arithmetic operators
Plus +
Reduction
By
Remove
Residual%
Self-increment + +
Self-reduction--
(2) Operator precedence
Generally according to the operator priority level to
(3) + addition operation on both sides of the left is a string so the addition operation represents the connection operation
var name = "Xiaohu"; var =+ age);
Will eventually get results displayed on the screen xiaohu22
5. Mouse events
Onclicks event handler (mouse click Trigger)
<input type= "button" onclick= "alert (' is ok! ')" Value= "click Me"/>
When the mouse click on this button will pop up is ok!
OnMouseOver (mouse entry Trigger)
onmouseout (mouse off trigger)
JavaScript creates a simple script