The most common object that we use in JavaScript is the Document object
Document object: Each HTML document that is loaded into the browser becomes the document object. We can use the Document object to access the elements in the HTML.
document.getElementById ()
To get the corresponding value by ID
1. Text box
If you want to get the value of a drop-down list box
2. Drop-down selection box
Second, Document.getelementsbyname
This method is roughly the same as getElementById, except that getElementById returns an object, and Getelementsbyname returns a list, This method is used in a text box or checkbox with the same name (see the previous article List select all feature)
Third, Document.getelementbytagname
getElementsByTagName gets a collection under a specified label, not because the label is placed in the range of the collection (for example, to write a form form, which also has the element that the input tag represents, it is also counted in the Elements collection). , it can be found through getElementsByTagName)
The above three methods combined with the use of our web page production is a more common step, so to understand the above relevant knowledge
Iv. Other document There are also some methods and objects set
document.write: Write an HTML expression or JavaScript code to a document
Sometimes we use the document.write () method when we dynamically create HTML tags.
Document.forms[]: Returns a reference to all the form references in a document, such as we want to get the value of a text box inside a form, we can do this:
V. About InnerText and innerHTML
InnerText and innerHTML can add the corresponding information to the tag body, such as we define a <span id= "feedback" ></span>, and the information we return can be dynamically loaded to put in this <span > Inside, here we can use innertext or innerHTML. Today in the project, found a problem, is that Firefox does not support the InnerText property, the solution is to change the innertext to innerHTML.
JavaScript Learning note Document and innerHTML, InnerText