0

我有一个名为 toprightbox 的 div,我正在使用 jquery 在单击时更改其 html:

$(".icon").click(function(){
$("#toprightbox").html('<a rel="prettyPhoto[artwork]" href="large.jpg">
<img src="thumbnail.jpg"  width="100" height="100" /></a>'); 
}

上面通过 jQuery 对 html 的更改调用了 prettyPhoto 灯箱以在 prettyPhoto 灯箱中打开更大的图像...

我想知道为什么这不起作用。生成了链接()和 html,但显然在 jQuery 代码中进行 jQuery 调用似乎是不可能的。PrettyPhoto 灯箱不工作...请帮助!

4

1 回答 1

1

It works. The problem is the order in which you call the code.

  1. Your page is loaded, all initial html is being rendered.
  2. The plugin you are using is called in the $(document).ready(function() { .... }); part of your page (I hope!). If you call your lightbox plugin there (say, on the items with a certain class), it will apply it to all items currently falling within the bounds of that selector.
  3. Afterwards, at some point in time, the user clicks an ".icon" element. Therefore, the new link is added. Your plugin does not work because it was never applied to that newly created link.

So you'll have to call your plugin again in a new step 4.

于 2012-08-16T11:19:15.470 回答