7.类数组.html 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <ul>
  10. <li>内容一</li>
  11. <li>内容二</li>
  12. <li>内容三</li>
  13. <li>内容四</li>
  14. </ul>
  15. <script>
  16. /**
  17. * 类数组:不能直接使用数组方法
  18. * 1.JavaScript中常见的类数组:arguments
  19. * 2.由querySelectorAll,getElementsByClassName,getElementsByTagName
  20. */
  21. var arr = [1,2,3,4,5,6];
  22. // console.log(arr);
  23. // function fn1() {
  24. // console.log(arguments);
  25. // }
  26. // fn1(arr);
  27. // document.getElementsByTagName
  28. // document.getElementsByClassName
  29. // console.log(document.querySelectorAll("ul li"));
  30. var news = document.querySelectorAll("ul li");
  31. news.push("000");
  32. console.log(news,'news');
  33. // 类数组转成正常数组
  34. let list = [...news];
  35. list.push("333");
  36. console.log(list,'list');
  37. </script>
  38. </body>
  39. </html>