Array type
var arr = [];arr.length; // returns the number of array elements
Changing the length can dynamically change the array size detection array instanceof can detect whether an object is an array, limit: can only be a Web page or a global scope
Array.isarray (arr); // finally determines whether a value is an array, no limit
Conversion method
Arr.tostring (); // Returns a comma-delimited string arr.valueof () that is stitched together as a string of each value in the array ; // consistent with ToString Method arr.tolocalstring (); // The general situation is consistent with the ToString and valueof values, and redefinition is not necessarily
Note:The ToString method will call the ToString method of each value, and tolocalestring will call the toLocaleString method of each value
Arr.join ("-"); // returns a string with the passed-in string as a delimiter, with no value, separated by commas
Stack method
Arr.push (Arg1,arg2,arg3 ...); // receives an unlimited parameter, added sequentially to the end of the array, and returns the length of the modified array arr.pop (); // returns the last item of the array and moves the group
Queue method (required and stack method combination)
Arr.shift (); // removes the first item of an array and returns the removed item arr.unshift (Arg1,arg2,arg3 ...); // Add any item to the front of the array and return the array length after the change
Reorder Methods
Arr.reverse (); // Inverse array arr.sort (); // converts each item of an array into a string, compares it, and arranges the arr.sort (function() {}) in ascending order; // receive a function as an argument, sort by the return value of the function, followed by the last item, return 1, row before, return-1
Operation method
Arr.concat (Arg1,arg2,arg3,.....); // do not limit the number of incoming, can be an array, can be a string, can be a numeric arr.slice (ARG1,ARG2); // receives two parameters, the starting item to return (optional) and the end position (optional), does not pass the last parameter, returns from the starting item to the end of the array, does not pass arguments, returns the entire array arr.splice (ARG1,ARG2,ARG3); // Arg1 removes the position of the first item, arg2 the number of items deleted, ARG3, can be any number of strings that are used to remove the insert after
Location method
Arr.indexof (ARG1,ARG2); // Arg1 finds the entry, Arg2 finds the starting point (optional), finds it from scratch, finds the return position index (starting at position 0), finds no return-1arr.lastindexof (ARG1,ARG2); // Search direction opposite to indexof, number of parameters, consistent meaning
Iterative methods
Arr.every (function(){});//each of the array run parameter functions returns true to TrueArr.filter (function(){});//an array member that returns true for each of the set of parameter functions that are returned by the functionArr.foreach (function(){});//run the parameter function for each item in an array, no return value, change the elementArr.map (function(){});//an array of each run parameter function that returns the result of each function call.Arr.some (function(){});//each item of an array runs a parameter function, and returns True whenever one of the items returns Truefunction(Item,index,array) {}//a parameter function that receives three parameters: the value of the array item, the position of the item in the array, the array object itself
Merge method
Arr.reduce (function() {},initvalue); // iterates over all the items of an algebraic group, constructs a return value, starting with the first item of the array arr.reduceright (function() {},initvalue); // iterates over all items of an algebraic group, constructs a return value, starting with the last item in the array function (Prev,cur,index,array) {} // parameter function, four parameters: previous value (determined by previous function result), current value, index of item, array object initvalue // Optional
Domnode Type NodeType Property: node Type, NodeName property: node name, NodeValue attribute: node value each node has childnodes attribute, save NodeList object, dynamic object, with length property, can be accessed using the item () method and the square bracket method.
- The ParentNode property, which points to the document tree parent node.
- PreviousSibling property: The previous node of the same list
- NextSibling property: The next node of the same list
- FirstChild Property: First child node
- LastChild property: Last child node
- Ownerdocument Property: A document node that points to the entire document
- HasChildNodes (node): Returns True if the node contains one or more child nodes
- Somenode.appendchild (NewNode): Joins a node after the last child node
- Somenode.insertbefore (Newnode,node): Inserts a node before the reference node, the reference node is null, and the result is consistent with the AppendChild method
- Somenode.replacechild (newnode,node): Replace node
- Somenode.removechild (node): removing Nodes
- Somenode.clonenode (Boolean): Copy, True deep copy, copy this node and subtree, false shallow copy, copy only this node
- Normalize (); Handles the text node in the document tree, combined with the
Document Type JS is used to represent documents, which is the entire document, not a part, that is, the paper object
- Document.documentelement properties: Point to
- Document.body properties: Point to <body>
- Document.doctype: Point to <! Doctype>
- Document.title: Point <title>
- Document. URL: page full URL
- Document.domain: Domain name, can be set, same domain
- Document.referrer: A URL that holds the page that is linked to the current page
Find element
- getElementById: Receives a parameter, the ID of the element to be taken, strictly matches the case, multiple IDs are the same, and the first element is returned
- Getelementbytagname: Takes an argument, gets the element tag name, returns the NodeList, returns the Htmlcollection object in the HTML document, the dynamic collection, and can access the element using the item () method or square bracket method.
- Htmlcollection object, there is also a method, Nameditem, that you can use to get the items in the collection by using the name attribute of the element.
- Getelementsbyname (): Htmlcollection type only method. Returns all elements of the given name attribute
Special Collections are Htmlcollection objects
- Document.anchors: All <a> with the name feature
- Document.applets: All <applets>
- Document.forms: All <form>
- Document.images: All
- Document.links: all <a> with href
Element type all HTML elements are htmlelement types, or they are represented by their subtypes. Characteristics:
- ID: Unique identifier in the document
- Title: Additional description of the element, usually shown by the ToolTip bar
- Lang: element content language code, rarely used
- Dir: Language direction, TLR (left to right), RLT (right to left), rarely used
- ClassName: Corresponds to the element class, the CSS class specified for the element
Get features
- GetAttribute (): note: The attribute name passed is the same as the actual attribute name, so to get the class attribute, to pass "class" instead of "ClassName", you can also get the custom attribute, the attribute is case-insensitive Note: Attributes are typically accessed through object properties, and only the GetAttribute method is used to obtain a custom attribute
- SetAttribute (): Receives two parameters, the attribute name and value to be set. already exists, replaced, not present, created. The attribute names that are set are uniformly converted to lowercase.
- RemoveAttribute (): Receives the attribute name. Clear the attribute value and delete the attribute.
The Attributes property element type is the only one that uses the Attributes property.The only oneThe DOM node type Attributes property contains a NamedNodeMap, a dynamic collection. Each attribute of an element is represented by a attr node, and each node is stored in the NamedNodeMap object, with the method that the object owns:
- Element.attributes.getNamedItem ("id"): Returns the node nodename attribute equals ID, abbreviated: element.attributes["id"]
- Element.attributes.removeNamedItem ("id"): Removes the node with the NodeName attribute equal to name
- Element.attributes.setNamedItem (node): A very uncommon way to add attributes to an element.
Attributes method is not convenient, more will use the Getattribute,setattribute,removeattribute method. Serialization is useful:
function Outputattribute (Element) { varnew Array (), attrname, attrValue, i , Len; for (i=0,len=element.attributes.length;i<len;i++) { = element.attributes[i].nodename; = Element.attributes[i].nodevalue; + = "=\" + attrValue + "\" "); } return pairs.join ("");}
Because IE7 and earlier versions return all possible attributes in HTML, the above function is improved to return the specified attribute. Each attribute node has a specified property, true, either specifying the attribute in HTML or setting it through setattribute. Improved post code:
function Outputattribute (Element) { varnew Array (), attrname, attrValue, i , Len; for (i=0,len=element.attributes.length;i<len;i++) { = element.attributes[i].nodename; = Element.attributes[i].nodevalue; if (element.attributes[i].specified) { Pairs.push (attrname + = "=\" + attrValue + "\"); } } return pairs.join ("");}
Creating elements
- Document.createelement (): Receives a parameter, the element tag name to be created, is case-insensitive in HTML, is differentiated in XML, and is also added when created Ownerdocument property
The childnodes attribute of the element child node element contains all its child nodes. The text type contains plain text content, which can contain escaped HTML characters, and the method of obtaining text in the text content manipulation node via nodevalue or data:
- AppendData (Text): Add text to the end of the node
- DeleteData (offset,count): Deletes count characters from the position specified by offset
- InsertData (Offset,text): Inserts text text from offset specified position
- ReplaceData (offset,count,text): Replace the count character with text starting at offset specified position
- Splittext (offset): divides text into two nodes starting with offset
- Substringdata (Offset,count): Extracting a string from offset to Offset+count
- The length property, which holds the number of characters in the node, nodevalue.length,data.length the same value
Create a text node
- document.createTextNode (): receives a parameter to insert the text in the node, it needs to be encoded in HTML or XML format, and the Ownerdocument attribute is added when created
Normalize text nodes
- Normalize method. Called on the parent element, all text nodes are merged.
Split text nodes
- Splittext method, divides a text node into two
Comment Type annotations are represented in the DOM by the comment type, inherit the same base class as text, and have all the string manipulation methods except the Splittext method, Similar to text can be obtained by nodevalue and data Comment content cdatasection type for XML documents, the CDATA zone DocumentType type is not commonly used, only firefox,safari,opera support. Save the DocumentFragment type of document fragment in Document.doctype. Of all node types, only documentfragment does not have a corresponding tag. Can be used as a warehouse. Use Document.createdocumentfragment () to create a document fragment that inherits all the methods of node attr type element attribute in the DOM is represented by the attr type attribute: Name (attribute name), value (attribute value, As with the NodeValue value), specified (Boolean, whether specified in code) uses Document.createattribute () and passes in the attribute name to create a new attribute node The above is for individuals this period of time since the study of JavaScript Advanced Programming (third Edition) of some summary, there are many shortcomings, welcome to discuss together!
JavaScript Advanced Programming (third edition) study, first summary