码迷,mamicode.com
首页 > Web开发 > 详细

Knockout.js Text绑定

时间:2015-08-17 15:19:09      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="js/jquery-1.11.1.min.js"></script>
    <script src="js/knockout-3.3.0.js"></script>
    <script>
        var viewModel = {
            myMessage: ko.observable() 
        };

        var viewModel1 = {
            price: ko.observable(24.95)
        };

        viewModel1.priceRating = ko.pureComputed(function () {
            return this.price() > 50 ? "expensive" : "affordable";
        }, viewModel1);

        $(function () {
            viewModel.myMessage("Hello, world!");
            viewModel1.price(51);
            ko.applyBindings(viewModel, $("#no1")[0]);
            ko.applyBindings(viewModel1, $("#no2")[0]);
        })

    </script>
</head>
<body>
    Today‘s message is: <span id="no1" data-bind="text: myMessage"></span>
    <br />
    The item is <span id="no2" data-bind="text: priceRating"></span>today.
</body>

 

Knockout.js Text绑定

标签:

原文地址:http://www.cnblogs.com/YuanSong/p/4736544.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!