1234567891011121314151617181920212223242526272829303132 |
- <!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>
- <div class="box" id="box1">hello world</div>
- <div class="box">你好世界</div>
- <script>
- // var a = 1;
- // a = 10;
- // js选择器
- // 类选择器 他将返回一个集合 里面有多个值 类似一个数组
- var box = document.getElementsByClassName("box");
- console.log(box[0]);
- // ID选择器 他将返回一个唯一值
- // var box1 = document.getElementById("box1");
- // console.log(box1);
- //标签选择器 他将返回一个集合 里面有多个值 类似一个数组
- var divs = document.getElementsByTagName("div");
- console.log(divs)
- </script>
- </body>
- </html>
|