window.onload = function () { // 等所有的东西全部加载完毕,再去执行里面的内容 var main = document.getElementById("main"); console.log(main); };