if $(document).not-ready()?如何检查页面是否仍在使用 Jquery 加载?
我只想在文档仍在加载时调用函数..我该怎么办?
I want to call a function only if the document is still loading.. how can I?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(3)
清风不识月2024-09-13 02:27:58
您可以使用非常有用的 jQuery 延迟对象来检查文档是否已加载:
http://api.jquery.com/category/deferred-object/
http://eng.wealthfront.com/2012/12/jquerydeferred-is-most-important-client.html
例如
(function($) {
var jqReady = $.Deferred();
// Bind doc ready to my deferred object
$(document).bind("ready", jqReady.resolve);
// Check to see is doc is ready
if(jqReady.state() !== 'resolved'){
alert('Doc is not ready');
}
$.when(jqReady).then(function () {
// Code here will run when doc is ready/state === 'resolved'
alert('Doc is ready');
});
})(jQuery);
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您可以检查
document.readyState
或在全局范围内使用一个简单的变量:You could check
document.readyState
or use a simple variable in the global scope: