$(function(){
});
$(document).ready(function(){
});
$(document).on('ready', function(){
});
這三種寫法本質都是調用了$().ready()實例方法,ready()是寫在jQuery.prototype中的方法
ready: function( fn ) {
// Add the callback
jQuery.ready.promise().done( fn );
return this;
}
jQuery.ready.promise中調用了 DOMContentLoaded 和 load事件,當DOM加載完成就會觸發這個事件。
DOM加載完成的標誌是 document.readyState === 'complete';
<
script
type
=
"text/javascript"
src
=
"https://code.jquery.com/jquery-2.0.3.js"
></
script
>