我想要做的是在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;
});
});
答案 0 :(得分:1)
您的ID错误,请将此行更改为:
var para = $('#lblReferralURL').textContent;
答案 1 :(得分:0)
试试这个。使用您的网址更改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>