【发布时间】:2018-02-24 23:30:35
【问题描述】:
我正在创建一个随机报价生成器。我已经使用quotesondesign.com的api完成了大部分工作,但我需要做的最后一件事是当我单击“新报价”按钮时将推特按钮更新为新报价。但它不会改变,我不知道为什么。
$( document ).ready(function() {
//get Quote And call to update twitter Button
$.getJSON("https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=", function(a) {
$("#quote-content").html(a[0].content);
$("#quote-title").text(a[0].title);
updateTweet(a);
});
//new Quote and update Twitter
$('#newButton').on('click', function() {
$.ajax( {
url: 'https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=',
success: function(a) {
$('#quote-content').html(a[0].content);
$('#quote-title').text(a[0].title);
updateTweet(a);
},
cache: false
});
});
//update twitter button function
function updateTweet(a) {
var thisQuote = a[0].content.replace(/<\/?[^>]+(>|$)/g, "");
var thisQuoteTitle = a[0].title;
$(".twitter-share-button").attr("href", "https://twitter.com/intent/tweet?text=" + thisQuote + "- " + thisQuoteTitle);
}
});
这是我正在处理的代码笔:https://codepen.io/Uberche/pen/RLbjbp
我意识到它很丑而且设置不正确,只是在更改样式等之前尝试让功能正常工作。任何帮助,将不胜感激。对不起,如果这是我忘记包含的一些愚蠢的东西,还在学习 javascript 并且忘记了很多东西......
【问题讨论】:
标签: javascript jquery html css twitter