Knockout JS 入门示例

<%@ 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 入门示例,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。