简体   繁体   English

如何将图片链接到帖子?

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

My posts have an image in them. 我的帖子中有图片。 They are shown in the homepage of my site. 它们显示在我网站的主页上。 Each post has a picture, a description about the post, and a "more" button which takes the user to the full article. 每个帖子都有一张图片,对该帖子的描述以及一个“更多”按钮,可将用户带到整篇文章。

My issue is that I want to make the image link to the full post. 我的问题是我想使图像链接到完整的帖子。 I want the image to function as the "more" button. 我希望图像充当“更多”按钮。

I have tried using jQuery, wrap() function, linking the image in the article itself, nothing has worked out so far. 我尝试过使用jQuery,wrap()函数,将文章本身中的图像链接起来,到目前为止还没有任何结果。

The code for the image is just: 该图像的代码仅是:

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

Does anybody know how I can get this to work? 有人知道我该如何使用它吗? I have been working on this issue and have not found the correct solution. 我一直在研究此问题,但没有找到正确的解决方案。 I hope someone helps me out. 我希望有人能帮助我。

Some of your images have class YTimg , others have YTimgs ... give it only one class: 您的某些图像具有YTimg类,其他图像具有YTimgs ...仅给其一个类:

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

And this should do the tricky 这应该很棘手

Updated fiddle: http://jsfiddle.net/5md7p9L7/7/ 更新的小提琴: 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 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