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 入门示例,布布扣,bubuko.com

Knockout JS 入门示例

上一篇:在WebBrowser中执行javascript脚本的几种方法整理(execScript/InvokeScript/NavigateScript) 附完整源码


下一篇:asp.net页面间传值方式