将jQuery colorbox插件添加到动态创建的元素中 [英] Add jQuery colorbox plugin to a dynamically created element
本文介绍了将jQuery colorbox插件添加到动态创建的元素中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在链接上分配颜色框功能的常用方法如下:
The usual way to assign color box functionality on a link is like this:
$("a.colorbox").colorbox({ transition: "elastic" });
尽管如此,新添加的项目并不受此约束.
Newly added items are not bound in this way though.
如何将colorbox也添加到动态创建的
How can I add colorbox to dynamically created
<a class="colorbox"></a>
元素中?
elements too?
推荐答案
The method described here is to live-bind to the click
event on the elements you're interested in (such as .colorbox
in this instance) and call the colorbox library function in the handler:
$('.colorbox').live('click', function() {
$.colorbox({href:$(this).attr('href'), open:true});
return false;
});
这篇关于将jQuery colorbox插件添加到动态创建的元素中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文