One. Arrays
1. Terminating the Loop
A. Break terminates the entire loop, which jumps out of the loop body and executes statements outside of it.
B. Continue terminate the cycle and proceed directly to the next cycle
2. Arrays
Definition: Open a contiguous area in memory to store data.
Disclaimer: var arr = []; var arr = new Array ();
Length: No more than the maximum value is OK, no fixed length. Arr.length
Index: Base address + offset of array
Storage Type: Array elements can make any type
Assignment mode: arr[0] = 1; Arr[name] = "Tom", Arr.name = "Tom";
Two. Functions
1. The function name represents the address of the functions, and the value can be assigned to other variables.
2. The function name () indicates that the function is called.
3. js function call can be again before the function declaration.
4. If a function with the same function name is declared more than once, subsequent declarations will overwrite the previous.
5. If you declare more than one function with the same name but with a different number of passes, the first one will match the function with the same number of parameters.
If it is not found, then matching the number of arguments is greater than its function, if the match is not matched, it will match the function without parameters.
6. Understand the function's return value, the address of the function, and the declaration of the anonymous function.
7. Scope of functions
A. If you define a global variable first, and then define your own variable within the function, but with the same name, use the variable in the function class
The volume name is the variable declared within the function, and the full play variable is masked.
B. Mistaken thinking
<script>
var num = 1;
function func () {
alert (num);
var num = 2;
}
Func ();
alert (num);
</script>
At this point the result is: Undefined, 1.
Analysis reason: In the above point, it can be concluded that Num declared in func () will automatically mask num declared outside, but
Because the declaration is behind the execution alert (NUM), when alert, NUM is a variable that is undefined, the result of printing is undefined.
8. Transfer of parameters
A. The passed parameter can be a value or an address (such as an array name, pointer).
9. Return value
A. When the function executes to the return statement, the function ends execution and returns the value.
10. Constructors
A. Constructors cannot be called and must be executed when an object is created by the new operator.
B. The compiler defaults to providing a constructor with no parameters, which the user defines as an overload between the constructors with parameters.
C. This keyword: refers to the current object itself. such as var stu = new Student (); Here is the Stu.
D. Simple to understand is who called the constructor this is the representative of this who, this is also window. Such as:
<script>
var i = 0;
alert (this);
alert (THIS.I);
</script>;
The result entered is: Object Window, 0
Three. Bubbling and capturing
1. Bubbling and capturing
Bubbling process: Most inner object--the outermost object
Capture process: Outermost object--the inner object
For example:
<p> I am a fish </p>
<script>
var obj = document.getelementsbytagname (' P ') [0];
Bubble
Obj.addeventlistener ("click", Function () {
Alert ("Point A fish");
},false);
Window.addeventlistener ("click", Function () {
Alert ("point to Window");
},false);
Document.addeventlistener ("click", Function () {
Alert ("Point the Document");
},false);
Capture
Document.addeventlistener ("click", Function () {
Alert ("Point the Document");
},true);
Obj.addeventlistener ("click", Function () {
Alert ("Point A fish");
},true);
Window.addeventlistener ("click", Function () {
Alert ("point to Window");
},true);
</script>
The process of bubbling execution is: alert ("Point A Fish"),-->alert ("point the Document"),-->alert ("point to Window");
The execution of the capture takes the following sequence: Alert ("point to Window"),-->alert ("point to Document"),-->alert ("point A fish");
2. DOM Level 0
The program is processed by assigning to the corresponding event, which can be used in JavaScript or HTML
In javascript: Obj.onclick = function () {};
In HTML: <p onclick= "func ()" ></p>
3. Adding and Deleting events
I. Adding and releasing events in IE
Add Event: Obj.attachevent ("onclick", func);
Release event: Obj.dettchevent ("onclick", func);
Ii. adding and removing events in the DOM (DOM level 2)
Add Event: Obj.addeventlistener ("click", Func,boolean); Boolean:true--> capture Phase,false--> bubbling Event
Release event: Obj.removeeventlistener (' click ', Func,boolean);
III. Compatible Solutions
if (Document.addeventlistener) {
Obj.addeventlistener (' click ', Func,boolean);
}
else if (document.attachevent) {
Obj.attachevent ("onclick", func);
}
4. Event Object
I. When you create an event, a single Event object is generated, and the event object is destroyed when it is executed.
Ii. resolving event compatibility for IE and DOM
Event = Event | | window.event;
5. Event Type
I. Mouse events
Includes: Click,dblclick,mousedown,mouseout,mouseover,mouseup,mousemove
II. Keyboard events
Includes: keydown,keyup,keypress
Iii. HTML events
Includes: Locd,select,change,scroll,focus,blur ...
Four. BOM and Dom
BOM Object
1. All objects are child objects of window
2. Sub-object of window: Document Frames History Location Navigator Screen
3. Sub-object of document: Anchors Forms images Links location
BOM function:
1. Ability to eject new browser window
2. Move, close, and change the browser window size
3. Navigation objects that provide detailed information about the Web browser
4. Local object that provides detailed information about the page that the browser loads
5. A Screen object that provides detailed information about the user's screen resolution
6. Support for Cookies
7. Under IE, you can use JS to implement the ActiveX object class
Timer:
1. Timed execution (only once)
A. SetTimeout (function name, MS);
B. Clear the timer var timer = setTimeOUt (func,time); Cleartimeout (timer);
2. Continuous execution (infinite execution)
A. SetInterval (Func,time);
B. Clear (same as settimeout)
3. Imitate setinterval with settimeout
Using recursive methods, the function constantly calls itself to execute repeatedly.
function func () {
document.write ("Timer");
SetTimeout (func,1000);
}
Func ();
Opening and closing windows
1. Opens the window open (url,window.name,size (position), Boolean if Window.name is an existing window, true. otherwise false)
2. Close the window window.close ();
Access the specified URL (window.location)
1. Location.href = "Http://www.baidu.com"
Access History (Window.history)
1. Return to previous page history.back ();
2. Access the next page, before you must use the back or go History.foward ();
3. Forward and backward how many pages history.go (num), NUM is forward, negative is back
Dom
1. Properties and methods of the node
NodeName: node Name
NodeValue: Node value
NodeType: Node type
ChildNodes: Node List
First node in Firstchild:childnodes
Last node in Lastchild:childnodes
PreviousSibling: Previous sibling node
NextSibling: After a sibling node
AppendChild (node): Adding node nodes at the end of ChildNodes
InsertBefore (new,ref): Inserting the new node before ref
RemoveChild (node): Removing node nodes
ReplaceChild (New,old), new---old replacement node
2. Constants and values for the type of the node
Node Type type constant value
A. Element node Node.element_node 1
B. Attribute node Node.attrbute_node 2
C. Text Node Node.text_node 3
3. Create a Node
A. Creating an element node
Createlement ("div");
B. Creating a text node
Createlement ("text");
4. Adding nodes
A. AppendChild (node)-Add a node at the end of ChildNodes
B. InsertBefore (NEW,REF)-Add the new node before the REF node
5. Enter in HTML will also count as a node (#text)
Five. Ajax
1. It's all a routine Ajax.
I. Creating XML
var xhr = null;
if (window. XMLHttpRequest) {
XHR = new XMLHttpRequest ();
}
else{
XHR = new ActiveXObject ("Microsoft.XMLHTTP");
}
II. Open link
/*
-type:post/get
-url
-boolean:true Asynchronous, false synchronous
*/
Xhr.open (Type,url,boolean);
Iii. binding synchronization function (triggered after a successful send request)
Xhr.onreadystatechange = function () {}
Iv. Sending requests
Xhr.send (NULL);
JavaScript Basics Summary