我在这里有一个wordpress电子商务网站/products- page /ring/product-1-2/,我使用的是一个叫做jquery-colorbox的插件,正如你从页面链接中看到的,我有4张图片,2张是一样的,当你点击任何一张图片时,它说画廊有3张图片(这是真的),但其中1张是重复的。有没有办法从jquery-colorbox中删除重复项?我试着用谷歌搜索它,但什么也没找到:
如果有人能给我指明正确的方向,我将不胜感激。
以下是我的代码,如果有帮助的话
<div class="imagecol">
<a class="preview_link cboxElement" style="text-decoration:none;" href="/wp-content/uploads/2012/07/DSC_0118.jpg" rel="Teardrop Druzy Amethyst Ring">
<img id="product_image_736" class="product_image colorbox-736" width="400" src="/wp-content/uploads/2012/07/DSC_0118.jpg" title="Teardrop Druzy Amethyst Ring" alt="Teardrop Druzy Amethyst Ring">
<br>
<div style="text-align:center; color:#F39B91;">Click To Enlarge</div>
</a>
<div class="wpcart_gallery" style="text-align:center; padding-top:5px;">
<a class="thickbox cboxElement" title="DSC_0118" href="/wp-content/uploads/2012/07/DSC_0118.jpg" rel="Teardrop Druzy Amethyst Ring" rev="/wp-content/uploads/2012/07/DSC_0118.jpg">
<img class="attachment-gold-thumbnails colorbox-736" width="50" height="50" title="DSC_0118" alt="DSC_0118" src="/wp-content/uploads/2012/07/DSC_0118-50x50.jpg">
</a>
<a class="thickbox cboxElement" title="P7230376" href="/wp-content/uploads/2012/07/P7230376.jpg" rel="Teardrop Druzy Amethyst Ring" rev="/wp-content/uploads/2012/07/P7230376.jpg">
<img class="attachment-gold-thumbnails colorbox-736" width="50" height="50" title="P7230376" alt="P7230376" src="/wp-content/uploads/2012/07/P7230376-50x50.jpg">
</a>
<a class="thickbox cboxElement" title="P7230378" href="/wp-content/uploads/2012/07/P7230378.jpg" rel="Teardrop Druzy Amethyst Ring" rev="/wp-content/uploads/2012/07/P7230378.jpg">
<img class="attachment-gold-thumbnails colorbox-736" width="50" height="50" title="P7230378" alt="P7230378" src="/wp-content/uploads/2012/07/P7230378-50x50.jpg">
</a>
</div>
</div>我将这个添加到了我的<head></head>部分
<script type="text/javascript">
$(document).ready(function(){
var srcs = [],
temp;
$(".attachment-gold-thumbnails img").filter(function(){
temp = $(this).attr("src");
if($.inArray(temp, srcs) < 0){
srcs.push(temp);
return false;
}
return true;
}).remove();
});
</script>但还是不起作用:
发布于 2012-09-04 22:46:19
代码被复制了,但这里仍然是这样:
$(function(){
var srcs = [],
temp;
$(".attachment-gold-thumbnails img").filter(function(){
temp = $(this).attr("src");
if($.inArray(temp, srcs) < 0){
srcs.push(temp);
return false;
}
return true;
}).remove();
});有关详细信息,请查看source:
发布于 2013-11-08 23:56:34
您可以使用以下jQuery代码来实现此目的:
var arrayImgsColorbox = new Array();
$('.cboxElement').each(function(i, obj){
if($.inArray($(obj).attr('href'), arrayImgsColorbox ) > -1)
$(obj).removeClass('cboxElement');
else
arrayImgsColorbox[i] = $(obj).attr('href');
});https://stackoverflow.com/questions/12265836
复制相似问题