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

Knockout JS 入门示例

时间:2014-06-18 18:52:25      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   java   http   

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="MyWeb.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
   <script src="knockout-2.2.1.js" type="text/javascript"></script>
   
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="Text1" type="text" data-bind="value: Text1" />
        <input id="Text2" type="text" data-bind="value: Text2" />
        <input id="Text3" type="text" data-bind="value: Text3" />
    </div>
    </form>
    <script src="a/b/js1.js" type="text/javascript"></script>
</body>
</html>
var testKo = function () {
    self = this;
    self.Text1 = ko.observable("1");
    self.Text2 = ko.observable("2");
    self.Text3 = ko.dependentObservable(function () {
        if (parseInt(self.Text1()) > 10 && parseInt(self.Text2()) < -5)
            return parseInt(self.Text1()) + parseInt(self.Text2());
        else
            return parseInt(self.Text1()) - parseInt(self.Text2());
    });
}
ko.applyBindings(new testKo());

 

Knockout JS 入门示例,布布扣,bubuko.com

Knockout JS 入门示例

标签:style   class   blog   code   java   http   

原文地址:http://www.cnblogs.com/nanfei/p/3790713.html

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