使每个数组项目一个单独的链接



我需要从数组创建链接的帮助。我需要为阵列中的每个项目创建个性化链接

这是代码:

caption: function(instance, item) {
    var caption, link, collectTags, tags;
    caption = $(this).data('caption');
    link = '<a href="' + item.src + '">Download image</a>';
    collectTags = $(this).parent().attr("class").split(' ');
    tags = $.each(function() {
        '<a href="' + collectTags + '">' + collectTags + '</a>'
    });
    return (caption ? caption + '<br />' : '') + link + '<br/>' + tags;
}

您的代码可能是这样的,您打电话给$。eash,而无需传递数组。

caption : function( instance, item ) {
    var caption, link, collectTags, tags;
    caption = $(this).data('caption');
    link    = '<a href="' + item.src + '">Download image</a>';
    collectTags =   $(this).parent().attr("class").split(' ');
    tags = $.map(collectTags,function(it){ return '<a href="' + it + '">'+ it +'</a>';});
    return (caption ? caption + '<br />' : '') + link + '<br/>' + tags;
}

最新更新