7.类数组.html 948 B

12345678910111213141516171819202122232425262728293031323334353637
  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>你好1</li>
  11. <li>你好2</li>
  12. <li>你好3</li>
  13. <li>你好4</li>
  14. </ul>
  15. <script>
  16. /**
  17. * 类数组:
  18. * 不能直接使用数组的方法
  19. * 1.js常见的类数组:arguments(实参);
  20. * 2.由querySelectorAll,getElementsByClassName,getElementsByTagName
  21. */
  22. var arr = [1,2,3,4,5,6,7];
  23. console.log(arr);
  24. function fn1(a) {
  25. console.log(a,arguments)
  26. }
  27. fn1(arr);
  28. let list = document.querySelectorAll("ul li");
  29. // list.push('9')
  30. console.log(list);
  31. //类数组转成整行数组:
  32. let newsList = [...list];
  33. newsList.push(0)
  34. console.log(newsList)
  35. </script>
  36. </body>
  37. </html>