.attr中的data-rel(javascript)

时间:2013-09-22 05:29:27

标签: javascript jquery

尝试将data-rel添加到我的javascript .attr这是原始的attr:

link.attr('href',obj.images.standard_resolution.url);

这是我尝试过的:

link.attr('href data-rel="lightframe"',obj.images.standard_resolution.url);

我还尝试将所有链接包括在内但没有运气:

$('a').attr('data-rel', 'lightframe');

这甚至可能吗?如果是这样,使用正确的语法是什么?我在http://api.jquery.com/attr/读了很好但是没有解决我的问题?

编辑:标记:

function ProcessData(response){
    if(response != null){
        var ul = $('<ul/>');
        ul.attr({'class': tag_name});

        $(response.data).each(function(index,obj){
            if(index == 20)
                return response.pagination.next_url;
            var link = $('<a/>'), image = $('<img/>'), li = $('<li/>');

            image.attr({'src': obj.images.standard_resolution.url,
                        'width':thumb_dimension,'height': thumb_dimension});

            link.attr({'href' : obj.images.standard_resolution.url,'data-rel' : 'lightcase'});  
            image.appendTo(link);
            link.appendTo(li);


            if(include_username){
                $('<div class="username">'+obj.from.username+'</div>').appendTo(li);
            }
            if(include_caption){
                $('<div class="caption">'+obj.caption.text+'</div>').appendTo(li);
            }
            // Append the image (and text) to the list
            ul.append(li);
        });
        // Append the list to the given div
        $(div_to_add_pics).append(ul);
        // make url correlate to the next set of data
        url = response.pagination.next_url;

    }
};

1 个答案:

答案 0 :(得分:0)

尝试

var link = $('<a/>')
link.attr({
    'href': obj.images.standard_resolution.url,
    'data-rel' : 'lightframe'
});

link.attr('data-rel', 'lightframe');