0

我正在使用我构建的图像库函数,尝试使用缩略图的图像属性在完整图像下方生成标题。alt标题。缩略图库侧没有问题。另一方面,标题返回undefined,并出现在第一个缩略图下方,而不是完整图像下方。

$('.gallery li img').hover(function(){
        var $viewer = $(this).parents('.viewer');
      $('.full-img',$viewer).attr('src',$(this).attr('src').replace('thumb/', ''));
      $('.full-img',$viewer).attr('alt',$(this).attr('alt').replace('thumb/', ''));
         var caption_alt = $('.full-img',$viewer).attr('alt');
         var caption_title = $('.full-img',$viewer).attr('title');
      if (caption_alt !== "" && caption_title !== ""){('.full-img', $viewer).after('<p class="captiontitle">' + caption_title + '</p>' + '<p class="captionalt">' + caption_alt + '</p>')}
});
4

1 回答 1

0

试试这个

$('.gallery li img').hover(function(){
        var $viewer = $(this).parents('.viewer');
        $('.full-img',$viewer).attr('src',$(this).attr('src').replace('thumb/', ''));
        $('.full-img',$viewer).attr('alt',$(this).attr('alt').replace('thumb/', ''));//missed . here
         var caption_alt = $('.full-img',$viewer).attr('alt');//missed . here
         var caption_title = $('.full-img',$viewer).attr('title');//missed . here
      if (caption_alt !== "" && caption_title !== ""){('.full-img', $viewer).after('<p class="captiontitle">' + caption_title + '</p>' + '<p class="captionalt">' + caption_alt + '</p>')}
}); //missed a . and an ending double quote "
于 2012-09-13T21:59:38.620 回答