我已经尝试过这段代码,但这不能正常工作。我的代码在下面
<link href="~/Content/knocktest.css" rel="stylesheet" />
<script src="~/Scripts/knockout-2.3.0.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var ViewModel = function (first, last) {
this.firstName = ko.observable(first);
this.lastName = ko.observable(last);
this.fullName = ko.computed(function () {
return this.firstName() + " " + this.lastName();
}, this);
};
ko.applyBindings(new ViewModel("Planet", "Earth"));
});
</script>
我的html代码如下
<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>