用document.onreadystatechange和document.readyState确保文档加载完毕才获取DOM
2016-06-14 11:58 盛世游侠 阅读(1320) 评论(0) 编辑 收藏 举报document.onreadystatechange = function(){ //document.readyState有“interactive”和“complate”两个值 if(document.readyState == "interactive" ){ return false; }; //从这里开始获取dom var dom = document.getElementById("canvas"); console.log(dom); };