First, what is the JavaScript language:
JavaScript is a scripting language
JavaScript is a lightweight programming language.
JavaScript is a programmatic code that can be inserted into an HTML page.
When JavaScript is inserted into an HTML page, it can be performed by all modern browsers.
Second, JavaScript needs to know the three frames:
(1) alert ("") Pop-up window (warning box)
(2) Confirm ("") Confirmation box (Confirmation and Cancel button in box)
(3) Prompt ("",) Submit confirmation box (comma can enter a default value)
Three, the output statement:
(1) Console.log ("") can output messages on the console (press F12 on the Firefox or Google page to render the console).
(2) document.write ("") will appear directly on the page.
Iv. Definition of variables:
All variables are defined by VAR.
V. Data types in javascript:
(1) String type (String): The string is wrapped by "/".
(2) empty type (Nall)
(3) Unknown type (underfined)
(4) numeric type (number)
(5) Boolean value (Boolear)
(6) Complex objects (object)
You can use the statement typeof () to detect the type of data.
Six, the operators in javascript:
+ |
Add |
- |
Reducing |
* |
By |
/ |
Except |
% |
Find remainder (reserved integers) |
++ |
Accumulation |
-- |
Decline |
Seven, the assignment operator in javascript:
Operator is equivalent to
= |
|
+= |
X=x+y |
-= |
X=x-y |
*= |
X=x*y |
/= |
x=x/y |
%= |
X=x%y |
Eight, comparison operators and logical operators:
(1) Comparison operators:
"= =" equal "= = =" Absolute equals "! = "Not equal to"! = = "Absolutely not equal to
(2) Logical operators:
"&&" and "| |" or "! "Non-
Nine, the conditional operator (trinocular operator):
Grammar:
(conditions)? "Result of condition": "result when condition is not established"
eg
var age=prompt ("Please enter your age section");
Alert (age>=18)? "Adults, allow Internet access": "Minors, unable to access the Internet";
How to get the element content in javascript:
Get information by ID Name: document.getElementById (""). Innerhtml/innertext; where innerHTML to get all of the elements, including all the contents of the label, two innertext can only get the text information.
Get information by class name: Document.getelementsbyclassname ("") [].innerhtml/innertext;
Get information by tag name: Document.getelemenstbytag ("") [].value; value can get the information in the form.
In addition to obtaining information through the ID name, all that is left is to add an index value to the next bracket, and the first index value is [0].
11, JavaScript in the statement:
(1) If statement:
If statement -Use this statement to execute code only if the specified condition is true
If...else Statement -executes code when the condition is true and executes other code when the condition is false
if...else if....else Statement -Use this statement to select one of several code blocks to execute
switch Statement -Use this statement to select one of several code blocks to execute
(2) switch statement:
Switch statements are used to perform different actions based on different conditions
Eg: executing different blocks of code
Switch (n)
{
Case 1: Executing code block 1
Break
Case 2: Executing code block 2
Break
Default
N code that executes when it differs from Case 1 and 2
}
(3) Loop statement:
for-loop code block for a certain number of times
for/in -Looping through the properties of an object
While-loops the specified block of code when the specified condition is true
Do/while -also loops the specified block of code when the specified condition is true
12. JavaScript Events:
The onload and OnUnload events are triggered when the user enters or leaves the page.
The onchange event is triggered when a change occurs.
The onmouseover and onmouseout events can be used to trigger a function when a user moves the mouse over an HTML element or moves out of an element.
onfocus is triggered when the input field gets focus.
onmousedown and OnMouseUp triggered when the user holds down the mouse or releases.
13. The math function in javascript:
MATH.E constant
math.piπ (PI)
Math.Round () rounded to integer
Math.random () randomly generates a 0~1 decimal
Math.ceil () rounding up
Math.floor () Down rounding
Basic JavaScript Knowledge (December 3)