gpt4 book ai didi

javascript - Fancybox:获取点击的 anchor /元素的 ID

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:49:08 25 4
gpt4 key购买 nike

我正在尝试获取 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您当前绑定(bind)的位置(或 document 如果在 ready 事件中,在没有看到更多代码的情况下无法确定)。对于 this成为<a>如你所愿,你应该使用 .each() 循环并在那里分配它......在 .each() 内关闭,this指的是 anchor 。

关于javascript - Fancybox:获取点击的 anchor /元素的 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2961496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com