2012-02-02 24 views
-1

我有一段代碼,似乎有問題。我試過JSLint和其他工具,看看我可能有一個缺少分隔符。 Eclipse也沒有顯示任何東西。在Firebug中,完整的代碼塊顯示爲禁用的行號,如註釋行。任何人都知道一個好工具?我用ctrl + K縮進下面粘貼的代碼。JavaScript格式

$(document).ready(function() { 

     $('.startover').live('click', function() { 
      var ReInitAnswer = confirm('Are you sure you want TO start over FROM SCRATCH?'); 
        if (ReInitAnswer){ 
         return true; 
     } 
     ELSE { 
      alert('canceled'); 
      return false; 
      } 
     }); 

     $('.notdupe').live('click', function(e) { 
      alert("indivNum=" + $(e.target).val() + "&SetValue=" + $(e.target).is(":checked")); 
      $.ajax({ type: "POST", 
       url: "cfc/basic.cfc?method=SetNotDupe", 
       data: "indivNum=" + $(e.target).val() + "&SetValue=" + $(e.target).is(":checked"), 
       error: function (xhr, textStatus, errorThrown){ 
       // show error alert(errorThrown); 
       } 
      }); 
     }); 

      $('.alphabet').live('click', function(l) { 
       SelectedLetter = $(l.target).val(); 
       $(".alphabet").each(function(i){ 
         var CheckLetter = $(this).val(); 
        if (CheckLetter == SelectedLetter){ 
        $(this).css("background-color", "yellow"); 
        $('.NameBeginsWith').val(SelectedLetter); 
        } ELSE { 
        $(this).css("background-color", ""); 
        } 
      }); 

    $('.Reinit').attr('value', SelectedLetter); 
    $('.Reinit').trigger ('click'); 

    }); 

$(".alphabet").hover(function() { 
      var _$this = $(this); 
      var usercount = 0; 
      $.ajax({ type: "POST", 
      url: "scribble.cfc?method=CountUsersByLetter&returnformat=json", 
      data: "nbw=" + $(this.target).val(), 
      datatype: "html", 
      success: function(res){ 
      usercount = eval("(" + res + ")").DATA[0][0]; 
      _$this.append($("<span> (" + usercount +")</span>")); 
      }, 
      error: function (xhr, textStatus, errorThrown){ 
      console.log('errorThrown'); 
      } 
     }); 
    }, 
     function() { 
     $(this).find("span:last").remove(); 
     } 
    ); 


     }); 
+0

的一個問題是,你不能利用'ELSE'有很好的理由了。 – Ryan 2012-02-02 19:44:37

+0

對於初學者,您的「ELSE」聲明應該是小寫。 – skybondsor 2012-02-02 19:44:50

+0

嘗試http://jsbeautifier.org/ – 2012-02-02 19:45:54

回答

0

Javascript區分大小寫。

ELSE必須小寫。

0

ELSE必須是小寫

 ELSE { // <-- this is bad 
     alert('canceled'); 
     return false; 
     } 
1

這真的很難告訴你在問什麼,但如果你的意思是它誤格式化,嘗試http://jsbeautifier.org/更好的格式。下面是清理代碼(包括else不正確的外殼):

$(document).ready(function() { 
    $('.startover').live('click', function() { 
     var ReInitAnswer = confirm('Are you sure you want TO start over FROM SCRATCH?'); 
     if(ReInitAnswer) { 
      return true; 
     } else { 
      alert('canceled'); 
      return false; 
     } 
    }); 

    $('.notdupe').live('click', function(e) { 
     alert("indivNum=" + $(e.target).val() + "&SetValue=" + $(e.target).is(":checked")); 
     $.ajax({ 
      type: "POST", 
      url: "cfc/basic.cfc?method=SetNotDupe", 
      data: "indivNum=" + $(e.target).val() + "&SetValue=" + $(e.target).is(":checked"), 
      error: function (xhr, textStatus, errorThrown) { 
       // show error alert(errorThrown); 
      } 
     }); 
    }); 

    $('.alphabet').live('click', function(l) { 
     SelectedLetter = $(l.target).val(); 
     $(".alphabet").each(function (i) { 
      var CheckLetter = $(this).val(); 
      if(CheckLetter == SelectedLetter) { 
       $(this).css("background-color", "yellow"); 
       $('.NameBeginsWith').val(SelectedLetter); 
      } else { 
       $(this).css("background-color", ""); 
      } 
     }); 

     $('.Reinit').attr('value', SelectedLetter); 
     $('.Reinit').trigger('click'); 
    }); 

    $(".alphabet").hover(function() { 
     var _$this = $(this); 
     var usercount = 0; 
     $.ajax({ 
      type: "POST", 
      url: "scribble.cfc?method=CountUsersByLetter&returnformat=json", 
      data: "nbw=" + $(this.target).val(), 
      datatype: "html", 
      success: function(res) { 
       usercount = eval("(" + res + ")").DATA[0][0]; 
       _$this.append($("<span> (" + usercount + ")</span>")); 
      }, 
      error: function(xhr, textStatus, errorThrown) { 
       console.log('errorThrown'); 
      } 
     }); 
    }, function() { 
     $(this).find("span:last").remove(); 
    }); 
}); 
+0

似乎很奇怪,像其他人/ ELSE的問題不會顯示爲一個問題。無論如何,這是訣竅。非常感謝。 – user990016 2012-02-02 19:57:26