Returns a reference to the first object with the specified
value of the id attribute.
dhtml语法
oelement = document.getelementbyid(sidvalue)
parameters
sIDValue |
Required.
Stringthat specifies the value of an ID attribute. |
Return Value
Returns the first object with the same ID attribute as the specified value.
Remarks
If the ID value belongs to a collection, the getElementById method returns the first object in the collection.
DHTML代码范例
This example uses the getElementById method to return the first occurrence of the ID attribute value, oDiv.
<SCRIPT>
function fnGetId(){
// Returns the first DIV element in the collection.
var oVDiv=document.getElementById("oDiv1");
}
</SCRIPT>
<DIV ID="oDiv1">Div #1</DIV>
<DIV ID="oDiv2">Div #2</DIV>
<DIV ID="oDiv3">Div #3</DIV>
<INPUT TYPE="button" VALUE="Get Names" onclick="fnGetId()">
是否符合公共标准
This method is defined in
World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 .
Applies To
更多语法参考
About the W3C Document Object Model