您的位置:首页 > 其它

Document getElementsByName() Method

2011-07-17 09:43 232 查看

Definition and Usage

The getElementsByName() method accesses all elements with the specified name.

Syntax

document.getElementsByName(name)
ParameterDescription
nameRequired. The name of the element you want to access/manipulate

Browser Support

The getElementsByName() method is supported in all major browsers.

Example

Example

Alert the number of elements with a specific name:
<html>
<head>
<script type="text/javascript">
function getElements()
{
var x=document.getElementsByName("x");
alert(x.length);
}
</script>
</head>
<body>

<input name="x" type="text" size="20" /><br />
<input name="x" type="text" size="20" /><br />
<input name="x" type="text" size="20" /><br /><br />
<input type="button" onclick="getElements()" value="How many elements named 'x'?" />

</body>
</html>
Try it yourself »
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: