自定义标题显示,jQuery,javascript

时间:2012-09-13 21:47:42

标签: javascript jquery

我正在使用我构建的图片库功能,尝试使用缩略图的图像属性在整个图像下方生成标题。具体来说, alt 标题。缩略图库方面没有问题。另一方面,标题返回未定义,并且显示在第一个缩略图下方,而不是在完整图像下方。

$('.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>')}
});

1 个答案:

答案 0 :(得分: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 "