The first statement is:
The document. getElementByName method does not exist. Document. getElementsByName obtains the tag array.
Document. getElementId: a tag.
<Form name = "form_write">
<Input name = "content" type = "text">
However, it can be obtained in a simple way, such:
Var fn = document. getElementsByName ("form_write") [0]; // get the object under this form
Fn. content. value; // you can use this object directly.
Document. getElementById 1. getElementById
Purpose: Generally, the ID on the page is unique and used to locate an element.
Syntax: document. getElementById (id)
Parameter: id: Required String)
Return Value: object. Return the first object of the same id in the order displayed on the page. If no object meets the conditions, return null.
Example:
Copy codeThe Code is as follows:
Document. getElementById ("id1"). value;
2. getElementsByName
Purpose: query by element name. An array with the same name is returned.
Syntax: document. getElementsByName (name)
Parameter: name: Required String)
Returned value: array object. If no matching object exists, an empty array is returned, in the order displayed on the page.
Note: The returned array value is the value of the value attribute,
If a tag does not have a value attribute, after you add the value Attribute and assign a value, getElementsByName can also get its value,
If no value is assigned to the value attribute, the array value returned by getElementsByName is undefined,
However, you can still obtain the number of document. getElementsByName (name). length Tags with the same name.
If the name attribute is not set, document. getElementsByName can still be used. It will get the value of the value Attribute Based on your id.
Example:
Copy codeThe Code is as follows:
Document. getElementsByName ("name1") [0]. value;
Document. getElementsByName ("name1") [1]. value;
<Span id = 'cbylawindexname' class = 'normalnode' value = 'all'> all </span>"
<Span id = 'cbylawindexname' class = 'normalnode' value = 'all'> ALL </span>"
The span tag does not have the name and value attributes.
However, document. getElementsByName ("CBylawIndexName") will still get the value of value.
3. getElementsByTagName
Purpose: query by HTML Tag name. An array with the same tag element is returned.
Syntax: object. getElementsByTagName (tagname) object can be document or event. srcElement. parentElement.
Parameter: tagname: the required parameter is a String, which is retrieved Based on HTML tags.
Returned value: array object. If no matching object exists, an empty array is returned, in the order displayed on the page.
Example:
Copy codeThe Code is as follows:
Document. getElementsByTagName ("p") [0]. childNodes [0]. nodeValue;
Document. getElementsByTagName ("p") [1]. childNodes [0]. nodeValue;