12345678910111213141516171819202122232425262728293031323334353637383940 |
- <!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>
- <ul>
- <li>内容一</li>
- <li>内容二</li>
- <li>内容三</li>
- <li>内容四</li>
- </ul>
- <script>
- /**
- * 类数组:不能直接使用数组方法
- * 1.JavaScript中常见的类数组:arguments
- * 2.由querySelectorAll,getElementsByClassName,getElementsByTagName
- */
- var arr = [1,2,3,4,5,6];
- // console.log(arr);
- // function fn1() {
- // console.log(arguments);
- // }
- // fn1(arr);
- // document.getElementsByTagName
- // document.getElementsByClassName
- // console.log(document.querySelectorAll("ul li"));
- var news = document.querySelectorAll("ul li");
- news.push("000");
- console.log(news,'news');
- // 类数组转成正常数组
- let list = [...news];
- list.push("333");
- console.log(list,'list');
- </script>
- </body>
- </html>
|