的fancybox链接并不Ajax内容里面工作并不、里面、链接、内容

2023-09-10 14:41:37 作者:夜袭

我需要频繁地使用AJAX,jQuery和PHP来更新我的网站上的一节。

I need to update a section on my site frequently using ajax, jquery, and php.

在第一次加载页面时,它调用一个JavaScript函数,显示部分的内容。然后使用JSON我检查更新,并如果有结果,调用相同的函数来显示。

When the page first loads, it calls a javascript function that displays the content of that section. Then using json I check for updates and if there are results, calls the same function to display it.

现在阿贾克斯的内容里面有像

Now inside the ajax content there are links like

<a href="news.php?id" class="ajaxpopup">title</a>

要调用的fancybox但不是打开一个弹出窗口,它直接打开的页面。 如果调用的fancybox的链路不是一个Ajax里面的内容会显示正常。 我知道有一些人有同样的问题,但答案是对的div特定ID。 我怎样才能全局设置。我的意思是工作在带班=ajaxpopup链接?

to call fancybox but instead of opening a popup, it opens the page directly. If the link to call fancybox is not inside an ajax content it displays properly. I know that there are some people with the same problem but the answers are for divs with specific id. How can I set it globally. I mean to work on links with class="ajaxpopup"?

这是我的函数调用的内容

this is my function to call the content

$(document).ready(function() {
  $(".ajaxpopup").fancybox({
    'overlayColor'      : '#000000', 
    'centerOnScroll'    : true,
    'transitionIn'      : 'none',
    'transitionOut'     : 'none',
    'modal'             : true
  }); 
});

function update(page,value)    {
  var data = 'id='+value;
  $.ajax({
    url: page,
    type: "POST",       
    data: data,     
    cache: false,
    success: function (html) {  
      $('#updates').html(html);   
      $('#updates').fadeIn(200);      
    }       
  });
}

那么的div

then the divs

推荐答案

加载动态内容后,再次绑定看中盒

After loading the dynamic content, bind the fancy box again

 div.load("myserverpage.aspx?mode=popularmodels", { symbol: $("#txtSymbol").val() }, function() {
                $(this).fadeIn(100);

                $(".ajaxpopup").fancybox({
                    'scrolling': 'no',
                    'titleShow': true,
                    'titlePosition': 'over',
                    'onClosed': function () {
                        $("#login_error").hide();
                    }
                });
            });