我正在尝试获取 fancybox 中单击/显示的元素的 id。我已经尝试过“this.id”和“this.attr(“id”)” - 但它们都不起作用。
$("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
});
});
this
大概指的是window
您当前绑定的位置(或document
如果在ready
事件,在没有看到更多代码的情况下无法确定)。为了this
成为<a>
就像你想要的那样,你应该使用.each() http://api.jquery.com/each/循环并将其分配在那里...里面.each() http://api.jquery.com/each/关闭,this
指锚点。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)