HurnsMobileの優れた答えに追加するには; を見るとbindReady()
、これは、呼び出すたびにjQueryがドキュメントロードイベントにバインドするために行う内部呼び出しです。$(some_function)
または$(document).ready(some_function)
、バインドできない理由がわかります"ready"
。
bindReady: function() {
if ( readyBound ) {
return;
}
readyBound = true;
// Catch cases where $(document).ready() is called after the
// browser event has already occurred.
if ( document.readyState === "complete" ) {
return jQuery.ready();
}
// Mozilla, Opera and webkit nightlies currently support this event
if ( document.addEventListener ) {
// Use the handy event callback
document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
// A fallback to window.onload, that will always work
window.addEventListener( "load", jQuery.ready, false );
// If IE event model is used
} else if ( document.attachEvent ) {
// ensure firing before onload,
// maybe late but safe also for iframes
document.attachEvent("onreadystatechange", DOMContentLoaded);
// A fallback to window.onload, that will always work
window.attachEvent( "onload", jQuery.ready );
// If IE and not a frame
// continually check to see if the document is ready
var toplevel = false;
try {
toplevel = window.frameElement == null;
} catch(e) { //and silently drop any errors
}
// If the document supports the scroll check and we're not in a frame:
if ( document.documentElement.doScroll && toplevel ) {
doScrollCheck();
}
}
}
要約すると、$(some_function)
以下にバインドする関数を呼び出します。
- DOMContentLoaded
- onreadystatechange(DOMContentLoaded)
- window.load / onload
最善の策は、readyイベント(1回だけ発生する)をリッスンしようとするのではなく、新しい要素を作成する可能性のあるアクションにバインドすることです。.tooltipper