如果jQuery不可用,有没有办法检查document.ready()? [英] Is there a way to check document.ready() if jQuery is not available?

查看:114
本文介绍了如果jQuery不可用,有没有办法检查document.ready()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

$(document).ready等效没有jQuery

I知道你可以使用window.onload事件来运行函数,但有没有办法让脚本查询文件是否准备就绪?

I know you can use the window.onload event to make functions run, but is there a way for a script to query if the document is ready or not?

function update()
{
    if( !document.ready() )  // don't do unless document loaded
        return ;
}
window.setInterval( 'update();', 100 ) ;

无法更改< body>元素,没有jQuery /其他库。

Cannot change the <body> element, and no jQuery/other libraries.

推荐答案

在这里:

var tid = setInterval( function () {
    if ( document.readyState !== 'complete' ) return;
    clearInterval( tid );       
    // do your work
}, 100 );

了解 document.readyState property < a href =https://developer.mozilla.org/en/DOM/document.readyState =noreferrer>这里。我不确定当前所有浏览器是否都实现了它。

Read about the document.readyState property here. I am not sure if all current browsers implement it.

这篇关于如果jQuery不可用,有没有办法检查document.ready()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆