1

我可以在http://learn.knockoutjs.com/#/?tutorial=intro上做在线教程,但是当我尝试在一个空的 ASP.NET 项目的 HTML 页面中做同样的事情时,它就不起作用了。为什么?

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts/knockout-2.3.0.js"></script>
    <script type="text/javascript">
        function AppViewModel() {
            this.firstName = "Bert";
            this.lastName = "Bertington";
        }

        ko.applyBindings(new AppViewModel());
    </script>
</head>
<body>
    <p>First name: <strong data-bind="text: firstName"></strong></p>
    <p>Last name: <strong data-bind="text: lastName"></strong></p>
</body>
</html>
4

1 回答 1

3

I looked at another link and it works if I move the ko.appyBindings to the bottom:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts/knockout-2.3.0.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">
        function AppViewModel() {
            this.firstName = "Bert";
            this.lastName = "Bertington";
        }

        ko.applyBindings(new AppViewModel());
    </script>
</body>
</html>
于 2013-07-24T19:14:48.303 回答