📜  检查文档是否准备好 js - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:46.894000             🧑  作者: Mango

代码示例1
if( document.readyState !== 'loading' ) {
    console.log( 'document is already ready, just execute code here' );
    myInitCode();
} else {
    document.addEventListener('DOMContentLoaded', function () {
        console.log( 'document was not ready, place code here' );
        myInitCode();
    });
}

function myInitCode() {}