_无空_
2017-03-01 20:14
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> </head> <body> <div> javascript <p>javascript</p> <div>jQuery</div> <h5>PHP</h5> </div> <script type="text/javascript"> var di_v=document.getElementsByTagName("div")[0].childNodes; for(var i=0;i<di_v.length;i++) { document.write(di_v[i].NodeName+" "); document.write(di_v[i].NodeValue+" "); document.write(di_v[i].NodeType+"<br>"); } </script> </body> </html>
结果输出是这样的:
undefined undefined undefined
undefined undefined undefined
undefined undefined undefined
undefined undefined undefined
undefined undefined undefined
undefined undefined undefined
undefined undefined undefined
NodeName、NodeValue、NodeType 的“N”都是小写的“n”,改成小写就可以了
不对啊 改了大小写还是undefined
// 上面对了啊.下面没定义.
// di_v[i]、NodeName和" "未定义变量.
// di_v[i]和NodeName间加 "+"不是点//(引号去掉).
// "< >"要这样才能输出空格;di_v[i]和NodeName间加 "+"不是.(引号去掉).
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题