Detailed description of javascriptdom operations js Enhanced Operation implementation code. 1. Each node in the document has the attributes nodeName, nodeValue, and nodeType.
The node name of the nodeName text node is # text, and nodeName is a read-only attribute.
NodeValue 1 Element Node 2 attribute node 3 text node read-only attribute
NodeType cannot be used for element nodes to return null
2. getElementsByTagName returns a node set.
3. The first and last element nodes of firstChild and lastChild
4. childNodes
5. previussibling the previous sibling node nextSibling the next sibling node parentNode returns the parent node
6. hasChildNodes text nodes can be used as child nodes of element nodes. text nodes and attribute nodes cannot contain any child nodes.
7. appendChild (node) appending node
8. removeChild () removes a node.
You can obtain the parent node from the child node and then remove the child node.
9. replaceChild () replacement method. There are two parameters. Replace the content of the first parameter with the content of the second parameter.
If both exist in the dom, the first will appear in the second position, and the second will disappear.
10. insertBefore (newnode, refnode) inserts newnode before refnode
11. Create a node
SetAttribute () adds an attribute to an element node.
CreateElement () creates an element node
CreateTextNode () creates a text node
You can use these three methods to add any node.
12. The innerHTML internal html can be obtained or set
Here is an example: select a city in association. The city information is in xml.
13. When calling a function
1,
Node. onclick = xxx (); obtain the return value of the function, that is, the function is executed.
2,
Node. onclick = function (){
Xxx ();
}
The function is referenced and executed only when the event is triggered.
14. delete a dynamic array: After an element in the array is deleted, the element following it will automatically move forward.
["Shandong", "Shanxi", "Guangdong", "Guangxi", "Sichuan", "Henan", and "Hebei"]
If you use for (int I = 0; I ["Shanxi", "Guangdong", "Guangxi", "Sichuan", "Henan", and "Hebei"]
["Shanxi", "Guangxi", "Sichuan", "Henan", and "Hebei"]
["Shanxi", "Guangxi", "Henan", and "Hebei"]
["Shanxi", "Guangxi", "Henan"]
Array out-of-bounds
Conclusion: The dynamic array needs to be deleted from the back to the front.
For (int I = xx. length; I> 0; I --)
Record an example of association Selection
After selecting a province, the corresponding city will appear in another select
City.html
The Code is as follows:
Untitled Document