Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.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_Colorbox - Fatal编程技术网

Javascript 颜色框在图像上有两个链接,但在组中显示一次

Javascript 颜色框在图像上有两个链接,但在组中显示一次,javascript,colorbox,Javascript,Colorbox,我有2个不同的链接到同一组图像的每个图像 但是我只想在我的群导航中查看一次照片 <a href="myimg1.jpg" class="img-gallery" rel="gallery"><img src="img-place-holder.jpg"></a> <a href="myimg1.jpg" class="img-gallery" rel="gallery">open my image</a> <a href="my

我有2个不同的链接到同一组图像的每个图像 但是我只想在我的群导航中查看一次照片

<a href="myimg1.jpg" class="img-gallery" rel="gallery"><img src="img-place-holder.jpg"></a>
<a href="myimg1.jpg" class="img-gallery" rel="gallery">open my image</a>

<a href="myimg2.jpg" class="img-gallery" rel="gallery"><img src="img-place-holder.jpg"></a>
<a href="myimg2.jpg" class="img-gallery" rel="gallery">open my image</a>


通过这段代码,我在我的图库中找到了4张图像,而不是2张。我在Colorbox常见问题解答中找到了一种解决方法:这不是复制/粘贴,而是可以让你走上正确的方向

var $gallery = $("a[rel=gallery]").colorbox();
$("a#openGallery").click(function(e){
    e.preventDefault();
    $gallery.eq(0).click();
});

删除gallery按钮上的
rel
属性(防止图像复制)很重要。

为什么downvote对我有效,除非我一开始就没有抓住问题的关键?我不是downvoter,但在编辑示例之前,你可能发布了一篇简短的文章,链接只回答。这样的答案经常被否决和删除。啊哈,谢谢你的解释,我做得真是太糟糕了(我太想回答了)。下次会更加耐心和精确。