何在执行回调函数之前等待jQuery的load函数呈现已加载的内

何在执行回调函数之前等待jQuery的load函数呈现已加载的内

本文介绍了如何在执行回调函数之前等待jQuery的load函数呈现已加载的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当文档准备好时,我正在使用jQuery的load函数来呈现我的某些内容.

I am using jQuery's load function to render some of my content when the document is ready.

$(document).ready(function(){
   $('#header').load('header.html',function() {
      //do call back function});
   $('#footer').load('footer.html');
});

我不希望我的回调函数在请求完成时执行,而希望在已加载的内容(或dom?)准备好进行操作时执行.我该怎么办?

I don't want my callback function to execute when the request completes, but rather when the loaded content (or dom?) is ready to be manipulated. How can I do this?

谢谢

推荐答案

我很确定您希望在加载Window之后而不是DOM上做一些事情.

I'm pretty sure your looking to do something after the Window is loaded, not the DOM.

如果有一些代码,则依赖于读取图像(文档)之类的高度和宽度.ready将无法工作,因为它是在加载图像之前运行的.尝试在页面上呈现RSS提要之前,我遇到过这个问题.

If you have some code the relies on reading the heights and widths of things like images, (document).ready will not work because it is run before the images have been loaded. I've had this problem before when trying to render RSS feeds on a page.

这是在加载窗口后执行某些操作的代码:

This is the code to do something after the window is loaded:

jQuery(window).load(function() {
    //Do something after the window is loaded!
});

这篇关于如何在执行回调函数之前等待jQuery的load函数呈现已加载的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 11:13