2014-01-05 50 views
-1

我已嘗試幾個小時才能使此程序正常工作,但我現在得到這些錯誤並不知道我做了什麼錯誤,任何幫助表示讚賞。未捕獲的SyntaxError和未捕獲的ReferenceError

Uncaught SyntaxError: Unexpected token {
Uncaught ReferenceError: start is not defined
Uncaught ReferenceError: global is not defined

Il將錯誤放在代碼中,以便您知道它們來自哪裏。

<html> 
<head> 
    <title>Uppgift 6</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <script type="text/javascript"> 
     var $NS {}; <---Uncaught SyntaxError: Unexpected token { 
     $NS.Vara = function() { 
      this.namn = Mjölk; 
      this.pris = 17; 
      this.beskrivning= Arla 3%; 
      this.antal= 40; 
      this.calcSubTotal = function() { 
       document.getElementById("resultat").value = this.pris * this.antal; 
      }; 
     }; 
     var global; 
     function start() { <---Uncaught ReferenceError: start is not defined 
      global = new $NS.Vara(); <--- Uncaught ReferenceError: global is not defined 
     } 
    </script> 
</head> 
<body onload="start()"> 
    <form> 
     <input type="button" value="Value" onClick="global.calcSubTotal()"/> 
     <input type="text" id="resultat"/> 
    </form> 
</body> 
</html> 
+2

好了,你有什麼期待* *'變量$ NS {};'怎麼辦?那*不是一個語法錯誤? – Doorknob

+0

那麼它的一個對象我用作命名空間? – user3162932

+2

但是這個有效的語法怎麼樣?! – Doorknob

回答

1

我認爲錯誤從丟失= var $NS後,常量字符串分配給namnbeskrivning不受'"封閉的開始。

嘗試:

var $NS = {}; <---Uncaught SyntaxError: Unexpected token { 
$NS.Vara = function() { 
    this.namn = "Mjölk"; 
    this.pris = 17; 
    this.beskrivning= "Arla 3%"; 
    this.antal= 40; 
    this.calcSubTotal = function() { 
     document.getElementById("resultat").value = this.pris * this.antal; 
    }; 
}; 
var global; 
function start() { <---Uncaught ReferenceError: start is not defined 
    global = new $NS.Vara(); <--- Uncaught ReferenceError: global is not defined 
} 
相關問題