javascript-如何调试缺少的Facebook点赞按钮?
作者:互联网
我正在尝试使用jQuery将Like Button和Tweet Button附加到页面上. “鸣叫”按钮可以正常工作,但“赞”按钮不会出现.我不知道出了什么问题,但是更糟糕的是,我没有收到任何错误或表明有问题的消息.
如何获得Facebook,Firebug或其他任何东西来告诉我所缺少的内容,或引发适当的错误?
对于那些不想去jsfiddle的人,这是完整的代码:
/**
* Generate the container elements for social media stuff.
*/
$(function generateSocMedElements($) {
var id = "socmed",
$container,
$fb_root,
$fb_like,
$tweet_button;
if ($("#" + id).length <= 0) {
$container = $(document.createElement("aside")).
addClass("socmed").
attr("id", id);
$fb_root = $(document.createElement("div")).attr("id", "fb-root");
$fb_like = $(document.createElement("div")).
addClass("fb-like").
attr("data-href", "example.org").
attr("data-send", "false").
attr("data-layout", "button_count").
attr("data-width", 82).attr("data-show-faces", "false");
$tweet_button = $(document.createElement("a")).
addClass("twitter-share-button").
attr("href", "//twitter.com/share").
attr("data-count", "none").
text("Tweet");
$container.
appendTo($("header").first()).
append($fb_root).
append($fb_like).
append($tweet_button);
}
});
/**
* Load the script for the Facebook API.
*/
$(function loadFacebook($) {
var id = "facebook-jssdk";
if ($("#" + id).length <= 0) {
$(document.createElement("script")).
attr("id", id).
attr("src", "//connect.facebook.net/en_US/all.js").
appendTo("head");
}
});
/**
* Load the script for the Twitter API.
*/
$(function loadTwitter($) {
var id = 'twitterSdk';
if ($("#" + id).length <= 0) {
$(document.createElement("script")).
attr("id", id).
attr("src", "//platform.twitter.com/widgets.js").
appendTo("head");
}
});
解决方法:
http://jsfiddle.net/ShawnsSpace/btN89/3/我能够通过它来工作
>在标题中添加div标签
>将generateSocMedElements()包装在一个函数中,并在页面加载后调用.
>使用了facebook html5脚本.
.您将不得不tweek得到想要的外观.
<header><h1>OH HAI I HAZ A HEADER</h1>
<div id="fb-root"></div>
</header>
/**
* Load the script for the Facebook API.
*/
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
/**
* Load the script for the Twitter API.
*/
$(function loadTwitter($) {
var id = 'twitterSdk';
if ($("#" + id).length <= 0) {
$(document.createElement("script")).
attr("id", id).
attr("src", "//platform.twitter.com/widgets.js").
appendTo("head");
}
});
function loadthis($){
$(function generateSocMedElements($) {
var id = "socmed",
$container,
$fb_root,
$fb_like,
$tweet_button;
if ($("#" + id).length <= 0) {
$container = $(document.createElement("aside")).
addClass("socmed").
attr("id", id);
$fb_root = $(document.createElement("div")).attr("id", "fb-root");
$fb_like = $(document.createElement("div")).
addClass("fb-like").
attr("data-href", "example.org").
attr("data-send", "false").
attr("data-layout", "button_count").
attr("data-width", 82).attr("data-show-faces", "false");
$tweet_button = $(document.createElement("a")).
addClass("twitter-share-button").
attr("href", "//twitter.com/share").
attr("data-count", "none").
text("Tweet");
$container.
appendTo($("header").first()).
append($fb_root).
append($fb_like).
append($tweet_button);
}
});
}
loadthis($);
标签:dom,facebook-like,javascript,jquery 来源: https://codeday.me/bug/20191102/1988520.html