簡體   English   中英

我怎樣才能使分享這個按鈕分享它留在旁邊的鏈接?

[英]How can I make the Share This button to share the link it stays beside?

這個分享這個按鈕也是如此,它做得很好,除了沒有分享鏈接的事實還在旁邊,但頁面的鏈接仍然存在。

例如StackOverflow Link分享這個按鈕。

問題:我怎樣才能讓這個按鈕分享它留在旁邊的鏈接,在這種情況下,分享 StackOverflow 鏈接?

我幾乎是 JS 的新手,所以如果有人可以在這里分享整個工作代碼將不勝感激:)

謝謝大家:) VD

假設您的鏈接是一個錨點( <a... /> )並且您的按鈕是一個按鈕( <input type="button" /> ),您可以將它們都包裝在一個容器中並執行以下操作:

<div>
  <a href="http://www.stackoverflow.com/">link</a>  
  <input type="button" value="share link" />
</div>

$(document).ready(function() {
  $('input:button').click(function() {
    var url = $(this).parent().find('a').attr('href');
    // do something to share url.
  });
});

示例: http://jsfiddle.net/fallen888/PaJLT/2/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM