kas*_*tru 3 javascript jquery fancybox
我想在fancybox中获取clicked/shown元素的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")
});
Run Code Online (Sandbox Code Playgroud)
有什么建议?
Nic*_*ver 11
你可以这样做:
$("a.lightbox_image").each(function() {
$(this).fancybox({
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'speedIn': 600,
'speedOut': 200,
'content': 'Id of element clicked' + this.id
});
});
Run Code Online (Sandbox Code Playgroud)
this可能指的是window您当前绑定的位置(或者document如果在ready事件中,如果没有看到更多代码则无法确定).为了this成为<a>你想要的样子,你应该使用一个.each()循环并在那里分配...在.each()闭包内,this指的是锚.
我在使用Nick Craver的解决方案和"onClosed"功能时遇到了问题,经过一些测试后我找到了工作解决方案:
$("a.lightbox_image").each(function() {
var tthis = this;
$(this).fancybox({
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'speedIn': 600,
'speedOut': 200,
onClosed : function() {
alert(this.id);
}
});
});
Run Code Online (Sandbox Code Playgroud)
在我的情况下,这用于在关闭编辑数据的fancybox窗口后重新加载数据行.
| 归档时间: |
|
| 查看次数: |
18405 次 |
| 最近记录: |