Я использую Twitter createShareButton на моем сайте (http://conn3cted.uk.tn/quote.html), но каждый раз, когда нажата кнопка «Новая цитата», создается новая кнопка Twitter, оставляя меня с несколькими кнопками (например, если Кнопка «Новая котировка» нажата 10 раз, будет 10 кнопок общего доступа).Кнопка Twitter создает несколько кнопок
Он работал отлично пару дней назад, поэтому не уверен, что, черт возьми, произошло.
My JavaScript ниже
// Random Quote Generator
$(document).ready(function() {
// Set the default values for future AJAX requests
$.ajaxSetup({
// Prevent all future AJAX requests from being cached.
cache: false
});
// API URL
var quoteURL = "http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1";
// getQuote function, which accepts a data parameter.
var getQuote = function(data) {
// Replace the html of the targeted element with the returned content field.
$(".quoteContent").html(data[0].content);
// Replace the html of the targeted element with the returned title field.
$(".quoteTitle").html('Author: ' + data[0].title);
newColor();
twttr.ready(function() {
// Use the pre-made createShareButton function
twttr.widgets.createShareButton(
// Do not share a URL
" ",
// Div where the share button should be inserted
document.getElementById('tweetButton'),
{
// Define the tweet that will be used
text: "'" + $(".quoteContent").text().replace(/(\r\n|\n|\r)/gm,"") + "'\n" +
$(".quoteTitle").text(),
// Set the size of the Twitter share button
size: "large",
}
);
});
};
var newColor = function() {
var color = Please.make_color();
$("body, button, .btn").css("background-color",color);
$("p, blockquote").css("color",color);
};
/*
* On every page load get JSON data from the URL, defined in the
* 'url' variable, and then run the getQuote function
*/
$.getJSON(quoteURL, getQuote);
//newColor();
/*
* When the button is clicked load get JSON data from the * URL,defined in the 'url' variable, and then run the
* getQuote function.
*/
$(".regenButton").click(function() {
$.getJSON(quoteURL, getQuote);
});
});
Ах, ладно! Поэтому он не понимает, что он должен только создать один - я думаю, что я запутывал настройку виджета HTML (что он делает это только один раз) с тем, что эта кнопка также не должна создавать несколько. Но это имеет смысл - это создание новой кнопки, как было сказано, просто добавив ее к указанному 'div' . Я добавил, что дополнительная строка и все работает сейчас :-) спасибо! Как вы можете сказать, я все еще учусь. Иногда я делаю глупые ошибки. – OmisNomis
Добро пожаловать, и, похоже, вы сейчас понимаете проблему! Удачи. – Pimmol