-1

我有一个使用 ajax jquery 和 facebox 的网站。在这里演示:http : //temp.nevergone.eu/facebox.php 在 div "#content" 里面有一些指向其他页面的链接,这些页面可以使用 facebox 正常打开。

如果我使用 ajax jquery 重新加载该 div 的内容,那么链接将不再使用 facebox 效果弹出。

我试图创建一个函数,每当我调用更改 div #content 内容的函数时,我都会调用该函数,但没有运气。我知道每次我将新内容加载到包含 rel="lightbox" 的页面时,我都必须重新初始化/重新加载 DOM,但我无法弄清楚如何。我在里面调用它如果我使用 jquery HTML 函数,它就可以工作,但是如果我使用加载功能,它将不再起作用。

function updatec() {
    $("#content").load('sometext.html');
    reinit();
}

function reinit() {
  $('a[rel*=facebox]').facebox() ;
}

sometext.html 仅包含<a href="http://www.google.com" rel="facebox">CLICK ME I DONT WORK</a>(if you click it it wont open using facebox,it will open like a normal link)'

4

1 回答 1

0

I think I got your problem. you are reinitializing your facebox script before you insert the content.

What you currently have is this:

function reinit() {
   $('a[rel*=facebox]').facebox() ;
}
function updatec() {
reinit();
$("#content").html('<a href="http://www.google.com" rel="facebox">CLICK ME I DONT          WORK</a>');
  }

You need to move your reinit function below the html insertion like so:

function updatec() {    
$("#content").html('<a href="http://www.google.com" rel="facebox">CLICK ME I DONT          WORK</a>');
    reinit();
  }

Sometimes you just need another pair of eyes on a problem.

于 2010-08-05T07:28:22.110 回答