【问题标题】:Wrapping $(document).ready inside $(window).load?在 $(window).load 中包装 $(document).ready?
【发布时间】:2017-02-02 04:53:37
【问题描述】:

根据答案here,我需要将我的所有代码包装在$(window).load(function(){ 中。但是,我的画廊也使用 imagesLoaded(在图像准备好时加载图像)和 ajax 在单击按钮时加载更多项目。我现在的布局是这样的:

function initialise(){
//code goes here, including imagesLoaded
};

$(document).ready(function(){
    initialise();
});

$(document).ajaxComplete(function () {
    initialise();

//ajax code goes here
}); 

如何将所有这些都包含在 $(window).load(function () { 中?

【问题讨论】:

  • $(function(){ ...<your code here>... });

标签: jquery ajax document document-ready window-load


【解决方案1】:

就这样!

$(window).load(function () {
    function initialise(){
    //code goes here, including imagesLoaded
    };

    $(document).ready(function(){
        initialise();
    });

    $(document).ajaxComplete(function () {
        initialise();

    //ajax code goes here
    });
});

【讨论】:

  • 好的哇。我试过了,因为这是最有意义的,但它不起作用。我敢肯定只是一个错字或什么的。现在完全工作。谢谢!
猜你喜欢
  • 1970-01-01
  • 2011-07-08
  • 2012-06-16
  • 1970-01-01
  • 1970-01-01
  • 2012-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多