我无法将Knockout.js连接到我的项目。 jQuery和knockout存储在“Scripts”文件夹中。怎么了?当我运行一个项目时,我只看到“名字”和“姓氏”。空白而不是“Bert”和“Bergton” 源文件:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title></title>
<link href="/Content/site.css" rel="stylesheet"/>
<script src="/Scripts/modernizr-2.6.2.js"></script>
<script src="/Scripts/jquery-1.8.2.js"></script>
</head>
<body>
<p>First name: <strong data-bind="text: firstName"></strong></p>
<p>Last name: <strong data-bind="text: lastName"></strong></p>
<script type="text/javascript" src="Scripts/knockout-2.2.0.js">
function AppViewModel() {
this.firstName = "Bert";
this.lastName = "Bergton";
}
// Activates knockout.js
ko.applyBindings(new AppViewModel());
</script>
</body>
</html>
请帮助我。
答案 0 :(得分:1)
您没有关闭Knockout脚本标记。
以下是更正后的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title></title>
<link href="/Content/site.css" rel="stylesheet"/>
<script src="/Scripts/modernizr-2.6.2.js"></script>
<script src="/Scripts/jquery-1.8.2.js"></script>
</head>
<body>
<p>First name: <strong data-bind="text: firstName"></strong></p>
<p>Last name: <strong data-bind="text: lastName"></strong></p>
<script type="text/javascript" src="Scripts/knockout-2.2.0.js"></script>
<script type="text/javascript">
function AppViewModel() {
this.firstName = "Bert";
this.lastName = "Bergton";
}
// Activates knockout.js
ko.applyBindings(new AppViewModel());
</script>
</body>
</html>