<!DOCTYPE html> <html> <head> <style></style> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script> <script> window.onload = function(){ console.log('load1'); }; window.onload = function(){ console.log('load2'); }; $(document).ready(function(){ console.log('ready1'); }); $(document).ready(function(){ console.log('ready2'); }); </script> </head> <body></body> </html>
總結:html
$(document).ready(function(){})
先於window.onload = function(){}
執行。$(document).ready(function(){})
,則依次執行。window.onload = function(){}
,則只執行最後一個。注意:$(document).ready(function(){})
等價於$(function(){})
,而$(function(){})
是jQuery的寫法。jquery
參考:.net