戒酒吧,波澜不惊造句,三亚楼市调控升级
本文主要介绍了html5 htmlcollection和nodelist的区别详解,分享给大家,具体如下:
获取
htmlcollection 对象
getelementsbytagname() 方法返htmlcollection对象。
htmlcollection 对象类似包含 html 元素的一个数组。
注意:
nodelist 对象
大部分浏览器的queryselectorall()返回 nodelist 对象。
注意
htmlcollection 与 nodelist 的区别
代码
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>document</title> </head> <body> <p>1</p> <p id="p2">2</p> <p>3</p> <p>4</p> <p>5</p> <script> // getelementsbytagname() 方法返回 htmlcollection 对象。 const mycollection = document.getelementsbytagname('p'); console.log(mycollection) // 大部分浏览器的 queryselectorall() 返回 nodelist 对象。 const mynodelist = document.queryselectorall("p"); console.log(mynodelist) console.log(mynodelist ===mycollection) //false console.log(mycollection.p2) // <p id="p2">2</p> console.log(mynodelist.p2) //undefine </script> </body> </html>
到此这篇关于html5 htmlcollection和nodelist的区别详解的文章就介绍到这了,更多相关html5 htmlcollection nodelist内容请搜索移动技术网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持移动技术网!
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
HTML5 HTMLCollection和NodeList的区别详解
网友评论