[英]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.