2013-03-16 79 views
-1

我收到此錯誤:的JavaScript:語法錯誤:之後的參數列表中缺少「}」

SyntaxError: missing '}' after argument list 

有了這個代碼:

(function(d, debug){ 
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
    if (d.getElementById(id)) {return;} 
    js = d.createElement('script'); js.id = id; js.async = true; 
    js.src = "//connect.facebook.net/en_US/all" + 
     (debug ? "/debug" : "") + ".js"; 
    ref.parentNode.insertBefore(js, ref); 
    }(document, false)); 

var checkboxes = document.querySelectorAll('input[type="checkbox"]'), 
    numCheckboxes = checkboxes.length, 
    x; 

$(function(){ 
    // Set up so we handle click on the button 
    $('#like_all').click(function(){ 
     for(x=0;x<numCheckboxes;x++) { //the error is indicated here 
     if (checkboxes[x].checked === true) { 
     FB.api(
     'me/og.likes' 
     'post', 
     { 
      object: checkboxes[x].value; 
     }, 
     function(response) { 
      if(response===null) 
      { 
      alert("Could not like page "+checkboxes[x].name); 
      } 
     } 
     ) 

    }}}) 
    }); 

什麼樣的語法錯誤造成這個錯誤,我該怎麼辦修理它?

+0

在我的瀏覽器(Google Chrome Web Developer Tools)中,我輸入了代碼的第一部分,一切都正常。我從控制檯得到了這個:「'fb-root」div尚未創建,自動創建''。 – 2013-03-16 21:46:15

+0

@EricaXu我只放了javascript代碼,但'fb-root div'存在於我的代碼中 – 2013-03-16 21:48:02

+0

正確縮進代碼並使用[JSHint](http://www.jshint.com/),你會發現你的問題。 – elclanrs 2013-03-16 21:56:07

回答

2

嘿問題是線21.對FB.api

FB.api(
    'me/og.likes' 
    'post', 
    { 

兩個參數之間缺少逗號應

FB.api(
    'me/og.likes', 
    'post', 
    { 
+0

看起來像是其中一個問題,但錯誤仍然存​​在。謝謝。好的,這是一個改變,我將編輯問題 – 2013-03-16 21:53:38

+0

另一個錯誤是在第25行的對象聲明中的分號(';') – 2013-03-16 22:00:34

+0

上面的第25行是'function(response)'。你的意思是? 'object:checkboxes [x] .value;' – 2013-03-16 22:03:45

0

在第一行沒有美元符號?
你有試過嗎?

$(function(d, debug){ 
+0

我試過了,沒有改變 – 2013-03-16 21:54:40

相關問題