簡體   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