<script type='text/javascript' src='Script/v1.0.js'></script>
<script type="text/javascript" src="Script/jquery-1.6.2.min.js"></script>
这是一个简单的视图模型- 定义 UI 数据和行为的 JavaScript:
function AppViewModel() {
this.firstName = ko.observable("Bert");
this.lastName = ko.observable("Bertington");
this.fullName = ko.computed(function() {
return this.firstName() + " " + this.lastName();
}, this);
}
激活 knockout.js:
ko.applyBindings(new AppViewModel());
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>First name: <strong data-bind="text: firstName"></strong></p>
<p>Last name: <strong data-bind="text: lastName"></strong></p>
<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
<p>Full name: <strong data-bind="text: fullName"></strong></p>
</div>
</form>
</body>
数据绑定不起作用。
错误:数据绑定不是有效的属性