javascript getElementById usage and usage_javascript skills
WBOY
Release: 2016-05-16 18:58:07
Original
1304 people have browsed it
document.getElementById("link").href; document.getElementById("link").target; document.getElementById("img").src; document.getElementById("img") .width; document.getElementById("img").height; document.getElementById("input").value; So how to get
, and bbb in bbb are also very simple, using innerHTML That's it: document.getElementById("div").innerHTML; document.getElementById("link").innerHTML; getElementById method returns the first one with the specified ID attribute value A reference to the object. Syntax oElement = document.getElementById(sIDValue) Parameters sIDValue is required. A string indicating the value of the ID attribute Return value Returns the first object whose ID attribute value is the same as the specified value. Notes If the ID belongs to a collection, the getElementById method returns the first object in the collection. The getElementById method is equivalent to using the item method on the all collection. For example, the following code sample shows how to retrieve the first feature with ID oDiv from a document object. Use DHTML Object Model: var oVDiv = document.body.all.item("oDiv"); Use Document Object Model (DOM): var oVDiv = document.getElementById("oDiv "); Example The following example shows how to use the getElementById method to return the first occurrence of the ID attribute value oDiv. <script> <br>function fnGetId(){ <br>// Returns the first DIV element in the collection. <br>var oVDiv=document.getElementById("oDiv1"); <br>} <br></script>
Div #1
Div #2
< ;DIV ID="oDiv3">Div #3
getElementById method Returns the first one with the specified ID attribute value. For example, there is a text box in a web page with an id called text1 getElementById(text1) can get the object of this text1 box and use all the properties and methods of the text box This is a JS method, which means to get the value of an element through the control ID, such as text, label, etc. in a form. They are all elements of FORM and have an assigned ID. getElementById() is to get these elements. of text value. This is a JS method, which means to obtain the value of an element through the control ID, such as a form containing text, label, etc. They are all elements of FORM and have an assigned ID. getElementById() obtains these The text value of the element. Program Example
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn