Ajax加载的页面上的jQuery ?

时间:2022-12-01 10:13:48

I'd like to use the jQuery plugin Fancybox on my site - for the most part this works perfectly, however, on this particular page I am loading up someone's profile via Ajax, and would like to have their picture display using Fancybox if the user clicks on the thumbnail.

我想在我的站点上使用jQuery插件Fancybox——在大多数情况下,它都能很好地工作,然而,在这个特定的页面上,我正在通过Ajax加载某人的个人资料,如果用户点击缩略图,我希望用Fancybox显示他们的图片。

If I have this code loaded as a test in the container page, it works fine, however, if I place it into the page that is called through Ajax it simply won't work:

如果我将此代码作为测试加载到容器页面中,它可以正常工作,但是,如果我将它放到通过Ajax调用的页面中,它将无法工作:

<script type="text/javascript">
    $(document).ready(function() {
        $("a#testing").fancybox();
    });
</script>

<a id="testing" href="pic.jpg"><img alt="test caption" src="thumb.jpg" /></a>

I have tried:

我有尝试:

  1. Placing the document.ready code onto the container page
  2. 将文档。容器页面上的现成代码
  3. Placing the document.ready code onto the page called via Ajax
  4. 将文档。准备好的代码通过Ajax调用。
  5. Removing the document.ready trigger and just placing the code directly below the picture
  6. 删除文档。准备好触发器,把代码直接放在图片下面

But none work! Any help would be very much appreciated, thank you :)

但没有工作!非常感谢您的帮助,谢谢!

1 个解决方案

#1


3  

Add

添加

 $("a#testing").fancybox(); 

to the success function of your AJAX call.

为AJAX调用的成功函数。

#1


3  

Add

添加

 $("a#testing").fancybox(); 

to the success function of your AJAX call.

为AJAX调用的成功函数。