0

我无法将 Knockout.js 连接到我的项目。jQuery 和淘汰赛存储在“脚本”文件夹中。怎么了?当我运行一个项目时,我只看到“名字”和“姓氏”。空白而不是“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>

请帮我。

4

1 回答 1

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>
于 2013-11-03T19:43:37.850 回答