javascript getElementsByName() method


  Translation results:

get

英[get] 美[ɡɛt]

vt.Get; catch; persuade; receive (punishment, etc.)

vt.& vi. Arrive, come

vi. Become; start; try to deal with; obtain benefits or wealth

n. Reproduce, cub; profit

Third person singular : gets present participle: getting past tense: got past participle: got gotten

element

##英[ˈelɪmənt] US[ˈɛləmənt]

n. element; [chemical] element; principle; [electricity] resistance wire

plural: elements

by

英[baɪ] 美[baɪ]

prep. Beside...; Expression method; Because; Passed

adv. Passed; Used to indicate reservation or preservation; Short visit

name

英[neɪm] 美[nem]

n.

Name; reputation; having...name; famous person

vt.

determine; decide; name...; name... Plural: names Present participle: naming Past tense: named Past participle: named

javascript getElementsByName() methodsyntax

Function: Returns a collection of objects with the specified name.

Syntax: document.getElementsByName(name)

Description: This method is similar to the getElementById() method, but it queries the element The name attribute, not the id attribute. In addition, because the name attribute in a document may not be unique (for example, radio buttons in HTML forms usually have the same name attribute), all getElementsByName() methods return an array of elements, not an element.

javascript getElementsByName() methodexample

<html>
<head>
    <meta charset="UTF-8">
    <script type="text/javascript">
        function getElements()
        {
            var x=document.getElementsByName("myInput");
            alert(x.length);
        }
    </script>
</head>

<body>
<input name="myInput" type="text" size="20" /><br />
<input name="myInput" type="text" size="20" /><br />
<input name="myInput" type="text" size="20" /><br />
<br />
<input type="button" onclick="getElements()" value="名为 'myInput' 的元素有多少个?" />
</body>

</html>

Run instance »

Click the "Run instance" button to view the online instance

Home

Videos

Q&A