ランダムクォートジェネレータを作っています。しかし、私はツイッターでそれを共有することはできません。私はツイッターページを取得していますが、ツイートのテキストボックスは空です。ランダムクォートジェネレータ:JqueryのTweetボタン
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>title</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="div1">
<p id="quote"></p>
<p id="author"></p>
<button id="btn">getquote</button>
<div>
<a href="https://twitter.com/intent/tweet" target="_blank">
<button type="button" id="twitter-share-button">tweet</button>
</a>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="script.js"></script>
</body>
</html>
は、ここで私は、ランダムに引用符を取得するが、私のコードでつぶやき]ボタンをクリックすると、jQueryので.attr
を使用してhref
を変更does notの私のJavascriptコード
var url1="http://api.forismatic.com/api/1.0/?method=getQuote&key=457653&format=jsonp&lang=en&jsonp=?";
//var url1=" http://date.jsontest.com/";
var getQuote=function(data){
//console.log(data);
var quot="https://twitter.com/intent/tweet?text=" + data.quoteText+data.quoteAuthor;
console.log(quot);
$('#quote').text(data.quoteText);
$('#author').text(data.quoteAuthor);
$('#twitter-share-button').attr("href", quot);
};
$(document).ready(function(){
$.getJSON(url1,getQuote,'jsonp');
});
$("#btn").on("click",function(){
$.getJSON(url1,getQuote,'jsonp');
});
です。私はそれを正しくしていますか?
どのようにあなたの 'href'が追加されていないことを知っていますか:
<a>
はあなたのボタンの直接の親であるので、あなただけで簡単にそうように、.parent()
を含めるためにあなたの$('#twitter-share-button').attr("href", quot);
行を変更できますか?私はちょうど非常にシンプルなJSFiddleを作って、あなたのメソッドが完全にうまくいくはずであることを示しました:https://jsfiddle.net/errd1p37/1/。これは私の次の質問にもつながります:なぜあなたは 'href'を' button 'に追加しようとしていますか? – Santi'href'が追加されました。私はコンソールでそれを見ることができます。しかし、ボタンをクリックすると、 'https://twitter.com/intent/tweet?text=" + data.quoteText + data.quoteAuthorの代わりに 'https:// twitter.com/intent/tweet'に行きます。 – vish09
あなたは '