AJAX加载后操作件

AJAX加载后操作件

本文介绍了AJAX加载后操作件()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图操纵某些元素使用.load后,我加载它们()。我把一切都正确加载,但我似乎无法针对内的任何加载的元素的任何元素。这似乎喜欢的事,会很容易,但我可以把我的手指上。

I am trying to manipulate some elements after I load them using .load(). I have everything loading correctly, but I can't seem to target any elements within any of the loaded elements. This seems like something that would be easy, but I just can put my finger on it.

我现在用的元素加载后回调,但DOM似乎没有意识到它们的存在?

I am using a callback after the elements load, but the DOM seems to not be aware of their existence?

function load_page(){
    $('#page_name').load("/page-name/ .page", null, load_complete());
}

function load_complete() {
    $('#page_name .book_img').addClass('hello');
}

好了,这就是我现在所在。我加...

Ok, this is where I am at now. I have added...

$('#wrapper').ajaxComplete(function() {
    $('#page_name .book_img').addClass('hello');
}

这工作。必须有.autoComplete并且被打包带.load()函数回调之间的差。我真的不喜欢这一点,因为它被称为每一个AJAX事件完成加载时间,但它确实还让我一点点的道路。

which works. There must be a difference between the .autoComplete and the callback which is packaged with the .load() function. I don't really like this because it is called every time an AJAX event is finished loading, but it does get me a little further down the road.

任何人有什么好?

我也试过...

$('#wrapper').ajaxComplete(function() {
    $('#page_name .book_img').addClass('hello');
}

这是一种很好的,因为它等待,直到所有的AJAX调用调用函数之前完成。也许这是为了做到这一点,但它仍然好像.load()函数会照顾呢?

Which is kind of nice since it waits till all AJAX calls are done before calling the function. Maybe this is the way to do it, but it still seems like the .load() function would take care of this?

推荐答案

看起来你执行它传递给load方法的回调函数:

Looks like your executing your callback function instead of passing it to the load method:

function load_page(){
    // $('#page_name').load("/page-name/ .page", null, load_complete());
    $('#page_name').load("/page-name/ .page", null, load_complete);
}

function load_complete() {
    $('#page_name .book_img').addClass('hello');
}

那么,什么是被传递到负载的方法为空,因为在load_complete没有返回值

So what was being passed to the load method is null because there is no return value in load_complete

这篇关于AJAX加载后操作件()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 18:43