当 dom 准备好事件时如何做某事?

发布于 2025-01-02 21:16:55 字数 232 浏览 2 评论 0原文

我有加载内容的ajax 函数。我想在加载内容准备好(加载)时做一些事情。我怎样才能做到这一点?

我尝试 live():

$("ul.slide-gallery").live("ready", function(){
                $("ul.slide-gallery").prettyGallery();
            });

不工作。

I have ajax function that load content. And I want to do something when loaded content ready (loaded). How can i do that?

I try live():

$("ul.slide-gallery").live("ready", function(){
                $("ul.slide-gallery").prettyGallery();
            });

Not work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

余生一个溪 2025-01-09 21:16:55

使用 ajax 请求回调来执行您需要执行的操作。 Live 监视事件。向 DOM 添加元素不是一个事件,因此您不能那样做。您从未指定如何进行 ajax 调用,所以我将承担职位。

$.post(url, function(data) {
      //load data or whatever you are doing
      //$('foo').append(data);

      //after loading call your code
      $("ul.slide-gallery").prettyGallery();
});

Use the ajax requests callback to do what you need to do. Live monitors events. Adding elements to the DOM is not an event so you can't do it that way. You never specified how you are making your ajax call so I will assume post.

$.post(url, function(data) {
      //load data or whatever you are doing
      //$('foo').append(data);

      //after loading call your code
      $("ul.slide-gallery").prettyGallery();
});
厌味 2025-01-09 21:16:55
$(document).ready(function(){
    $("ul.slide-gallery").prettyGallery();
});
$(document).ready(function(){
    $("ul.slide-gallery").prettyGallery();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文