1: Modify the execution method of the loop
For (var I = 0; I <element. childNodes. length; I ++ ){
Execute Code
}
In this way, the value of element. childNodes. length must be set
Var n = element. childNodes. length
For (var I = 0; I <n; I ++ ){
Execute Code
}
2: Number of dom modification operations
Dom inserts a batch of similar nodes in batches. Instead, it is better to construct an object and insert it once.
For example, the following method is reasonable:
Var div = document. createElement ("div ");
For (var I = 0; I <10; I ++ )[
Var element = document. createElement ("");
A. href = "";
Div. appendChild (element );
}
// Insert the object once after Construction
Document. body. appendChild (div );
3: reduces the reference layers of objects and reduces the complexity of browser parsing objects.
For example, a method named net. Loader. LoadXml (params)
You can
Var loadXml = net. Loader. LoadXml;
LoadXml (params );