<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div class="box">1</div> <div class="box">2</div> <div class="box">3</div> <script> let a =document.getElementsByClassName('box'); console.log(a); // let a =document.getElementsByTagName() // 通过class获取 // 通过标签名获取 console.log(a.length); // 查看有多少个名字叫box的 console.log(a[0]); //获取第一个 a[1].innerHTML = 'zy' // 添加内容 </script> </body> </html>