Jquery加载然后编辑加载的内容 [英] Jquery load and then edit loaded content

查看:62
本文介绍了Jquery加载然后编辑加载的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jquery加载,然后一旦内容加载到div中,我想将一些标记更改为语言因变量。

I am using Jquery load and then as soon as the content is loaded into the div I want to change some of the tags to language dependent variables.

我的问题是因为我不得不使用settimeout来让脚本等待足够长的时间让元素准备好进行编辑。

My problem is that I am having to use a settimeout to get the script to wait long enough for the elements to be ready to edit.

当我使用回调函数参数时我想编辑显然没有准备好,因为他们没有设置。我讨厌使用settimeout,因为这会限制每个人到最慢的设置,并且总是某些连接会比这更慢。

When I use the callback function parameter the elements I want to edit apparently aren't ready because they don't get set. I hate to use settimeout because this limits everyone to the slowest setting and invariably some connections will be even slower than that.

显然回调方法只是意味着获得了ajax方法html返回,但它不能确保导入的元素在dom中实际准备就绪。

Apparently the callback method just means that the ajax method got the html back but it doesn't ensure that the imported elements are actually ready in the dom.

任何人都有想法?

当前代码

$("#content-basket").load("/BasketPage.htm?time=" + now.getMilliseconds());
...
...
setTimeout("timedbasket();", 500);
...
...
function timedbasket() {
    alert($('#basketlegend'));
    $('#basketlegend').html(basketlabel);
}

我希望能够使用

$("#content-basket").load("/BasketPage.htm?time=" + now.getMilliseconds(), "", timedbasket());

这是basket.htm来源

Here is the basket.htm source

<tr>
    <td>
        <div id="basket">
            <fieldset>
                <legend><span id="basketlegend"></span></legend>
                <table id="baskettbl" border="0" class="basket-table">
                    <tbody>
                        <tr class='total'>
                            <td>
                                <span id="empty"></span>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </fieldset>
        </div>
    </td>
</tr>


推荐答案

使用callback参数进行加载并将代码放入回调。

Use the callback parameter for load and put your code in the callback.

$("#content-basket").load("/BasketPage.htm?time=" + now.getMilliseconds(),null,
    function() {
           ...do stuff here after #content-basket is finished loading...
});

在查看jQuery之后,确实看起来响应是在调用任何回调之前注入的,所以DOM应该更新。您是否有可能重新使用可能引用之前存在的DOM元素但被负载替换的jQuery对象?

After looking at jQuery, it sure seems like the response is injected before any callbacks are called so the DOM should be updated. Is it possible that you are are re-using jQuery objects that may reference DOM elements that were previously there, but were replaced by the load?

这篇关于Jquery加载然后编辑加载的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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