0

我正在构建一个图像库,并且已经能够将单击的缩略图图像加载到主#large div 一个新的标签 src 中。我也在尝试获取 rel 属性,以便在标签中填充 rel 属性。

这是我的代码...

$(document).ready(function() {
    $('a.thumbnail').live("click", function() {
        $('#large').hide();
        $('#project-image').css('background-image', "url('/assets/images/ajax-loader.gif') no-repeat");

     //   var i = $('<img />').attr('src',this.href).load(function() {

        var i = $('<img />').attr({    
        src: this.href,
        rel: MISSING REL SELECTOR

        }).load(function() {




            $('#large').attr('src', i.attr('src'));
            $('#large').attr('rel', i.attr('rel'));
          $('#project-image').css('background-image', 'none');
            $('#large').fadeIn();
    });

        return false; 
    });
});

在 i 数组中加载 rel 属性的正确选择器是什么?

4

3 回答 3

2

我想你想要:

rel: this.attr('rel')
于 2011-11-23T22:15:35.360 回答
2

我想你要使用$(this).attr('rel'),而不是简单this.attr('rel')

于 2011-11-23T22:26:44.473 回答
0

也许你需要一个

$(this).children('img').attr('rel')

代替您的 MISSING REL SELECTOR

于 2011-11-23T22:27:43.160 回答