3

到目前为止,我有这个:

var imageTitle = $("a.articleimages img").attr("title");

$('a.articleimages').attr('title', (imageTitle));

问题是它需要第一张图片的标题并在每个链接上重复它。我可以用 ID 来完成它,但它会创建很多代码,因为你有 #image1,然后是 #image2 等等。在我看来,这似乎过于愚蠢和愚蠢,必须有一种更简单/更好的方法。也许有一些方法可以让它知道点击了哪个图像并从中提取标题。

我想这样做,这样用户就不必重新输入图像标题就可以在 Fancybox 上看到它。

如果有办法改变fancybox并让它获取缩略图标题并显示为全尺寸图像,那么我也会对此感到满意。

谢谢

4

3 回答 3

2
$("a.articleimages img").each(function() {
  var $this = $(this);
  $this.parent().attr('title', $this.attr('title'));
});
于 2010-12-16T00:55:41.547 回答
2

鉴于 theimga您要设置的子项title,您可以尝试以下操作:

$('a.articleimages img').each(function(idx, element) {
   $(element).parent().attr('title',$(element).attr('title'));
});
于 2010-12-16T00:58:13.783 回答
1
var imgs = $("a.articleimages img");

imgs.each(function(i, ele){
    var img = $(ele);
    var title = img.attr('title');
    img.parent('a').attr('title', title);
});
于 2010-12-16T00:55:13.087 回答