Fancybox:绑定多个具有相同类的DIV,但如何在onComplete函数中单独访问它们?
正如您在 onComplete 定义中看到的,我试图访问当前正在启动的特定 DIV 的 HTML,但绑定调用是由类完成的。如果我有许多同一类的 DIV,它会正确绑定,这意味着当我单击“.opener”锚点时,它会弹出正确的内容。但是,我无法弄清楚如何从 onComplete 函数访问该内容,因为它每次都只返回第一个“.opener”,无论正在启动哪个。有什么想法吗?
initFancyBox: function() {
//ie hack for fancy box
if ($(".dialog").length > 0 || $(".imageDetail").length > 0) {
$(".opener").fancybox({
'titlePosition': 'inside',
'transitionIn': 'none',
'transitionOut': 'none',
'type': 'inline',
'onComplete': function(){
alert($(".opener").parent().html());
}
});
} else {
$(".opener").fancybox({
'titlePosition': 'inside',
'transitionIn': 'none',
'transitionOut': 'none',
'type': 'image'
});
}
}
As you can see in the onComplete definition I am trying to access the HTML of the specific DIV that is currently being launched, but the bind call is done by class. If I have many DIVs all of the same class it is bound properly, this means that when I click the ".opener" anchor it pops up the proper content. However I can't figure out how to access that content from the onComplete function as it only ever gives back the first ".opener" every time, regardless of which one is being launched. Any ideas?
initFancyBox: function() {
//ie hack for fancy box
if ($(".dialog").length > 0 || $(".imageDetail").length > 0) {
$(".opener").fancybox({
'titlePosition': 'inside',
'transitionIn': 'none',
'transitionOut': 'none',
'type': 'inline',
'onComplete': function(){
alert($(".opener").parent().html());
}
});
} else {
$(".opener").fancybox({
'titlePosition': 'inside',
'transitionIn': 'none',
'transitionOut': 'none',
'type': 'image'
});
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想对选择器中的每个项目执行某些操作,请尝试使用以下内容:
If you want to do something for each of your items from the selector, try using something like: