2013-03-01 105 views
3

为什么这不起作用?FB.XFBML.parse未捕获[object Object]

$('.fb-like-button').each (function(){ 
    if ($(this).html() == "" || !$(this).html() || $(this).html() == "undefined") 
     { 
      $(this).html('<fb:like href="'+$(this).attr("data-url")+'" layout="button_count" send="false" show_faces="false" width="100" action="like" font="verdana" colorscheme="light" />'); 
      FB.XFBML.parse($(this)); 
      $(this).attr("class", "done"); 
     } 
}); 

错误:未捕获的翻译:

+0

$(this).attr(“data-url”)你可以提醒这个检查网址吗? – 2013-03-01 12:59:22

+0

是的,我做了:console.log($(this).attr(“data-url”))和url是正确的。错误在这里:FB.XFBML.parse($(this)); – mitch 2013-03-01 13:03:33

回答

2

好的,我找到了解决办法。我不知道为什么,但这个作品:

FB.XFBML.parse($(this).get(0)); 
+1

原因:parse()正在等待DOM Element Object作为参数,而不是jQuery Object。 – fyodorananiev 2013-07-02 09:08:43

相关问题