2012-07-14 30 views
1

我碰到的JSLint以下錯誤,我不明白他們:未知的JSLint錯誤

- 所有問題都得到了回答道

任何這些任何幫助嗎?

use /*jslint browser: true, devel: true */ 
function submit() { 
    "use strict"; 
    document.forms.form.submit(); 
    var Mathematics = document.personal.Mathematics; 
    var OMathematics = document.personal.OMathematics; 
    var Sci = document.personal.Sci; 
    var OSci = document.personal.OSci; 
    var ELA = document.personal.ELA; 
    var OELA = document.personal.OELA; 
    var SS = document.personal.SS; 
    var OSS = document.personal.OSS; 
    var Elec1 = document.personal.Elec1; 
    var OElec1 = document.personal.OElec1; 
    var Elec2 = document.personal.Elec2; 
    var OElec2 = document.personal.OElec2; 
    var Elec3 = document.personal.Elec3; 
    var OElec3 = document.personal.OElec3; 
    var Owed = 0; 
    function calc(n, o) { 
     if (n >= 90) { 
      Owed = Owed + 1; 
      if (n >= 95) { 
       Owed = Owed + 1; 
      } 
     } 
     else if (o >= 80) { 
      Owed = Owed + 0.5; 
     } 
     if (n > o) { 
      Owed = Owed + 0.5; 
     } 
     if (n < o) { 
      if (n > 95) { 
       Owed = Owed - 0.25; 
      } 
     } 
    } 
    calc(Mathematics, OMathematics); 
    calc(Sci, OSci); 
    calc(ELA, OELA); 
    calc(SS, OSS); 
    calc(Elec1, Elec1); 
    calc(Elec2, Elec2); 
    calc(Elec3, Elec3); 
    alert(Owed); 
}​ 

這是在上下文中的代碼:使用http://jsfiddle.net/Aidoboy/AdzwC/

例外:「每個功能的許多VAR聲明」和「亂空白」

+0

哪裏是你的代碼?張貼在這裏。 – 2012-07-14 22:17:43

+0

添加了代碼。 – 2012-07-14 22:30:12

+0

總是在問題本身中包含相關的代碼和標記**,請不要鏈接:http://meta.stackexchange.com/questions/118392/add-stack-overfow-faq-entry-or-similar-代碼問題 – 2012-07-14 22:33:06

回答

13

' document ' was used before it was defined

你得到這個,因爲document變量尚未宣佈。您可以告訴JSLint它應該假設代碼將在瀏覽器中運行,並因此認爲預先定義了諸如documentwindow之類的內容。

/*jslint browser: true */ 

['form'] is better written in dot notation

你既然知道了屬性的名稱,也沒有必要使用方括號:

你可以在你的文件的頂部與JSLint的評論這樣做
document.forms.form.submit(); 

' alert ' was used before it was defined

可以使用devel選項ŧ Ø防止出現此錯誤(你還用它允許,例如,console.log電話):

/*jslint browser: true, devel: true */ 

Unexpected '​'

有右括號後,一些不可見字符。只要刪除該字符以消除此錯誤。

+0

我仍然收到'alert'的錯誤 – 2012-07-14 23:02:29

+0

使用'/ * jslint browser:true,devel:true * /' - 不確定我對上述答案的編輯將通過 – olore 2012-07-14 23:21:36

+0

@olore - 感謝編輯。我只是修改了一下,將它添加到'alert'錯誤的部分,而不是'document'錯誤的部分。 – 2012-07-14 23:25:09

1

添加是爲了避免警報定義錯誤:

/*jslint devel: true */ 

「alert」 is not defined when running www.jshint.com - Stack Overflow

and the following about the devel option:

This option defines globals that are usually used for logging poor-man's debugging: console, alert, etc. It is usually a good idea to not to ship them in production because, for example, console.log breaks in legacy versions of Internet Explorer.