JavaScript consists of ECMAScript: the core part as an interpreter. There is almost no compatibility issue with Dom:document Object Model, which operates the entry of HTML pages. Some operations are not compatible. Bom:browser Object Model, and browser-related operations. is completely incompatible. The variable type variable itself does not have a type, depending on what type is stored internally. Type cast cast: parseint (), parsefloat (). Implicit type conversion: = = comparison, the conversion type is then compared, the subtraction operation, only for the number subtraction, so it will be converted before the calculation. Variable scope
Local variables, global variables.
Closed Package
A child function can use a local variable in the parent function.
Naming conventions Hungarian nomenclature:. Type prefix,. First letter uppercase. JSON is used to store data such as Var json={a:12,b:5,c: ' abc '}; Take out data: (JSON.A) or json[' a ']json without the length attribute, looping through for...in. The function returns a value of 1. Returns the result of the function execution 2. There can be no return, return UNDEFINED3. A function has only one return value arguments: The number of arguments is variable arguments is an array, there is a argumemts.length attribute to the non-inline style between the lines: for example-- -->odiv.style.width; non-inline: currentstyle
ODiv.currentStyle.width; compatible with IE only, other browsers (including IE9) with getComputedStyle (odiv,anything,width);
A function encapsulated into a get style
function getStyle(obj,name){ if(obj.currentStyle) { return obj.currentStyle[name]; } else { return getComputedStyle(obj,anything,name); }}
Gets the compound style, for example:background, need to be specific toA single style, for example: background-color; array definition: var a=[1,2,3];var a=new Array (All-in-one), array method: Add, Push (): Adds a value to the end of the array. Pop (): Deletes a value at the tail. Shift (): Removes a value from the head. Unshift (): Added from the head. Splice (): The universal operation method of the array, splice (beginning position, length): Delete, splice (beginning position, 0, "abc"): Insert, splice (beginning position, length, and new element of length same number): Replace. Contact (): connection. Join ('-'): Concatenate an array element with a symbol. Sort (): Sort comparison function
arr.sort(function(n1,n2){ return (n1-n2);});
Domdom node Nodes: ChildNodes (behaves differently)/children (contains no text nodes, only element nodes), node type: NodeType, parent node: parentnode, OffsetParent: The principle locates the parent with absolute. Child nodes: FirstChild and LastChild (with compatibility issues, available under Ie6-8, others with Firstelementchild and Lastelementchild) ; Sibling nodes: NextSibling and previoussibling (ibid. compatibility issues, corresponding to nextelementsibling and previouselementsibling). Element attribute operation the first type: odiv.style.display= "block"; second: odiv.style[' Display ']= ' block '; Third: Dom mode: SetAttribute (' name ', ' value '); Package Getbyclass () function with classname selection element
function Getbyclass (oparent,sclass) {
var aresult=[];
var aele=oparent.getelementsbytagname (' * ');
for (Var i=0;i<aele.length;i++)
{if (Aele[i].classname==sclass) {
Aresult.push (Aele[i]);
}
}
return aresult;
}
The DOM manipulation app creates a DOM element createelement (' Li '), which is added to the parent: oul.appendchild (' oLi '); Insert element InsertBefore: Also called at the parent level, the difference is The parent element. InsertBefore (child element, who precedes it); Delete element parent. removechild (child element); Document fragmentation (Basic No) first create ofrag=createdocumentfragment (); Ofrag.appendchild (OLi); Oul.appenddchild (Ofrag);
JavaScript notes (i)