使用当前显示图片的标题作为邮件主题

Use title of currently displayed image as mail subject

我使用 Jack Moore 的 Colorbox 来显示几张图片。现在我想在灯箱的标题后面集成一个mailto link。这应该让访问者有机会请求有关当前显示的图像的更多信息。为了稍后可以将邮件分配给图像,当前显示的图像的标题应该是邮件的主题。目前,我可以使用 jQuery 和“附加”将 mailto link 附加到标题。但是,我还没有找到一种方法来获取图像的标题并将其用作邮件的主题。到目前为止我的解决方案:

<script>
$(document).bind('cbox_complete', function(){
    $('#cboxTitle').append( "<a href='mailto:123@test.com?subject=???'>Get info</a>" );
});
</script>

有没有人有什么想法?

我不知道 colorbox,但我希望

$(document).on('cbox_complete', function(e){
  $('#cboxTitle')
    .append(`<a href="mailto:123@test.com?subject=${e.target.title}">Get info</a>`);
});

或将${e.target.title}更改为

$(e.target).closest(".somecontainer").find("img").attr("title")

您需要为“.somecontainer”提供选择器的地方

感谢@mplungjan 的输入,我找到了答案: 有

var text = $('#cboxTitle').text();

我可以从 div #cboxTitle 中获取内容作为变量,然后像这样将变量插入到我的主题中

<script>
$(document).on('cbox_complete', function(e){
  var text = $('#cboxTitle').text();
  $('#cboxTitle')
    .append(`<div><a href="mailto:123@test.com?subject=${text}">Anfrage</a></div>`);
});
</script>