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值

 

posted @ 2018-08-07 12:03  annofyf  阅读(396)  评论(0编辑  收藏  举报