window.onload比$(document).ready加载时间要长,onload要加载dom,还要加载页面元素。
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>onload和ready</title> <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> </head> <body> <h3>onload和ready的先后测试</h3> <script> window.onload = function(){ alert('我是onload')} $(document).ready(function(){alert('我是ready')}); </script> </body> </html>