jQuery.ready


jQuery.ready返回: Thenable

描述: 一个 类 Promise 对象(或 “thenable” ,注:即带有 then 方法 ),当文档准备就绪(document ready)时,它处于 resolves 状态。

  • 添加的版本: 1.8jQuery.ready

从jQuery 3.0开始, 可以通过jQuery.when 或者原生的 Promise.resolve() 使用这个对象。你的代码不应该假设这个对象是否是一个 jQuery.Deferred,原生的 Promise ,或者其他类型的promise对象。

另请参见 ready(), 它就是使用了这个对象。

例子:

使用 jQuery.when 监听 document ready

1
2
3
$.when( $.ready ).then(function() {
// Document is ready.
});

典型用法涉及另一个 promise ,使用 jQuery.when.

1
2
3
4
5
6
7
$.when(
$.getJSON( "ajax/test.json" ),
$.ready
).done(function( data ) {
// Document is ready.
// Value of test.json is passed as `data`.
});