getElementById的语法
注意事项1:js代码写在标签后面
注意事项2:参数是区分大小写的字符串
注意事项3:返回的是1个元素对象
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>获取元素</title> </head> <body> <div id="time">2020-10-10</div> <script> // 通过id来过去标签 var timer = document.getElementById('time'); console.log(timer); </script> </body> </html>