将facebook喜欢按钮添加到div中

时间:2013-05-01 09:46:41

标签: javascript jquery facebook facebook-like

任何想法为什么facebook按钮不起作用? -------------------------------------------------- --------------------------------

演示:http://jsfiddle.net/9DWTf/

CSS

.test { margin:20px; padding:20px; background-color:#cccccc; border:1px solid #000000; cursor:pointer; }
.fl { float:left; }
.cb { clear:both; }

HTML

<div id="fb-root"></div>
<div id="test_1" class="test">Test link 1 Google</div>
<div id="test_2" class="test">Test link 2 jsfiddle</div>

JS

$(document).ready(function()
{
    $('#test_1').click(function() { lika('#test_1','http://google.de','myImg.jpg','Text text');  });
    $('#test_2').click(function() { lika('#test_2','http://jsfiddle.net','myImg.jpg','Text text');  });    
});

function lika(selector,likeUrl,likeImg,likeDesc,insertMode)
{
    var genHtml = '<div style="width:93px; height:61px; " class="fl"> <div class="fb-like" data-href="'+likeUrl+'" data-send="false" data-layout="box_count" data-width="450" data-show-faces="false" data-font="tahoma"></div> </div> <div style="width:69px; height:61px; " class="fl"> <su:badge layout="5" location="'+likeUrl+'"></su:badge></div> <div style="width:69px; height:61px; " class="fl"> <div class="g-plusone" data-href="'+likeUrl+'" data-size="tall"></div> </div> <div style="width:93px; height:61px;" class="fl"> <div style="margin-top:12px;"><a href="https://twitter.com/share" class="twitter-share-button" data-url="'+likeUrl+'" data-via="dokucc" data-lang="de">Twittern</a></div> <div style="margin-top:5px;"><a href="//pinterest.com/pin/create/button/?url='+likeUrl+'&media='+likeImg+'&description='+likeDesc+'" data-pin-do="buttonPin" data-pin-config="beside"><img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" /></a></div> </div>  <div class="cb"></div>';

    $(selector).append(genHtml);

    // Google Plus
    window.___gcfg = {lang: 'de-DE'};
    $.getScript('https://apis.google.com/js/plusone.js');

    // Facebook
    $.getScript('http://connect.facebook.net/en_GB/all.js#xfbml=1&appId=103416386490092');

    // Twitter
    $.getScript('http://platform.twitter.com/widgets.js');

    // Stumbleupon
    var li = document.createElement('script'); li.type = 'text/javascript'; li.async = true;
    li.src = ('https:' == document.location.protocol ? 'https:' : 'http:') + '//platform.stumbleupon.com/1/widgets.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(li, s);
}

1 个答案:

答案 0 :(得分:0)

我明白了。

$.getScript('http://connect.facebook.net/de_DE/all.js#xfbml=1&appId=197419270383446', function ()
{
    FB.XFBML.parse(document.getElementById('#likeBox'));
});