[英]Javascript Tweet Button not linking
我想知道我的tweet按鈕有什么問題,有人可以檢查我的代碼嗎? 鏈接不會生成推文。
在這里檢查我的代碼。
http://codepen.io/mochiii/pen/YyqmJP
$(document).ready(function(){
$(".tweet-hold a").hide();
$("button").click(function(){
$.getJSON("http://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?", function(response){
$(".quote").html("<p>" + response.quoteText + "</p>");
$(".author").html("<p>" + response.quoteAuthor + "</p>");
});
$(".tweet-hold a").show();
var tweet="http://twitter.com/intent/tweet?text=" + response.quoteText;
if(response.quoteAuthor!==""){
tweet+=" - " + response.quoteAuthor;
}
$(".tweet-hold a").click(function(tweet){
$(this).attr('href', tweet);
});
});
});
看來您需要稍微修改一下代碼。
$(document).ready(function(){
$(".tweet-hold a").hide();
$("button").click(function(){
$.getJSON("http://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?", function(response){
$(".quote").html("<p>" + response.quoteText + "</p>");
$(".author").html("<p>" + response.quoteAuthor + "</p>");
});
$(".tweet-hold a").show();
var tweet="http://twitter.com/intent/tweet?text=" + response.quoteText;
if(response.quoteAuthor!==""){
tweet+=" - " + response.quoteAuthor;
}
});
$(".tweet-hold a").click(function(tweet){
$(this).attr('href', tweet);
});
});
當我嘗試使用您的Codepen時,這似乎工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.