首页 > Web开发 > 详细

Knockout JS 入门示例

时间:2014-06-18 18:52:48      阅读:439      评论:0      收藏:0      [点我收藏+]
<%@ 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 入门示例

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!