2016-09-10 1 views
0

「Get Quote」ボタンをクリックすると、取得されたdivにさまざまな引用符が表示されるページを設計しましたAPIから。私はツイッターシャッターボタンを追加したい。しかし、Twitterのボタンの "data-text"属性の値を動的に変更する方法については本当に混乱しています。私はAPIからデータを処理するためにjQueryを使用しています。したがって、jQueryを使用して「データ・テキスト」の値を変更するにはどうすればよいですか?jqueryを使用したAPIからの入力データに基づいてTwitterボタンのデータテキスト属性の値を動的に変更

コードは次のとおりです。

HTML:

<body> 
    <h1><div id="quotegot" class="well well-lg quote"></div></h1> 
    <button type="submit" class="btn btn-success btn-lg" id="quoteid">Get Quote</button> 
    <a href="https://twitter.com/share" class="twitter-share-button" data-show-count="false" data-text="hello">Tweet</a><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script> 
</body> 

JS:

$("#quoteid").on("click",function(){ 
    $.getJSON("http://api.forismatic.com/api/1.0/?method=getQuote&key=457653&format=json&lang=en",function(quotejson){ 
     $("#quotegot").html(quotejson["quoteText"]); 
    }); 
}); 
$(".twitter-share-button").attr("data-text", $(".quote").text()); 
+0

コードを入力してください(APIデータを処理するコード) – lucasnadalutti

答えて

関連する問題