2016-02-12 47 views
0

我試圖做的是在twitter上共享標籤文本值作爲url鏈接,但它不按預期工作。什麼錯我的代碼..從數據庫生成用asp.net中的標籤文本替換href值

我的標籤值:

<asp:Label ID="lblReferralURL" runat="server" Text="" ForeColor="Blue" Font-Bold="true"></asp:Label> 

<a href="https://twitter.com/intent/tweet?url=https://google.com" id="TwitterLink" class="twitter" onclick="window.open(this.href, 'mywin','left=300,top=100,width=650,height=500,toolbar=1,resizable=0'); return false;">Tweet New</a> 

$(document).ready(function() { 
      var para = $('#cphPage_lblReferralURL').html(); 
      $('#TwitterLink').attr('href', function() {    

       return this.href + '?url=' + para; 
      });   
     }); 

回答

1

你的ID是錯的變化這一行到:

var para = $('#lblReferralURL').textContent; 
0

試試這個。更改http://www.example.com/與您的網址和新文本與您的文字。

$(document).ready(function(){ 
 
\t \t \t $("#TwitterLink").attr("href", "http://www.example.com/"); 
 
\t \t \t $("#TwitterLink").html("New Text"); \t \t \t 
 
\t \t });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<a href="https://twitter.com/intent/tweet?url=https://google.com" id="TwitterLink" class="twitter" onclick="window.open(this.href, 'mywin','left=300,top=100,width=650,height=500,toolbar=1,resizable=0'); return false;">Tweet New</a>