繁体   English   中英

如何将图片链接到帖子?

[英]How to make an image link to the post?

我的帖子中有图片。 它们显示在我网站的主页上。 每个帖子都有一张图片,对该帖子的描述以及一个“更多”按钮,可将用户带到整篇文章。

我的问题是我想使图像链接到完整的帖子。 我希望图像充当“更多”按钮。

我尝试过使用jQuery,wrap()函数,将文章本身中的图像链接起来,到目前为止还没有任何结果。

该图像的代码仅是:

<img src="random.jpg" class="YTimgs">

有人知道我该如何使用它吗? 我一直在研究此问题,但没有找到正确的解决方案。 我希望有人能帮助我。

您的某些图像具有YTimg类,其他图像具有YTimgs ...仅给其一个类:

$(document).on("click", "img.YTimgs", function(){
    $(this).closest("div.post").find(".jump-link").find("a").trigger("click");
});

这应该很棘手

更新的小提琴: http : //jsfiddle.net/5md7p9L7/7/

<img src="http://lorempixel.com/400/200/"/>
<a class="link" href="http://google.com" target="_blank">The picture and this text are both links to the same page :)</a>

jQuery的

$('img').click(function(){
    var link =$(this).next().attr('href');
    window.open(link);   
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM