获取 input 节点的正确方法 ()
<form class="file" name="upload">
<input id="file" name="file" />
</form>
getElementById() | 返回对拥有指定 id 的第一个对象的引用。所以B错 |
getElementsByName() | 返回带有指定名称的对象集合。 |
getElementsByTagName() | 返回带有指定标签名的对象集合。 |
NodeList 对象表示节点的集合。可以通过索引访问,索引值从 0 开始。
提示: 你可以使用 NodeList 对象的 length 属性来获取匹配选择器的元素属性,然后你可以遍历所有元素,从而获取你想要的信息。
方法 | 描述 |
---|---|
| |
getElementById() | 返回对拥有指定 id 的第一个对象的引用。 |
getElement***yName() | 返回带有指定name属性的对象集合。 |
getElement***yTagName() | 返回带有指定标签名的对象集合。 |