0

我是KnockoutJs的新手,我尝试了其官方网站上的所有教程。
现在我想在我的本地机器上运行所有的实用教程,我已经下载了knockout-2.1.0.js

我试过这段代码,但它不能在本地机器上工作

index.php
---------
<!DOCTYPE html>
<html>
    <head>
        <title>Knockout</title>
        <script src="js/knockout-2.1.0.js"></script>
        <link rel="stylesheet" href="css/styles.css" />
        <script>
        // This is a simple *viewmodel* - JavaScript that defines the data and behavior of your UI
        function AppViewModel() {
            this.myname= ko.observable("Frank");
            this.myage= ko.observable("26");

            this.mydetails= ko.computed(function() {
                var x;
                return this.myname() + ", and my age is " + this.myage() + 'yr. old.';
            }, this);

            this.capitalizeMyName = function() {
                var currentVal = this.myname();        // Read the current value
                this.myname(currentVal.toUpperCase()); // Write back a modified value
            };
        }

        // Activates knockout.js
        ko.applyBindings(new AppViewModel());
        </script>
    </head>
    <body>
    <p>New Application</p>
        <!-- This is a *view* - HTML markup that defines the appearance of your UI -->
        <p>My Name: <strong data-bind="text: myname"></strong></p>
        <p>My Age: <strong data-bind="text: myage"></strong></p>

        <p>My Name: <input data-bind="value: myname" /></p>
        <p>My Age: <input data-bind="value: myage" /></p>

        <p>Full Detalis: <strong>Hi, my name is <text data-bind="text: mydetails"></strong></p>

        <button data-bind="click: capitalizeMyName">Go caps</button>
    </body>
</html>

如果有人对此有知识或想法,请建议我。谢谢!

4

1 回答 1

1

http://code.jquery.com/jquery-1.7.2.min.js

你需要包括缩小文件:js/jquery-1.7.2.min.js

And put your viewmodel code between:

  $(document).ready(function(){

  // This is a simple *viewmodel* - JavaScript that defines the data and behavior of

});
于 2012-06-21T06:51:56.310 回答