We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

这篇翻译不完整。请帮忙从英语翻译这篇文章

根据给定的name 返回一个在 (X)HTML document的节点列表集合。

语法

elements = document.getElementsByName(name) 
  • elements 是一个实时更新的 NodeList 集合。
  • name 是元素的 name 属性的值。

例子

<!DOCTYPE html>
<html lang="en">
<head>
 ...
</head>

<body>
<form name="up"><input type="text"></form>
<div name="down"><input type="text"></div>

<script>
var up_forms = document.getElementsByName("up");
console.log(up_forms[0].tagName); // returns "FORM"
</script>
</body>
</html>

注释

name属性只有在(X)HTML文档中可用。该方法返回一个live的 NodeList   集合,这个集合包含name属性为指定值的所有元素,例如<meta><object>,甚至那些不支持name属性但是添加了name自定义属性的元素也包含其中。

getElementsByName  在不同的浏览器其中工作方式不同。在IE和Opera中, getElementsByName()  方法还会返回那些id为指定值的元素。所以你要小心使用该方法,最好不要为元素的name和id赋予相同的值。

The name attribute is only applicable to (X)HTML documents. The method returns a live NodeList Collection that contains all elements with a given value for the name attribute, such as <meta> or <object> or even if name is placed on elements which do not support a name attribute at all.

The getElementsByName method works differently in different browsers. In IE & Opera, getElementsByName() method will also return elements that have an id attribute with the specified value. so you should be careful not to use the same string as both a name and an ID.

Specifications

Specifications

Specification Status Comment
HTML Living Standard
Document.getElementsByName()
Living Standard  
Document Object Model (DOM) Level 2 HTML Specification
Document.getElementsByName()
Obsolete Initial definition

See also

文档标签和贡献者

标签: 
此页面的贡献者: LylaYuKakola, xcchcaptain, Soy
最后编辑者: LylaYuKakola,