2013-03-01 101 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

相關問題