一开始我想到这,DOMContentLoaded,不兼容,
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script type="text/javascript"> function addReady(fn){ if(document.addEventListener){ //DOMContentLoaded firfox .chrome. iE8+ dom事件必须绑定 document.addEventListener('DOMContentLoaded',fn,false) }else{ //onreadystatechange 所有浏览器都可以使用 document.attachEvent('onreadystatechange',function(){ if(document.readyState == 'complete'){ fn &&fn(); } }) } } addReady(function(){ alert(999) }) </script> </head> <body> </body> </html>