[英]replace the href value with label text in asp.net
我想做的是在Twitter上將標簽文本值共享為url鏈接,但未按預期工作。 我的代碼怎么了..
我的標簽值是從db生成的:
<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;
});
});
您的ID錯誤,請將此行更改為:
var para = $('#lblReferralURL').textContent;
嘗試這個。 用您的網址更改http://www.example.com/ ,並用文本更改新文本。
$(document).ready(function(){ $("#TwitterLink").attr("href", "http://www.example.com/"); $("#TwitterLink").html("New Text"); });
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.