Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使每个数组项成为单独的链接_Javascript_Jquery_Fancybox - Fatal编程技术网

Javascript 使每个数组项成为单独的链接

Javascript 使每个数组项成为单独的链接,javascript,jquery,fancybox,Javascript,Jquery,Fancybox,我需要帮助从数组创建链接。我需要为阵列中的每个项目创建个性化链接 代码如下: caption: function(instance, item) { var caption, link, collectTags, tags; caption = $(this).data('caption'); link = '<a href="' + item.src + '">Download image</a>'; collectTags = $(th

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

代码如下:

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;
}
标题:函数(实例,项){
变量标题、链接、集合标记、标记;
caption=$(this.data('caption');
链接='';
collectTags=$(this.parent().attr(“类”).split(“”);
标记=$。每个(函数(){
''
});
返回(标题?标题+'
':'')+链接+'
'+标记; }
您的代码可能是这样的,您调用了$。每个都没有传递数组

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;

}
标题:函数(实例,项){
变量标题、链接、集合标记、标记;
caption=$(this.data('caption');
链接='';
collectTags=$(this.parent().attr(“类”).split(“”);
tags=$.map(collectTags,函数(it){返回“”;});
返回(标题?标题+'
':'')+链接+'
'+标记; }
那么,您的代码有什么问题?您面临什么问题?您能否创建一个示例链接,以便我们看到您的问题并尝试纠正它?此列表列出了阵列,但没有为每个阵列创建链接。我已更新了我的答案,此代码对您适用。您必须使用
map
而不是
each
,您对此有何见解?