Retrieves a collection of objects based on the value of the attribute.
Syntax
collObjects = document.getElementsByName(sNameValue)
Parameters
sNameValue Required. String that specifies the value of a NAME attribute.
Return Value
Returns a collection of objects with the same NAME attribute value.
Remarks
When you use the getElementsByName method, all elements in the document that have the specified NAME or attribute value are returned.
Elements that support both the NAME and the ID attribute are included in the collection returned by the getElementsByName method, but not elements with a NAME .
Example
This example uses the getElementsByName method to return a collection of elements with the specified NAME attribute value, firstName.
<SCRIPT> function fnGetNames(){ var aInput=document.getElementsByName("firstName"); } </SCRIPT> <INPUT TYPE="text" NAME="firstName"> <INPUT TYPE="text" NAME="firstName"> <INPUT TYPE="button" VALUE="Get Names" οnclick="fnGetNames()">摘自MSDN