我需要帮助从数组创建链接。我需要为数组中的每个项目创建一个个性化链接
以下是代码:
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;
}
答案 0 :(得分:1)
你的代码可能是这样的,你调用$ .each而不传递数组。
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;
}