Fancybox:获取点击的锚点/元素的ID [英] Fancybox: Get id of clicked anchor/element
本文介绍了Fancybox:获取点击的锚点/元素的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在fancybox中获取clicked / shown元素的id。我试过this.id和this.attr(id) - 但它们都不起作用。
I am trying to get the id of the clicked/shown element in fancybox. I have tried both "this.id" and "this.attr("id")" - but none of them works.
$("a.lightbox_image").fancybox({
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'speedIn': 600,
'speedOut': 200,
'content': 'Id of element clicked'+this.attr("id")
});
有什么建议吗?
推荐答案
你可以这样做:
$("a.lightbox_image").each(function() {
$(this).fancybox({
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'speedIn': 600,
'speedOut': 200,
'content': 'Id of element clicked' + this.id
});
});
此
指的可能是 window
您当前绑定的位置(或 document
,如果在 ready
事件中,如果没有看到更多的代码,不能确定)。对于此
是< a>
,您应该使用 .each()
循环并在那里分配...在 .each()
关闭,这个
指的是锚。
this
refers probably to window
where you're binding currently (or document
if in the ready
event, can't be sure without seeing more code). For this
to be the <a>
like you want, you should use a .each()
loop and assign it there...inside the .each()
closure, this
refers to the anchor.
这篇关于Fancybox:获取点击的锚点/元素的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文