<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div id="box2" class="box1"></div> <script> window.onload = function (ev) { //1.利用原生的js查找dom元素 var div1 = document.getElementsByTagName("div")[0];//根据div标签名--获取第0个<div> var div2 = document.getElementsByClassName("box1")[0];//根据class类名获取 var div3 = document.getElementById("box2");//根据id获取 //2.利用原生js修改背景颜色 div1.style.backgroundColor = "red"; div2.style.backgroundColor = "blue"; div3.style.backgroundColor = "yellow"; } //利用jquery获取 $(function () { var $div1 = $("div")[0]; var $div2 = $(".box1")[0]; var $div3 = $("#box2")[0]; $div1.css({ background:"red", "200px" }); }) </script> </body> </html>