• knockout 学习实例2 text


    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script src="js/knockout-3.4.0.js" type="text/javascript" charset="utf-8"></script>
    </head>
    <body>
    Today‘s message is:<span data-bind="text:myMessage"></span>
    
    <script type="text/javascript">
    var myViewModel = {
        myMessage:ko.observable()
    };
    ko.applyBindings(myViewModel);
    
    setTimeout(function(){
    myViewModel.myMessage("Hello, world!");
    },2000);
    </script>
    </body>
    </html>
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script src="js/knockout-3.4.0.js" type="text/javascript" charset="utf-8"></script>
    </head>
    <body>
    The item is <span data-bind="text: priceRating"></span> today.
     
    <script type="text/javascript">
        var viewModel = {
            price: ko.observable(24.95)
        };
        viewModel.priceRating = ko.pureComputed(function() {
            return this.price() > 50 ? "expensive" : "affordable";
        }, viewModel);
        ko.applyBindings(viewModel);
    </script>
    </body>
    </html>
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script src="js/knockout-3.4.0.js" type="text/javascript" charset="utf-8"></script>
    </head>
    <body>
    The item is <span data-bind="text: price() > 50 ? 'expensive' : 'affordable'"></span> today.
    
     
    <script type="text/javascript">
        var viewModel = {
            price: ko.observable(24.95)
        };
        ko.applyBindings(viewModel);
    </script>
    </body>
    </html>
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script src="js/knockout-3.4.0.js" type="text/javascript" charset="utf-8"></script>
    </head>
    <body>
    
    Today‘s message is:<span data-bind="text:myMessage"></span>
    
     
    <script type="text/javascript">
        var viewModel = {
            myMessage:ko.observable()
        };
        ko.applyBindings(viewModel);
        viewModel.myMessage("<i>Hello, world!</i>");
    </script>
    </body>
    </html>

    这个是插不入文本不是html如果想插入html请吧text换成html

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script src="js/knockout-3.4.0.js" type="text/javascript" charset="utf-8"></script>
    </head>
    <body>
    <ul data-bind="foreach: items">
         <li><span data-bind="text:name"></span></li>
     </ul> 
     
    <script type="text/javascript">
        var viewModel = {
            items:ko.observableArray([{'name':"111"},{'name':"22222"}])
            // items:[{'name':"111"},{'name':"22222"}]
        };
        ko.applyBindings(viewModel);
        viewModel.items.push({name:'3333'})
    </script>
    </body>
    </html>
  • 相关阅读:
    transient关键字
    java 序列化,反序列化工具
    switch case语法
    java空map定义
    斐波那契数列的实现算法
    正则表达式
    java业务逻辑代码中需要增加一些与主流业务无关操作
    阿里巴巴开发手册对manager层的定义
    july 19
    bulletproof monk quote
  • 原文地址:https://www.cnblogs.com/tongchuanxing/p/5654590.html
Copyright © 2020-2023  润新知