0

我有一个示例代码:在 Javascript 中:

function initFB(appId) {
    this.appId = appId;
    window.fbAsyncInit = function() {
        FB.init({appId: appId, status: true, cookie: true, xfbml: true});

        // Additional initialization code such as adding Event Listeners goes here
        insertLikeButton('https://www.facebook.com/cocacola', 'facebooklike')
    };

    if(document.getElementById('fb-root')) return;
    var fbr = document.createElement('div'); fbr.id = 'fb-root';
    document.getElementsByTagName('body')[0].appendChild(fbr);
    (function(d, s, id, appId) {
        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&appId=' + appId;
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk', this.appId));

    function insertLikeButton(url, id) {
        var lb = document.createElement('fb:like');
        lb.id = 'fblike';
        lb.setAttribute('width', '450');
        lb.setAttribute('href', this.url);
        lb.setAttribute('show_faces', 'false');

        lb.style.overflow = 'hidden';
        lb.style.cursor = 'pointer';
        lb.style.width = '50px';
        lb.style.height = '25px';
        lb.style.zIndex = '99999';
        document.getElementById(this.id).appendChild(lb);
    }  
}

和 html

<div id="facebooklike"></div>
<script>
var fb = new initFB('zzzzzz');
</script>

当我运行代码时,按钮无法显示,如何解决?

4

0 回答 0