我想从图像中获取标题属性并将其添加到周围的链接
到目前为止,我有这个:
var imageTitle = $("a.articleimages img").attr("title");
$('a.articleimages').attr('title', (imageTitle));
问题是它获取第一个图像的标题并在每个链接上重复它。我可以用 ID 来完成它,但它会创建很多代码,因为你有 #image1,然后是 #image2 等等。在我看来,这似乎太过分和愚蠢,必须有一种更简单/更好的方法。也许有某种方法可以让它知道哪个图像被点击并从中提取标题。
我想这样做,这样用户就不必重新输入图像标题即可在 Fancybox 上看到。
如果有一种方法可以改变 fancybox 并让它抓取缩略图图像标题并显示全尺寸图像,那么我也会对此感到满意。
谢谢
So far I have this:
var imageTitle = $("a.articleimages img").attr("title");
$('a.articleimages').attr('title', (imageTitle));
The problem is it takes the first image's title and repeats it on every link. I can pull it off with IDs but it creates a lot of code because you have #image1, then #image2 and so on. Which to me seems excessive and stupid there must be an easier/better way. Maybe there is some way for it to know which image has been clicked and pull the title from that.
I want to do this so users don't have to retype an image title for it to be seen on Fancybox.
If there is a way to alter fancybox and get it to grab the thumbnail image title and show that for the full size image then I’d be happy with that too.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
鉴于
img
是您想要为其设置title
的a
的子级,您可以尝试如下操作:Given that the
img
is a child of thea
that you want to set thetitle
for you could try something like this: