我已经尝试了几个小时让这个程序运行但我现在得到了这些错误,并且不知道我做错了什么,感谢任何帮助。
未捕获的SyntaxError:意外的令牌{
未捕获的ReferenceError: start未定义
未捕获的ReferenceError:全局不是 定义
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>
答案 0 :(得分:1)
我认为错误从var $NS
之后的缺失=开始,分配给namn
和beskrivning
的常量字符串未被'
或"
括起来
尝试:
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
}