# JavaScript Summary
# # syntax
1. Case-sensitive
2. Naming conventions
1. The first letter must be the letter _ $
2. Other characters can be numeric letters underlined $
3. Avoid the system keywords
4. Word and Word connection method recommended hump naming
3. Notes
1. The contents of a single-line comment//comment
2. Multi-line Comment/* Comment content */
4. Statements
1. To use; End (Recommended practice)
2. if not written; Then the system defaults to line wrapping as the end of the statement
# # Variables/Constants
1. Variable declaration var
2. Constant Declaration const
# # Data type
1. typeof detection data type a=null;typeof A may be object for older browsers are function
2. Undefined
3. Null
4. Boolean
1. True/false
5. Number
1. Number (positive/negative/whole/small/0/infinity/-infinity)
2. NaN Nan==nan returns False
6. String
1. Use single or double quotation marks to define
2. escape character \ \ n \ r \ \ \ "
3. A string can be used to invoke the character of a string corresponding to its position by means of an array subscript
# # operator
1. Arithmetic operator: +-*/% + +--+ (positive)-(reverse)
2. String: +
3. Comparison operators: > < = = = = = =!== >= <=
4. Logical operators: && | | !
5. Bitwise operators: & | ^ XOR << >> <<< >>>
6. Ternary operator: Condition? Statement 1: Statement 2
7. Assignment: = with operation assignment: + = = *=/=%= |= &= ^= <<= >>= <<<= >>>=
8. Other operators:. , typeof delete instanceof void
# # Process Control Statements
# # Branch
# # # If statement
```
1. if (condition) {Execute ...}
2. if (condition) {...} Else{...}
3. if (condition) {...} else if (condition) {}
4. if (condition) {...} else if (condition) {}else{}
5. If statements can be nested in multiple layers
```
# # # switch statement
```
Switch (incoming value) {
Case Value:
Execute content ...;
Break
Case Value:
....
Break
Default
Perform.....
}
```
# # Cycle
# # # for
```
Statement 1 executes only 1 times
Executes statement 2 When statement 2 returns true to continue execution
for (statement 1; Statement 2; statement 4) {
Statement 3
}
```
# # # while
```
while (condition) {...}/condition for true execution
Do{...} while ()//execute once before judging if the condition is true to continue execution
```
# # # For...in
```
Iterating over an array or object
for (var i in obj) {
I represents the subscript key name for obj
Obj[i]//obj The value of subscript I
}
```
# # function (scope)
```
Function name () {
}
var variable name = function () {}
Call
Function name ()
Variable name ()
(function (formal parameter) {}) (actual parameter)
(function (formal parameter) {} (argument))
Inside the function there is a arguments that represents the argument object
```
# # Object
1. Object declaration
```
Array
var arr = [];
var arr = new Array ();
Object
var obj = {};
var obj1 = new Object ();
var obj2 = new Custom construction method ();
var obj = {"name1": "Zhangsan", Name2: "Lisi"}
```
2. Construction method
```
Construction method
function person (n) {
THIS.name = n| | ' Small white ';
This.say = function () {
Alert (this.name)
}
}
```
# # Built-in objects
# # # Boolean
# # # Date
```
getFullYear ()//year
GetMonth ()//month 0-11 current month requires +1
GetDate ()//day
GetDay ()//week 0~6 0 Sunday
GetHours ()//when
Getminutes ()//min
Getseconds ()//sec
Getmilliseconds ()//milliseconds
GetTime ()//timestamp millisecond level
ToString ()//output in string form
ValueOf ()//internal stored value
```
# # #
```
toString (binary)
ToFixed (n) displays N decimal places
Toexponential (n) displays n bits. Back number exponential notation
Toprecision (n) display n-bit
```
# # Math
```
Math.PI//3.1415926535
Math.Abs ()//Take absolute value
Math.ceil ()//into a rounding
Math.floor ()//Return to rounding
Math.max ()//maximum value
Math.min ()//Minimum value
Y power of Math.pow (x, y)//x
Random number of math.random ()//0~1
M~n random integers
Math.floor (Math.random () * (n-m+1)) +m//recommends using
Math.ceil (Math.random () * (n-m+1)) +m-1
Math.Round ()//round rounding
MATH.SQRT ()//Seek square root
```
# # String
```
Trim ()//clear blank on both sides
Find
CharAt ()//Gets the character at the specified position
charCodeAt ()//Gets the ASCII code for the character at the corresponding position
INDEXOF ("abc")//returns the position of the substring ABC in the first occurrence of the string
LASTINDEXOF ("abc")//returns the position of the substring ABC in the last occurrence of the string
Match (RegExp)//Find match for one or more regular expressions
Search (RegExp)//Find substrings that match regular expressions
Replace
Replace (expression, substituted string)//replaces a substring that matches a regular expression
Intercept
Split (regular expression, maximum length of the array)//used to split a string into a string array
Slice (startindex,endindex)//Returns a substring
SUBSTRING (STARTINDEX,ENDINDEX)//Returns a substring
SUBSTR (startindex,length)//Returns a substring
Transformation
toLowerCase ()//convert string to lowercase
toUpperCase ()//convert string to uppercase
```
# # REGEXP
```
EXEC ()//return matching content
Test ()//determine if match
```
# # Array
```
Add/Remove
Unshift ()//Add elements from the head of the array
Shift ()//delete an element from the head of the array
Push ()//Add from tail
Pop ()//eject an element from the tail
Splice ()//delete replace or insert array element
Intercept
Concat ()//merge array or element into a new array
Slice ()//returns part of the array
Formatting
ToString ()//output array as a string
Join ()//concatenate an array element with a character into a string
Reverse ()//reverse the order of elements in an array
Sort ()//Arrange the order of elements in an array
```
# # # Function (useless)
# # Global
```
parseint ()//cast to int
Parsefloat ()//forced newline into float
IsNaN ()//judging is not Nan
Isfinite ()//judging is not infinity
Eval ()//execute the string as a JS statement
Escape ()//code
Unescape ()//decoding
```
# # BOM
# # Location Object current document URL address object model
```
Jump page Settings location.href = ""
Protocal//protocol
Hostname//Host domain name
port//Port number
pathname//Path Plus file name
Search//get parameters? What's behind it?
hash//Anchor Point #后面的
href//Full URL address
Assign ()//Jump
Replace ()//replacement Jump
Reload ()//Refresh
```
# # # Navigator Browser Information
```
appcodename//Code Name
appname//Browser Name
AppVersion//Browser version number
language//language
platform//system
useragent//User Request Header
```
# # # Screen Browser information
```
width//Screen width
height//screen Height
Availwidth-Available screen widths
Availheight-The available screen height
```
# # # History visits Web pages
```
Back ()//back to previous URL
Forward ()//forward to next URL
Go (n)//jump to nth URL
```
# # Other
```
Alert ("text")//Warning box
Confirm ("text")//Confirmation box
Prompt ("text", "Default value")//Hint box
SetInterval ()
Clearinterval ()
SetTimeout
Cleartimeout ()
```
# # DOM
```
ALL[]//provides access to all HTML elements in the document.
forms[]//all form elements
images[]//all IMG Elements
links[]//all a elements
Node acquisition
getElementById ()//Get node by ID
getElementsByTagName ()//Get node by tag name
Getelementsbyname ()//Get node by Name property
Childnodeschildren
Firstchildfirstelementchild
Lastchildlastelementchild
Nextsiblingnextelementsibling
Previoussiblingpreviouselementsibling
Parentnodeparentelement
Get Properties
Attributes//attribute Collection
GetAttribute ("attribute name")//Get Property
SetAttribute ("Property name", "Property value")//Set Property
Node.removeattribute ("attribute name")//Delete property
ClassName
Node operations
Document.createelement ()//Create node
document.createTextNode ();//Create a text node
Parentnode.appendchild ()//Add node
Parentnode.insertbefore (Newnode,oldnode)//Add child nodes in front of XX node
Parentnode.replacechild (Newnode,oldnode)//Replace the XX node with the previous new node
Parentnode.removechild ()//Delete node
Easy access to content
node.innerhtml//Get everything inside the label
node.value//get the value of the form
```
# # Event
```
Mouse events
* onclick//Click
dblclick//Double-click
mousedown//Press the
mouseup//Lift Up
* mouseover//Move in
* mouseout//Move out
* mousemove//Mobile
contextmenu//right mouse button
Keyboard events
onkeydown//Press the
onkeyup//Press Up
onkeypress//triggered when the user taps the button
Document
* OnLoad Load
* Scroll scroll bar
Resize//Monitor browser window size change
Form
* * OnSubmit Submit Event
* Focus Gets the spotlight
* Blur loses focus
* Change Content changes
Onselect fires when text is selected in the element.
```
# # Event Object
```
OnXXX = function (ent) {
Get Event Object
var e = ent | | window.event;//compatibility processing
}
Properties of the Event object
Altkey returns whether "ALT" is pressed when the event is triggered.
The button returns which mouse button is clicked when the event is triggered.
* ClientX returns the horizontal coordinates of the mouse pointer when the event is triggered.
* ClientY returns the vertical coordinates of the mouse pointer when the event is triggered.
* PageX position relative to the page
* Pagey position relative to the page
Ctrlkey returns whether the "CTRL" key is pressed when the event is triggered.
Metakey returns whether the "meta" key is pressed when the event is triggered.
Relatedtarget returns the node associated with the target node of the event.
ScreenX returns the horizontal coordinates of the mouse pointer when an event is triggered.
ScreenY returns the vertical coordinates of the mouse pointer when an event is triggered.
Shiftkey returns whether the "SHIFT" key is pressed when the event is triggered.
* KeyCode Returns the ASCII code of the character
Cancel bubbling
e.cancelbubble = true| | E.stoppropagation ();
```
# # Ajax
# JavaScript Summary