JavaScrip学习笔记_JS中的foreach

var hobbies = document.getElementsByName("hobby");

用getElementsByName和getElementsByTagName获得的数组如果用foreach进行遍历并输出结果是:

[object HTMLInputElement]
[object HTMLInputElement]
[object HTMLInputElement]
[object HTMLInputElement]
[object HTMLInputElement]
[object HTMLInputElement]
[object HTMLInputElement]
function item() { [native code] }
function keys() { [native code] }
function values() { [native code] }
function entries() { [native code] }
function forEach() { [native code] }
7

 所以foreach获得value时会得到undefined值

猜你喜欢

转载自www.cnblogs.com/annofyf/p/9436222.html