应用jQuery的功能,Ajax内容 [英] Apply jquery function to ajax content

查看:99
本文介绍了应用jQuery的功能,Ajax内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这个功能适用于通过AJAX加载的内容。事情是,该功能不工作的这些内容。是否有某种方式解决有关此的每个函数?

  $(。liquidcam)。每个(函数(指数){
          如果((!this.width ||!this.height)){

         $(本).parent()父()隐藏(快)。;
        }

        $(本).error(函数(){

         $(本).parent()父()隐藏(快)。;
        });



  });
 

解决方案

建立在什么achitaka山说,与最新的jQuery,你可以这样做...

  $(文件)。在('准备ajaxComplete',函数(){
    // ...在这里附上您的事件/插件
});
 

其中,我认为是一个有点更清洁,更容易执行/如果你曾经需要扩大。你必须要小心,虽然创建循环(例如,如果你开除你'准备好'处理一些AJAX调用!)。

I want to apply this function to content which is loaded by ajax. Thing is, the function is not working on such content. Is there somehow a workaround for this each-function?

     $(".liquidcam").each(function(index) {
          if( (!this.width || !this.height) ) {

         $(this).parent().parent().hide("fast");
        }

        $(this).error(function() {

         $(this).parent().parent().hide("fast");
        });



  });

解决方案

Building on what achitaka-san said, with the latest jQuery you can just do...

$(document).on('ready ajaxComplete', function() {
    // ...attach your events/plugins here
});

Which, I think is a bit cleaner and easier to follow/extend if you ever needed to. You need to be careful about creating loops though (for example if you fire some AJAX calls in your 'ready' handler!).

这篇关于应用jQuery的功能,Ajax内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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